Python package for information theory.
Project description
dit is a Python package for information theory.
- Documentation:
- Downloads:
- Dependencies:
Python 2.7, 3.3, 3.4, 3.5, or 3.6
boltons
contextlib2
debtcollector
networkx
numpy
prettytable
scipy
six
- Optional Dependencies:
colorama
cython
numdifftools
scikit-learn
- Note:
The cython extensions are currently not supported on windows. Please install using the --nocython option.
- Install:
The easiest way to install is:
pip install ditAlternatively, 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 .- Mailing list:
None
- Code and bug tracker:
- License:
BSD 2-Clause, see LICENSE.txt for details.
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']
Enjoy!
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
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 dit-1.0.0.dev27.tar.gz.
File metadata
- Download URL: dit-1.0.0.dev27.tar.gz
- Upload date:
- Size: 234.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff255dd140fa8b1be33ff3e531c89535ffc083ad7ddf0ef4bbd3e17737925a5f
|
|
| MD5 |
fdaca6d5da56985b2684c69a7fb7333a
|
|
| BLAKE2b-256 |
62a31f0d1995132faa0098b9bdaa35d491b7bc8719606bd0a5a65748d0268fab
|
File details
Details for the file dit-1.0.0.dev27-py2.py3-none-any.whl.
File metadata
- Download URL: dit-1.0.0.dev27-py2.py3-none-any.whl
- Upload date:
- Size: 322.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a23aae220d3e27243693a3d246ced8f77fb9b454bcd4b77eaf2393d51e802f3
|
|
| MD5 |
29a7c529cd7b323403369850bdb0c814
|
|
| BLAKE2b-256 |
476acd616c99353faf438c46c54c9e7a19162762feae549c992a2da9c85d514b
|
File details
Details for the file dit-1.0.0.dev27-cp36-cp36m-macosx_10_12_x86_64.whl.
File metadata
- Download URL: dit-1.0.0.dev27-cp36-cp36m-macosx_10_12_x86_64.whl
- Upload date:
- Size: 404.4 kB
- Tags: CPython 3.6m, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6c8b3b7b5de3cfb533ee1f798168f1400443dac5582f9fa99e6391ac9959405
|
|
| MD5 |
dc01294961309bd554b26e331cd4a49b
|
|
| BLAKE2b-256 |
1ec859ff0951be8e421e864750a7751e1897e002222c729ad29c74362a8d553a
|
File details
Details for the file dit-1.0.0.dev27-cp27-cp27m-macosx_10_12_x86_64.whl.
File metadata
- Download URL: dit-1.0.0.dev27-cp27-cp27m-macosx_10_12_x86_64.whl
- Upload date:
- Size: 420.3 kB
- Tags: CPython 2.7m, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b750829ecaa1c544b35133bc04d66be645f81d836865bf5972cf75d6726cd9ff
|
|
| MD5 |
cdb3f976b9ad525772e2fb2829c6a188
|
|
| BLAKE2b-256 |
17b8c5d4fbc4146c88b8212fcd32efcb853622f71149357da4862b7dc143b418
|