Python routines to compute (conditional) mutual information
Both mutual information
- numpy
- scipy (only scipy.special.digamma)
- scikit-learn (only sklearn.neighbors.KDTree)
Compute mutual information between x and y, which can be 1d or 2d arrays:
mi = compute_mi(x, y, n_neighbors=3, noise_type=None)
Similarly, to compute conditional mutual information:
cmi = compute_cmi(x, y, n_neighbors=3, noise_type=None)
The file run_tests.py
contains several test cases for which analytic solutions are known. Execute it with a -h
flag to see available options.
A nearest neighbor approach is used, for which theoretical background is provided in the following papers and references therein:
- Estimating mutual information, by Kraskov et al.
- Estimating Mutual Information for Discrete-Continuous Mixtures, by Gao et al.
- Conditional Mutual Information Estimation for Mixed Discrete and Continuous Variables with Nearest Neighbors, by Mesner and Shalizi
The basic idea is to first determine the Chebyshev distance
where
Conditional mutual information can be estimated in two ways, either by using the identity
or by using a slightly modified estimator. The radius
after which the conditional mutual information of
The implementation is inspired by and based on the mutual information methods available in scikit-learn, which where implemented by Nikolay Mayorov. The nearest neighbor searches are performed using the k-d tree implementation provided by scikit-learn.
This project has received funding from the European Union’s Horizon 2020 Research and Innovation programme under grant agreement No 776262 AIDA.