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 pyvoi

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.1.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.1-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python-voi-0.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 2246f2ad0eb7e24ceedacd5478827099818ab6b7a2132961a127b089a6bd78e7
MD5 a74b0d7a868e85b078fd95f8ecf95f76
BLAKE2b-256 dce3c499e6b6aa5535bb8afa800438bc18a2122e76663e05b02c71333c96611c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_voi-0.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 df3bbda984d40282c8414be8abc898ef388c0347c44af59cdd094ca41160fd56
MD5 ec58e2828a726f7c47c2121e3151b096
BLAKE2b-256 8feb85ddf2dfe756b8dbb20f733d22d31cc43352bf6b782779dc4e0498c4e551

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