infomeasure package#
Subpackages#
- infomeasure.composite_measures package
- infomeasure.estimators package
- Subpackages
- infomeasure.estimators.entropy package
- Submodules
- infomeasure.estimators.entropy.ansb module
- infomeasure.estimators.entropy.bayes module
- infomeasure.estimators.entropy.bonachela module
- infomeasure.estimators.entropy.chao_shen module
- infomeasure.estimators.entropy.chao_wang_jost module
- infomeasure.estimators.entropy.discrete module
- infomeasure.estimators.entropy.grassberger module
- infomeasure.estimators.entropy.kernel module
- infomeasure.estimators.entropy.kozachenko_leonenko module
- infomeasure.estimators.entropy.miller_madow module
- infomeasure.estimators.entropy.nsb module
- infomeasure.estimators.entropy.ordinal module
- infomeasure.estimators.entropy.renyi module
- infomeasure.estimators.entropy.shrink module
- infomeasure.estimators.entropy.tsallis module
- infomeasure.estimators.entropy.zhang module
- Module contents
- infomeasure.estimators.mutual_information package
- Submodules
- infomeasure.estimators.mutual_information.ansb module
- infomeasure.estimators.mutual_information.bayes module
- infomeasure.estimators.mutual_information.bonachela module
- infomeasure.estimators.mutual_information.chao_shen module
- infomeasure.estimators.mutual_information.chao_wang_jost module
- infomeasure.estimators.mutual_information.discrete module
- infomeasure.estimators.mutual_information.grassberger module
- infomeasure.estimators.mutual_information.kernel module
- infomeasure.estimators.mutual_information.kraskov_stoegbauer_grassberger module
- infomeasure.estimators.mutual_information.miller_madow module
- infomeasure.estimators.mutual_information.nsb module
- infomeasure.estimators.mutual_information.ordinal module
- infomeasure.estimators.mutual_information.renyi module
- infomeasure.estimators.mutual_information.shrink module
- infomeasure.estimators.mutual_information.tsallis module
- infomeasure.estimators.mutual_information.zhang module
- Module contents
- infomeasure.estimators.transfer_entropy package
- Submodules
- infomeasure.estimators.transfer_entropy.ansb module
- infomeasure.estimators.transfer_entropy.bayes module
- infomeasure.estimators.transfer_entropy.bonachela module
- infomeasure.estimators.transfer_entropy.chao_shen module
- infomeasure.estimators.transfer_entropy.chao_wang_jost module
- infomeasure.estimators.transfer_entropy.discrete module
- infomeasure.estimators.transfer_entropy.grassberger module
- infomeasure.estimators.transfer_entropy.kernel module
- infomeasure.estimators.transfer_entropy.kraskov_stoegbauer_grassberger module
- infomeasure.estimators.transfer_entropy.miller_madow module
- infomeasure.estimators.transfer_entropy.nsb module
- infomeasure.estimators.transfer_entropy.ordinal module
- infomeasure.estimators.transfer_entropy.renyi module
- infomeasure.estimators.transfer_entropy.shrink module
- infomeasure.estimators.transfer_entropy.tsallis module
- infomeasure.estimators.transfer_entropy.zhang module
- Module contents
- infomeasure.estimators.utils package
- Submodules
- infomeasure.estimators.utils.array module
- infomeasure.estimators.utils.discrete_interaction_information module
- infomeasure.estimators.utils.discrete_transfer_entropy module
- infomeasure.estimators.utils.exponential_family module
- infomeasure.estimators.utils.kde module
- infomeasure.estimators.utils.normalize module
- infomeasure.estimators.utils.ordinal module
- infomeasure.estimators.utils.te_slicing module
- infomeasure.estimators.utils.test_unit_ball_volume module
- infomeasure.estimators.utils.unit_ball_volume module
- Module contents
- infomeasure.estimators.entropy package
- Submodules
- infomeasure.estimators.base module
- infomeasure.estimators.functional module
- infomeasure.estimators.mixins module
- Module contents
- Subpackages
- infomeasure.utils package
- Submodules
- infomeasure.utils.config module
- infomeasure.utils.data module
DiscreteDataStatisticalTestResultStatisticalTestResult.confidence_interval()StatisticalTestResult.methodStatisticalTestResult.n_testsStatisticalTestResult.null_meanStatisticalTestResult.null_stdStatisticalTestResult.observed_valueStatisticalTestResult.p_valueStatisticalTestResult.percentile()StatisticalTestResult.t_scoreStatisticalTestResult.test_values
- infomeasure.utils.exceptions module
- infomeasure.utils.types module
- Module contents
Module contents#
infomeasure package.
- class infomeasure.Config[source]#
Bases:
objectConfiguration settings for the package.
This class provides configuration settings for the package. The settings are stored as class attributes and can be accessed and modified using the class methods.
Default settings:
base: “e” (nats)statistical_test_method: “permutation_test”statistical_test_n_tests: 200
- Attributes:
- _settings
dict A dictionary containing the configuration settings.
- _settings
Methods
get(key)Get the value of a configuration setting.
Get the logarithmic unit for entropy calculations.
Get the description of the logarithmic unit for entropy calculations.
reset()Reset the configuration settings to the default values.
set(key, value)Set the value of a configuration setting.
set_log_level(level)Set the logging level for the package.
set_logarithmic_unit(unit)Set the base for the logarithmic unit.
- classmethod get(key: str)[source]#
Get the value of a configuration setting.
- Parameters:
- key
str The key of the configuration setting.
- key
- Returns:
AnyThe value of the configuration setting.
- classmethod get_logarithmic_unit() str[source]#
Get the logarithmic unit for entropy calculations.
- Returns:
strThe logarithmic unit.
- classmethod get_logarithmic_unit_description() str[source]#
Get the description of the logarithmic unit for entropy calculations.
- Returns:
strThe description of the logarithmic unit.
- Raises:
ValueErrorIf there is no description for the logarithmic unit.
- static set_log_level(level: int | str) None[source]#
Set the logging level for the package.
- Parameters:
- Raises:
ValueErrorIf the level is not a valid logging level.
- classmethod set_logarithmic_unit(unit: str)[source]#
Set the base for the logarithmic unit.
The base determines the logarithmic unit used for entropy calculations:
‘bits’ or ‘shannons’ (base 2)
‘nats’ (base e)
‘hartleys’, ‘bans’, or ‘dits’ (base 10)
Alternatively, you can set the base directly using the ‘base’ key, via
set().- Parameters:
- unit
str The logarithmic unit to set. Use ‘bit(s)’ or ‘shannon(s)’ for base 2, ‘nat(s)’ for base e, and ‘hartley(s)’, ‘ban(s)’, or ‘dit(s)’ for base 10.
- unit
- Raises:
ValueErrorIf the unit is not recognised.
- infomeasure.cmi(*data, **kwargs: any)#
Conditional mutual information between two variables given a third variable.
See
mutual_informationfor more information.
- infomeasure.conditional_mutual_information(*data, **kwargs: any)[source]#
Conditional mutual information between two variables given a third variable.
See
mutual_informationfor more information.
- infomeasure.conditional_transfer_entropy(*data, **kwargs: any)[source]#
Conditional transfer entropy between two variables given a third variable.
See
transfer_entropyfor more information.
- infomeasure.cross_entropy(*data, **kwargs: any)[source]#
Calculate the cross-entropy using a functional interface of different estimators.
See
entropy()for more details on the parameters and returns.
- infomeasure.cte(*data, **kwargs: any)#
Conditional transfer entropy between two variables given a third variable.
See
transfer_entropyfor more information.
- infomeasure.entropy(*data, approach: str, **kwargs: any)[source]#
Calculate the (joint) entropy using a functional interface of different estimators.
Supports the following approaches:
bayes:Bayesian entropy estimator.bonachela:Bonachela entropy estimator.[
chao_shen,cs]:Chao-Shen entropy estimator.[
chao_wang_jost,cwj]:Chao Wang Jost entropy estimator.discrete:Discrete entropy estimator.grassberger:Grassberger entropy estimator.kernel:Kernel entropy estimator.[
metric,kl]:Kozachenko-Leonenko entropy estimator.[
miller_madow,mm]:Miller-Madow entropy estimator.[
ordinal,symbolic,permutation]:Ordinal / Permutation entropy estimator.renyi:Renyi entropy estimator.[
shrink,js]:Shrinkage (James-Stein) entropy estimator.tsallis:Tsallis entropy estimator.zhang:Zhang entropy estimator.
For the discrete Shannon entropy this is
\[\texttt{im.entropy(data_X, approach="discrete")} = H(X) = -\sum_{x \in X} p(x) \log p(x).\]Where for \(H(x)\), the estimated pmf \(p(x)\) belongs to the RV \(X\).
\[\texttt{im.entropy(data_P, data_Q, ...)} = H_Q(P) = H_\times(P, Q) = -\sum_{x \in X} p(x) \log q(x)\]For the cross-entropy \(H_Q(P)\), the estimated pmf \(p(x)\) belongs to the RV \(P\) and \(q(x)\) to the RV \(Q\). For other approaches, this formula is generalized in different forms.
- Parameters:
- *dataarray_like
The data used to estimate the entropy. For entropy, this can be an array-like. For joint entropy, pass the joint values inside a tuple. For cross-entropy, pass two separate parameters.
- approach
str The name of the estimator to use.
- **kwargs: dict
Additional keyword arguments to pass to the estimator.
- Returns:
floatThe calculated entropy.
- Raises:
ValueErrorIf the estimator is not recognised.
- infomeasure.estimator(*data, cond=None, measure: str = None, approach: str = None, step_size: int = 1, prop_time: int = 0, src_hist_len: int = 1, dest_hist_len: int = 1, cond_hist_len: int = 1, **kwargs: any) EstimatorType[source]#
Get an estimator for a specific measure.
This function provides a simple interface to get an
Estimatorfor a specific measure.If you are only interested in the global result, use the functional interfaces:
Estimators available:
- Entropy:
bayes:Bayesian entropy estimator.bonachela:Bonachela entropy estimator.[
chao_shen,cs]:Chao-Shen entropy estimator.[
chao_wang_jost,cwj]:Chao Wang Jost entropy estimator.discrete:Discrete entropy estimator.grassberger:Grassberger entropy estimator.kernel:Kernel entropy estimator.[
metric,kl]:Kozachenko-Leonenko entropy estimator.[
miller_madow,mm]:Miller-Madow entropy estimator.[
ordinal,symbolic,permutation]:Ordinal / Permutation entropy estimator.renyi:Renyi entropy estimator.[
shrink,js]:Shrinkage (James-Stein) entropy estimator.tsallis:Tsallis entropy estimator.zhang:Zhang entropy estimator.
- Mutual Information:
bonachela:Bonachela mutual information estimator.chao_shen:Chao-Shen mutual information estimator.chao_wang_jost:Chao Wang Jost mutual information estimator.discrete:Discrete mutual information estimator.grassberger:Grassberger mutual information estimator.[
metric,ksg]:Kraskov-Stoegbauer-Grassberger mutual information estimator.[
miller_madow,mm]:Miller-Madow mutual information estimator.nsb:NSB (Nemenman-Shafee-Bialek) mutual information estimator.[
ordinal,symbolic,permutation]:Ordinal mutual information estimator.shrink:Shrinkage (James-Stein) mutual information estimator.
- Transfer Entropy:
bonachela:Bonachela transfer entropy estimator.chao_shen:Chao-Shen transfer entropy estimator.chao_wang_jost:Chao Wang Jost transfer entropy estimator.discrete:Discrete transfer entropy estimator.grassberger:Grassberger transfer entropy estimator.[
metric,ksg]:Kraskov-Stoegbauer-Grassberger transfer entropy estimator.[
miller_madow,mm]:Miller-Madow transfer entropy estimator.nsb:NSB (Nemenman-Shafee-Bialek) transfer entropy estimator.[
ordinal,symbolic,permutation]:Ordinal transfer entropy estimator.tsallis:Tsallis transfer entropy estimator.
- Parameters:
- *data
The data used to estimate the measure. For entropy: a single array-like data. A tuple of data for joint entropy. For cross-entropy: two array-like data. Second input RV relative to the first. For mutual information: arbitrary number of array-like data. For transfer entropy: two array-like data. Source and destination.
- condarray_like,
optional Only if the measure is conditional transfer entropy.
- measure
str The measure to estimate. Options:
entropy,cross_entropy,mutual_information,transfer_entropy,conditional_mutual_information,conditional_transfer_entropy; aliases:h,hx,mi,te,cmi,cte.- approach
str The name of the estimator to use. Find the available estimators in the docstring of this function.
- *args: tuple
Additional arguments to pass to the estimator.
- **kwargs: dict
Additional keyword arguments to pass to the estimator.
- Returns:
EstimatorThe estimator instance.
- Raises:
ValueErrorIf the measure is not recognised.
- infomeasure.get_estimator_class(measure=None, approach=None) EstimatorType[source]#
Get estimator class based on the estimator name and approach.
This function returns the estimator class based on the measure and approach provided. If you want an instance of an estimator, initialized with data and parameters, use the functional interface
estimator().- Parameters:
- Returns:
classThe estimator class.
- Raises:
ValueErrorIf the measure is not recognized.
ValueErrorIf the approach is not recognized.
- infomeasure.h(*data, approach: str, **kwargs: any)#
Calculate the (joint) entropy using a functional interface of different estimators.
Supports the following approaches:
bayes:Bayesian entropy estimator.bonachela:Bonachela entropy estimator.[
chao_shen,cs]:Chao-Shen entropy estimator.[
chao_wang_jost,cwj]:Chao Wang Jost entropy estimator.discrete:Discrete entropy estimator.grassberger:Grassberger entropy estimator.kernel:Kernel entropy estimator.[
metric,kl]:Kozachenko-Leonenko entropy estimator.[
miller_madow,mm]:Miller-Madow entropy estimator.[
ordinal,symbolic,permutation]:Ordinal / Permutation entropy estimator.renyi:Renyi entropy estimator.[
shrink,js]:Shrinkage (James-Stein) entropy estimator.tsallis:Tsallis entropy estimator.zhang:Zhang entropy estimator.
For the discrete Shannon entropy this is
\[\texttt{im.entropy(data_X, approach="discrete")} = H(X) = -\sum_{x \in X} p(x) \log p(x).\]Where for \(H(x)\), the estimated pmf \(p(x)\) belongs to the RV \(X\).
\[\texttt{im.entropy(data_P, data_Q, ...)} = H_Q(P) = H_\times(P, Q) = -\sum_{x \in X} p(x) \log q(x)\]For the cross-entropy \(H_Q(P)\), the estimated pmf \(p(x)\) belongs to the RV \(P\) and \(q(x)\) to the RV \(Q\). For other approaches, this formula is generalized in different forms.
- Parameters:
- *dataarray_like
The data used to estimate the entropy. For entropy, this can be an array-like. For joint entropy, pass the joint values inside a tuple. For cross-entropy, pass two separate parameters.
- approach
str The name of the estimator to use.
- **kwargs: dict
Additional keyword arguments to pass to the estimator.
- Returns:
floatThe calculated entropy.
- Raises:
ValueErrorIf the estimator is not recognised.
- infomeasure.hx(*data, **kwargs: any)#
Calculate the cross-entropy using a functional interface of different estimators.
See
entropy()for more details on the parameters and returns.
- infomeasure.jensen_shannon_divergence(*data, approach: str | None = None, **kwargs)[source]#
Calculate the Jensen-Shannon Divergence between two or more distributions.
The Jensen-Shannon Divergence is a symmetrized and smoothed version of the Kullback-Leibler Divergence. It is calculated as the average of the Kullback-Leibler Divergence between each distribution and the average distribution.
\[JSD(P \| Q) = \frac{1}{2} KL(P \| M) + \frac{1}{2} KL(Q \| M)\]where \(M = \frac{1}{2} (P + Q)\).
- Parameters:
- parray_like
The first data.
- qarray_like
The second data.
- …array_like
Further data to compare.
- approach
str The name of the entropy estimator to use.
- **kwargs
dict Additional keyword arguments to pass to the entropy estimator.
- Returns:
floatThe Jensen-Shannon Divergence.
- Raises:
ValueErrorIf the approach is not supported or the entropy estimator is not compatible with the Jensen-Shannon Divergence.
ValueErrorIf any of the given data is not an array-like object.
- infomeasure.jsd(*data, approach: str | None = None, **kwargs)#
Calculate the Jensen-Shannon Divergence between two or more distributions.
The Jensen-Shannon Divergence is a symmetrized and smoothed version of the Kullback-Leibler Divergence. It is calculated as the average of the Kullback-Leibler Divergence between each distribution and the average distribution.
\[JSD(P \| Q) = \frac{1}{2} KL(P \| M) + \frac{1}{2} KL(Q \| M)\]where \(M = \frac{1}{2} (P + Q)\).
- Parameters:
- parray_like
The first data.
- qarray_like
The second data.
- …array_like
Further data to compare.
- approach
str The name of the entropy estimator to use.
- **kwargs
dict Additional keyword arguments to pass to the entropy estimator.
- Returns:
floatThe Jensen-Shannon Divergence.
- Raises:
ValueErrorIf the approach is not supported or the entropy estimator is not compatible with the Jensen-Shannon Divergence.
ValueErrorIf any of the given data is not an array-like object.
- infomeasure.kld(data_p, data_q, approach: str = '', **kwargs)#
Calculate the Kullback-Leibler Divergence between two distributions.
The Kullback-Leibler Divergence is a measure of the difference between two probability distributions. It is calculated as the expectation of the logarithm of the ratio of the probability of two events. To calculate, we use the identity of combining the joint and marginal entropies:
\[KL(P \| Q) = \sum_{x \in X} P(x) \log \left( \frac{P(x)}{Q(x)} \right) = H_Q(P) - H(P)\]- Parameters:
- data_parray_like
The first data.
- data_qarray_like
The second data.
- approach
str The name of the entropy estimator to use.
- **kwargs
dict Additional keyword arguments to pass to the entropy estimator.
- Returns:
floatThe Kullback-Leibler Divergence.
- Raises:
ValueErrorIf the approach is not supported or the entropy estimator is not compatible with the Kullback-Leibler Divergence.
- infomeasure.kullback_leiber_divergence(data_p, data_q, approach: str = '', **kwargs)[source]#
Calculate the Kullback-Leibler Divergence between two distributions.
The Kullback-Leibler Divergence is a measure of the difference between two probability distributions. It is calculated as the expectation of the logarithm of the ratio of the probability of two events. To calculate, we use the identity of combining the joint and marginal entropies:
\[KL(P \| Q) = \sum_{x \in X} P(x) \log \left( \frac{P(x)}{Q(x)} \right) = H_Q(P) - H(P)\]- Parameters:
- data_parray_like
The first data.
- data_qarray_like
The second data.
- approach
str The name of the entropy estimator to use.
- **kwargs
dict Additional keyword arguments to pass to the entropy estimator.
- Returns:
floatThe Kullback-Leibler Divergence.
- Raises:
ValueErrorIf the approach is not supported or the entropy estimator is not compatible with the Kullback-Leibler Divergence.
- infomeasure.mi(*data, approach: str, **kwargs: any)#
Calculate the mutual information using a functional interface of different estimators.
Supports the following approaches:
bonachela:Bonachela mutual information estimator.chao_shen:Chao-Shen mutual information estimator.chao_wang_jost:Chao Wang Jost mutual information estimator.discrete:Discrete mutual information estimator.grassberger:Grassberger mutual information estimator.[
metric,ksg]:Kraskov-Stoegbauer-Grassberger mutual information estimator.[
miller_madow,mm]:Miller-Madow mutual information estimator.nsb:NSB (Nemenman-Shafee-Bialek) mutual information estimator.[
ordinal,symbolic,permutation]:Ordinal mutual information estimator.shrink:Shrinkage (James-Stein) mutual information estimator.
- Parameters:
- *dataarray_like
The data used to estimate the (conditional) mutual information.
- condarray_like,
optional The conditional data used to estimate the conditional mutual information.
- approach
str The name of the estimator to use.
- normalizebool,
optional If True, normalize the data before analysis. Default is False. Not available for the discrete estimator.
- **kwargs: dict
Additional keyword arguments to pass to the estimator.
- Returns:
floatThe calculated mutual information.
- Raises:
ValueErrorIf the estimator is not recognised.
- infomeasure.mutual_information(*data, approach: str, **kwargs: any)[source]#
Calculate the mutual information using a functional interface of different estimators.
Supports the following approaches:
bonachela:Bonachela mutual information estimator.chao_shen:Chao-Shen mutual information estimator.chao_wang_jost:Chao Wang Jost mutual information estimator.discrete:Discrete mutual information estimator.grassberger:Grassberger mutual information estimator.[
metric,ksg]:Kraskov-Stoegbauer-Grassberger mutual information estimator.[
miller_madow,mm]:Miller-Madow mutual information estimator.nsb:NSB (Nemenman-Shafee-Bialek) mutual information estimator.[
ordinal,symbolic,permutation]:Ordinal mutual information estimator.shrink:Shrinkage (James-Stein) mutual information estimator.
- Parameters:
- *dataarray_like
The data used to estimate the (conditional) mutual information.
- condarray_like,
optional The conditional data used to estimate the conditional mutual information.
- approach
str The name of the estimator to use.
- normalizebool,
optional If True, normalize the data before analysis. Default is False. Not available for the discrete estimator.
- **kwargs: dict
Additional keyword arguments to pass to the estimator.
- Returns:
floatThe calculated mutual information.
- Raises:
ValueErrorIf the estimator is not recognised.
- infomeasure.te(*data, approach: str, **kwargs: any)#
Calculate the transfer entropy using a functional interface of different estimators.
Supports the following approaches:
bonachela:Bonachela transfer entropy estimator.chao_shen:Chao-Shen transfer entropy estimator.chao_wang_jost:Chao Wang Jost transfer entropy estimator.discrete:Discrete transfer entropy estimator.grassberger:Grassberger transfer entropy estimator.[
metric,ksg]:Kraskov-Stoegbauer-Grassberger transfer entropy estimator.[
miller_madow,mm]:Miller-Madow transfer entropy estimator.nsb:NSB (Nemenman-Shafee-Bialek) transfer entropy estimator.[
ordinal,symbolic,permutation]:Ordinal transfer entropy estimator.tsallis:Tsallis transfer entropy estimator.
- Parameters:
- source, destarray_like
The source (X) and destination (Y) data used to estimate the transfer entropy.
- condarray_like,
optional The conditional data used to estimate the conditional transfer entropy.
- approach
str The name of the estimator to use.
- step_size
int Step size between elements for the state space reconstruction.
- src_hist_len, dest_hist_len
int Number of past observations to consider for the source and destination data.
- prop_time
int,optional Number of positions to shift the data arrays relative to each other. Delay/lag/shift between the variables. Default is no shift. Assumed time taken by info to transfer from source to destination. Not compatible with the
condparameter / conditional TE. Alternatively calledoffset.- *args: tuple
Additional arguments to pass to the estimator.
- **kwargs: dict
Additional keyword arguments to pass to the estimator.
- Returns:
floatThe calculated transfer entropy.
- Raises:
ValueErrorIf the estimator is not recognised.
- infomeasure.transfer_entropy(*data, approach: str, **kwargs: any)[source]#
Calculate the transfer entropy using a functional interface of different estimators.
Supports the following approaches:
bonachela:Bonachela transfer entropy estimator.chao_shen:Chao-Shen transfer entropy estimator.chao_wang_jost:Chao Wang Jost transfer entropy estimator.discrete:Discrete transfer entropy estimator.grassberger:Grassberger transfer entropy estimator.[
metric,ksg]:Kraskov-Stoegbauer-Grassberger transfer entropy estimator.[
miller_madow,mm]:Miller-Madow transfer entropy estimator.nsb:NSB (Nemenman-Shafee-Bialek) transfer entropy estimator.[
ordinal,symbolic,permutation]:Ordinal transfer entropy estimator.tsallis:Tsallis transfer entropy estimator.
- Parameters:
- source, destarray_like
The source (X) and destination (Y) data used to estimate the transfer entropy.
- condarray_like,
optional The conditional data used to estimate the conditional transfer entropy.
- approach
str The name of the estimator to use.
- step_size
int Step size between elements for the state space reconstruction.
- src_hist_len, dest_hist_len
int Number of past observations to consider for the source and destination data.
- prop_time
int,optional Number of positions to shift the data arrays relative to each other. Delay/lag/shift between the variables. Default is no shift. Assumed time taken by info to transfer from source to destination. Not compatible with the
condparameter / conditional TE. Alternatively calledoffset.- *args: tuple
Additional arguments to pass to the estimator.
- **kwargs: dict
Additional keyword arguments to pass to the estimator.
- Returns:
floatThe calculated transfer entropy.
- Raises:
ValueErrorIf the estimator is not recognised.