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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python-voi-0.0.3.tar.gz.
File metadata
- Download URL: python-voi-0.0.3.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6be0e61dccc35da429fc57161702a40ab6d8c6c3a28a529e4ae1d49826136bc1
|
|
| MD5 |
2faba6d1eb492e0ff6b76e60120fafd0
|
|
| BLAKE2b-256 |
43b95d246fe49d1727e162fe85afb101e5963d1bd8f16a2a78465f0f39a1856c
|
File details
Details for the file python_voi-0.0.3-py3-none-any.whl.
File metadata
- Download URL: python_voi-0.0.3-py3-none-any.whl
- Upload date:
- Size: 1.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63612cf00b0c48d2ec270c6d63fc685990595c6c630745b4f0871309a652cfdc
|
|
| MD5 |
2d19abb975a01f142e2c025d6a4b7c7b
|
|
| BLAKE2b-256 |
dcf9509a8dec2a0197c74d4d8f58778a8e466c0c4fade0f9ca46f07b0d895b3d
|