Package: ndd
nddis a Python package for Bayesian entropy estimation from discrete
data.nddprovides thendd.entropyfunction, a Bayesian replacement
for thescipy.stats.entropyfunction from the SciPy library,
based on an efficient implementation of theNemenman-Schafee-Bialek (NSB) algorithm.
Remarkably, the NSB algorithm allows entropy estimation when the number of
samples is much smaller than the number of classes with non-zero probability.Basic usageTheentropyfunction takes as input a vector offrequency counts(the observed frequencies for a set of classes or states) and analphabet size(the number of classes with non-zero probability, including unobserved classes)
and returns an entropy estimate (in nats):>>> import ndd
>>> counts = [4, 12, 4, 5, 3, 1, 5, 1, 2, 2, 2, 2, 11, 3, 4, 12, 12, 1, 2]
>>> ndd.entropy(counts, k=100)
2.8060922529931225The uncertainty in the entropy estimate can be quantified using the
posterior standard deviation (see Eq. 13 inArcher 2013)>>> ndd.entropy(counts, k=100, return_std=True)
(2.8060922529931225, 0.11945501149743358)If the alphabet size is unknown or countably infinite, thekargument can
be omitted and theentropyfunction will either use an upper bound estimate
fork, or switch to the asymptotic NSB estimator for strongly undersampled
distributions (Equations 29, 30 inNemenman 2011)>>> import ndd
>>> counts = [4, 12, 4, 5, 3, 1, 5, 1, 2, 2, 2, 2, 11, 3, 4, 12, 12, 1, 2]
>>> ndd.entropy(counts)  # k is omitted
2.8130746489179046Where to get itcondaThe easiest way to installnddis via thecondapackage manager.
Packages are provided on theconda-forgeAnaconda Cloud channel for Linux,
OS X, and Win platforms.Install the latest stable release usingcondawith:conda install --channel conda-forge nddpipInstall using pip with:pip3 install -U nddor directly from sources in github for the latest version of the code:pip3 install git+https://github.com/simomarsili/ndd.gitIn order to buildnddwithpip, you will neednumpy(>= 1.13) and aFortran compilerinstalled on your machine.
If you are using Debian or a Debian derivative such as Ubuntu,
you can install the gfortran compiler using the following command:sudo apt-get install gfortranOn Windows, you can use the gfortran compiler from theMinGW-w64project
(direct linkto the installer).Changesv1.10.5Addednddto the anacondaconda-forgechannel.v1.10Changed:
the signature of theentropyfunction is::entropy(nk, k=None, estimator=None, return_std=False)v1.9Changed:if argumentkis omitted, theentropyfunction will guess a
reasonable alphabet size and select the best estimator for the sampling
regime.v.1.8.3Fixed:integration for huge cardinalitiesv1.8Added:full Bayesian error estimate (from direct computation of the posterior
variance of the entropy)v1.7Changed:estimation is much faster (removed unnecessary checks on input counts)entropy()function needs cardinalitykfor the default (NSB)
estimatorv1.6.1Changed:
Fixed numerical integration for large alphabet sizes.v1.6Changed:The signature of theentropyfunction has been changed to allow
arbitrary entropy estimators. The new signature is:entropy(pk, k=None, estimator='NSB', return_std=False)The available estimators are:>>> import ndd
>>> ndd.entropy_estimators
['Plugin', 'MillerMadow', 'NSB', 'AsymptoticNSB', 'Grassberger']Check the function docstring for details.Added:MillerMadowestimator classAsymptoticNSBestimator classGrassbergerestimator classv1.5For methods/functions working on data matrices:
the default input is an-by-p2D array (n samples from p discrete
variables, with different samples on differentrows).
Since release 1.3, the default was a transposed (p-by-n) data matrix.
The behavior of functions taking frequency counts as input
(e.g. theentropyfunction) is unchanged.v1.4Added thekullback_leibler_divergencefunction.v1.1Added:from_datamutual_informationconditional_informationinteraction_informationcoinformationv1.0Drop support for Python < 3.4.v0.9Added thejensen_shannnon_divergencefunction.ReferencesSome refs:@article{wolpert1995estimating,
  title={Estimating functions of probability distributions from a finite set of samples},
  author={Wolpert, David H and Wolf, David R},
  journal={Physical Review E},
  volume={52},
  number={6},
  pages={6841},
  year={1995},
  publisher={APS}
}

@inproceedings{nemenman2002entropy,
  title={Entropy and inference, revisited},
  author={Nemenman, Ilya and Shafee, Fariel and Bialek, William},
  booktitle={Advances in neural information processing systems},
  pages={471--478},
  year={2002}
}

@article{paninski2003estimation,
  title={Estimation of entropy and mutual information},
  author={Paninski, Liam},
  journal={Neural computation},
  volume={15},
  number={6},
  pages={1191--1253},
  year={2003},
  publisher={MIT Press}
}

@article{nemenman2004entropy,
  title={Entropy and information in neural spike trains: Progress on the sampling problem},
  author={Nemenman, Ilya and Bialek, William and van Steveninck, Rob de Ruyter},
  journal={Physical Review E},
  volume={69},
  number={5},
  pages={056111},
  year={2004},
  publisher={APS}
}

@article{nemenman2011coincidences,
  title={Coincidences and estimation of entropies of random variables with large cardinalities},
  author={Nemenman, Ilya},
  journal={Entropy},
  volume={13},
  number={12},
  pages={2013--2023},
  year={2011},
  publisher={Molecular Diversity Preservation International}
}

@article{archer2013bayesian,
  title={Bayesian and quasi-Bayesian estimators for mutual information from discrete data},
  author={Archer, Evan and Park, Il Memming and Pillow, Jonathan W},
  journal={Entropy},
  volume={15},
  number={5},
  pages={1738--1755},
  year={2013},
  publisher={Multidisciplinary Digital Publishing Institute}
}

@article{archer2014bayesian,
  title={Bayesian entropy estimation for countable discrete distributions},
  author={Archer, Evan and Park, Il Memming and Pillow, Jonathan W},
  journal={The Journal of Machine Learning Research},
  volume={15},
  number={1},
  pages={2833--2868},
  year={2014},
  publisher={JMLR. org}
}and interesting links:Sebastian Nowozin on Bayesian estimatorsIl Memming Park on discrete entropy estimatorsContributingnddis an OPEN Source Project so please help out byreporting bugsor forking and opening pull requests when possible.LicenseCopyright (c) 2016-2019, Simone Marsili.
All rights reserved.Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.