Skip to main content

Python implementation of Variation of Information

Project description

pyvoi: Variation of Information in numpy/torch

Calculate the Variation of Information for two clusterings

References: Meila, Marina (2003). Comparing Clusterings by the Variation of Information. Learning Theory and Kernel Machines: 173–187

Installation

pip install python-voi

Usage

By default, pyvoi uses torch to compute the variation of information.

To get VI values only

import pyvoi
labels1=[0,1,1,2,4]
labels2=[0,2,3,4,4]
vi,vi_split,vi_merge=pyvoi.VI(labels1,labels2)
print(vi,vi_split,vi_merge)
# total vi, split vi, merge vi
# tensor(0.5545) tensor(0.2773) tensor(0.2773)

To get VI components

import pyvoi
labels1=[0,1,1,2,4]
labels2=[0,2,3,4,4]
vi,vi_split,vi_merge,splitters,mergers=pyvoi.VI(labels1,labels2,return_split_merge=True)
print(vi,vi_split,vi_merge)
# (same as above) total vi, split vi, merge vi
# tensor(0.5545) tensor(0.2773) tensor(0.2773)

print(splitters)
# vi contribution, label in label2
#tensor([[0.2773, 4.0000],
#    [0.0000, 3.0000],
#    [0.0000, 2.0000],
#    [0.0000, 0.0000]])

print(mergers)
# vi contribution, label in label1
#tensor([[0.2773, 1.0000],
#    [0.0000, 4.0000],
#    [0.0000, 2.0000],
#    [0.0000, 0.0000]])

Using cuda

import pyvoi
labels1=[0,1,1,2,4]
labels2=[0,2,3,4,4]
vi,vi_split,vi_merge=pyvoi.VI(labels1,labels2,device="cuda")
print(vi,vi_split,vi_merge)
#tensor(0.5545, device='cuda:0') tensor(0.2773, device='cuda:0') tensor(0.2773, device='cuda:0')

Using numpy

import numpy as np
import pyvoi
labels1=np.array([0,1,1,2,4])
labels2=np.array([0,2,3,4,4])
vi,vi_split,vi_merge=pyvoi.VI(labels1,labels2,torch=False)
print(vi,vi_split,vi_merge)
#0.5545177444479561 0.27725887222397794 0.27725887222397816

Contact and Bug Reports

Core Francisco Park: cfpark00@gmail.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-voi-0.0.2.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_voi-0.0.2-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file python-voi-0.0.2.tar.gz.

File metadata

  • Download URL: python-voi-0.0.2.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.13

File hashes

Hashes for python-voi-0.0.2.tar.gz
Algorithm Hash digest
SHA256 0147e1101b2d46b3f8e62c2b4661cf50e630d6c9a0466b6e9930b70b2c3490ec
MD5 2b6bcf026b1436c574378f04c2fbfac5
BLAKE2b-256 a3add3f036357be33d9db0a7b42024b41afec0f75cdc239aa38b06957ce489ae

See more details on using hashes here.

File details

Details for the file python_voi-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: python_voi-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 2.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.13

File hashes

Hashes for python_voi-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 154acb0555551423856815bc5fb4662ba974efbdad064d557f7b9bf1569b3560
MD5 a5faaefac3799a7d20a45dce55019d71
BLAKE2b-256 ba98761caa2b8af2b758c4accd5337b779b65c7f4669d6892d6f21f8d445cf3f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page