nws_tools.mutual_info

nws_tools.mutual_info(tsdata, n_bins=32, normalized=True, fast=True, norm_ts=True)[source]

Calculate a (normalized) mutual information matrix at zero lag

Parameters:

tsdata : NumPy 2d array

Array of data values per time point. Format is: timepoints-by-N. Note that both timepoints and N have to be >= 2 (i.e., the code needs at least two time-series of minimum length 2)

n_bins : int

Number of bins for estimating probability distributions

normalized : bool

If True, the normalized mutual information (NMI) is computed otherwise the raw mutual information (not bounded from above) is calculated (see Notes for details).

fast : bool

Use C++ code to calculate (N)MI. If False, then a (significantly) slower Python implementation is employed (provided in case the compilation of the C++ code snippets fails on a system)

norm_ts : bool

If True the input time-series is normalized to zero mean and unit variance (default).

Returns:

mi : NumPy 2d array

N-by-N matrix of pairwise (N)MI coefficients of the input time-series

See also

pyunicorn.pyclimatenetwork.mutual_info_climate_network
classes in this module

Notes

For two random variables \(X\) and \(Y\) the raw mutual information is given by

\[MI(X,Y) = H(X) + H(Y) - H(X,Y),\]

where \(H(X)\) and \(H(Y)\) denote the Shannon entropies of \(X\) and \(Y\), respectively, and \(H(X,Y)\) is their joint entropy. By default, this function normalizes the raw mutual information \(MI(X,Y)\) by the geometric mean of \(H(X)\) and \(H(Y)\)

\[NMI(X,Y) = {MI(X,Y)\over\sqrt{H(X)H(Y)}}.\]

The heavy lifting in this function is mainly done by code parts taken from the pyunicorn package, developed by Jonathan F. Donges and Jobst Heitzig [R9]. It is currently available here The code has been modified so that weave and pure Python codes are now part of the same function. Further, the original code computes the raw mutual information only. Both Python and C++ parts have been extended to compute a normalized mutual information too.

References

[R9](1, 2)

Copyright (C) 2008-2015, Jonathan F. Donges (Potsdam-Institute for Climate Impact Research), pyunicorn authors. 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 pyunicorn authors and the Potsdam-Institute for Climate Impact Research 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.

Examples

>>> tsdata = np.random.rand(150,2) # 2 time-series of length 150
>>> NMI = mutual_info(tsdata)