Python package for information theory.
Project description
dit is a Python package for information theory.
Basic Information
Documentation
Downloads
Dependencies |
Optional Dependencies |
---|---|
|
Install
The easiest way to install is:
pip install dit
Alternatively, you can clone this repository, move into the newly created dit directory, and then install the package:
git clone https://github.com/dit/dit.git
cd dit
pip install .
Code and bug tracker
License
BSD 2-Clause, see LICENSE.txt for details.
Implemented Measures
dit implements the following information measures. Most of these are implemented in multivariate & conditional generality, where such generalizations either exist in the literature or are relatively obvious — for example, though it is not in the literature, the multivariate conditional exact common information is implemented here.
Entropies
|
Mutual Informations
|
Divergences
|
Other Measures
|
||
Common Informations
|
Partial Information Decomposition
|
|
Secret Key Agreement Bounds
|
Quickstart
The basic usage of dit corresponds to creating distributions, modifying them if need be, and then computing properties of those distributions. First, we import:
>>> import dit
Suppose we have a really thick coin, one so thick that there is a reasonable chance of it landing on its edge. Here is how we might represent the coin in dit.
>>> d = dit.Distribution(['H', 'T', 'E'], [.4, .4, .2])
>>> print d
Class: Distribution
Alphabet: ('E', 'H', 'T') for all rvs
Base: linear
Outcome Class: str
Outcome Length: 1
RV Names: None
x p(x)
E 0.2
H 0.4
T 0.4
Calculate the probability of H and also of the combination H or T.
>>> d['H']
0.4
>>> d.event_probability(['H','T'])
0.8
Calculate the Shannon entropy and extropy of the joint distribution.
>>> dit.shannon.entropy(d)
1.5219280948873621
>>> dit.other.extropy(d)
1.1419011889093373
Create a distribution where Z = xor(X, Y).
>>> import dit.example_dists
>>> d = dit.example_dists.Xor()
>>> d.set_rv_names(['X', 'Y', 'Z'])
>>> print d
Class: Distribution
Alphabet: ('0', '1') for all rvs
Base: linear
Outcome Class: str
Outcome Length: 3
RV Names: ('X', 'Y', 'Z')
x p(x)
000 0.25
011 0.25
101 0.25
110 0.25
Calculate the Shannon mutual informations I[X:Z], I[Y:Z], and I[X,Y:Z].
>>> dit.shannon.mutual_information(d, ['X'], ['Z'])
0.0
>>> dit.shannon.mutual_information(d, ['Y'], ['Z'])
0.0
>>> dit.shannon.mutual_information(d, ['X', 'Y'], ['Z'])
1.0
Calculate the marginal distribution P(X,Z). Then print its probabilities as fractions, showing the mask.
>>> d2 = d.marginal(['X', 'Z'])
>>> print d2.to_string(show_mask=True, exact=True)
Class: Distribution
Alphabet: ('0', '1') for all rvs
Base: linear
Outcome Class: str
Outcome Length: 2 (mask: 3)
RV Names: ('X', 'Z')
x p(x)
0*0 1/4
0*1 1/4
1*0 1/4
1*1 1/4
Convert the distribution probabilities to log (base 3.5) probabilities, and access its probability mass function.
>>> d2.set_base(3.5)
>>> d2.pmf
array([-1.10658951, -1.10658951, -1.10658951, -1.10658951])
Draw 5 random samples from this distribution.
>>> dit.math.prng.seed(1)
>>> d2.rand(5)
['01', '10', '00', '01', '00']
Contributions & Help
If you’d like a feature added to dit or notice any problems, please file an issue, or, even better, open a pull request. We’ll work with you to ensure that the code is tested and documented.
If you have any questions about using dit, you can reach us over at our slack channel.
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 Distributions
Hashes for dit-1.2.0-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d1ea9723fcf6f81bd5c53586ad93f9f492c61f5ae5103badd13eaa3a9d6a819 |
|
MD5 | fc645b9a494dfb9c2da5945bdc6d8eb1 |
|
BLAKE2b-256 | e097a230223a86f42aa48bbaf814510c5afcf3362d6f486af1c7704e2c3d6859 |
Hashes for dit-1.2.0-cp27-cp27m-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8164ebf10ead0ade77f76322b9b0c7258cf52b99af3dc410dd8da65afd4f45b0 |
|
MD5 | 44636bd51221b40c89072f21815ec059 |
|
BLAKE2b-256 | c6c22dd5eaa3c03746fa7169c1f0da2f0da2d7702717b59145d10b22050bf6cb |