infomeasure.utils package#
Submodules#
infomeasure.utils.config module#
Utility module for configuration settings.
- class infomeasure.utils.config.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.utils.data module#
Data structures and containers for the infomeasure package.
- class infomeasure.utils.data.DiscreteData(uniq: ndarray, counts: ndarray, data: ndarray = None)[source]#
Bases:
objectContainer for discrete random variable data.
- Attributes:
- uniq
ndarray Array of unique values in the discrete data.
- counts
ndarray Array of counts for each unique value.
- data
ndarray,optional Original data array. Defaults to None.
- N
int,optional Total number of samples (length of data). Defaults to None.
- K
int,optional Number of unique values (len(uniq)). Defaults to None.
- uniq
Methods
from_counts(uniq, counts)Constructs a DiscreteData instance from unique values and their counts.
from_data(data)Create a DiscreteData object from a data array.
- property distribution_dict: dict#
Dictionary mapping unique elements to their corresponding probabilities.
- Returns:
dictA dictionary where keys are unique elements and values are their corresponding probabilities.
- classmethod from_counts(uniq: ndarray, counts: ndarray) DiscreteData[source]#
Constructs a DiscreteData instance from unique values and their counts.
This class method creates an instance of the DiscreteData class by specifying the unique values and their corresponding counts. The data attribute of the created instance is set to None.
- Parameters:
- Returns:
DiscreteDataA new instance of the DiscreteData class initialized with the given unique values and their counts.
- classmethod from_data(data: ndarray) DiscreteData[source]#
Create a DiscreteData object from a data array.
- Parameters:
- data
ndarray Raw data array to analyse.
- data
- Returns:
DiscreteDataNew instance with computed unique values and counts.
- property probabilities: ndarray#
Computes and returns the probabilities by normalizing counts.
The probabilities property calculates the probabilities as the ratio of counts to the total value N. This provides a normalized representation of counts as probabilities.
- Returns:
ndarrayAn array containing the probabilities, calculated by dividing counts by N.
- class infomeasure.utils.data.StatisticalTestResult(p_value: float, t_score: float, test_values: ndarray, observed_value: float, null_mean: float, null_std: float, n_tests: int, method: str)[source]#
Bases:
objectComprehensive statistical test result containing p-value, t-score, and confidence intervals.
- Attributes:
- p_value
float The p-value of the statistical test.
- t_score
float The t-score (standardized test statistic).
- test_values
ndarray The test values from permutation/bootstrap sampling.
- observed_value
float The observed value being tested.
- null_mean
float Mean of the null distribution (test values).
- null_std
float Standard deviation of the null distribution.
- n_tests
int Number of tests performed (permutations or bootstrap samples).
- method
str The statistical test method used (“permutation_test” or “bootstrap”).
- p_value
Methods
confidence_interval(confidence_level[, method])Get confidence interval for the specified confidence level.
percentile(q[, method])Compute the q-th percentile of the test values.
- confidence_interval(confidence_level, method='linear')[source]#
Get confidence interval for the specified confidence level.
This is a convenience function that converts a confidence level (e.g., 95 for 95% CI) to the appropriate percentile calls.
- Parameters:
- confidence_level
float Confidence level as a percentage (e.g., 95 for 95% CI). Must be between 0 and 100.
- method
str,optional Method to use for estimating the percentile. Default is “linear”. See
numpy.percentile()for available methods.
- confidence_level
- Returns:
ndarrayArray containing [lower_bound, upper_bound] of the confidence interval.
- Raises:
ValueErrorIf confidence_level is not between 0 and 100.
Examples
>>> result = estimator.statistical_test(n_tests=100) >>> result.confidence_interval(95) # 95% CI >>> result.confidence_interval(90, method="nearest") # 90% CI with nearest method
- percentile(q, method='linear')[source]#
Compute the q-th percentile of the test values.
This method wraps numpy’s percentile function to compute percentiles of the test values from the statistical test.
- Parameters:
- qarray_like
offloat Percentage or sequence of percentages for the percentiles to compute. Values must be between 0 and 100 inclusive.
- method
str,optional Method to use for estimating the percentile. Default is “linear”. See
numpy.percentile()for available methods.
- qarray_like
- Returns:
See also
numpy.percentileCompute percentiles along specified axes.
Notes
For details on the method parameter, reference
numpy.percentile().Examples
>>> result = estimator.statistical_test(n_tests=100,method="permutation_test") >>> result.percentile(50) # Median >>> result.percentile([25, 75]) # Quartiles >>> result.percentile(95, method="nearest") # 95th percentile with nearest method
infomeasure.utils.exceptions module#
Custom exceptions for the infomeasure package.
- exception infomeasure.utils.exceptions.TheoreticalInconsistencyError[source]#
Bases:
ExceptionException raised when a method cannot be implemented due to theoretical inconsistencies.
This exception is used for cases where the mathematical or theoretical foundation of a method makes it inappropriate or impossible to implement in a meaningful way. Examples include cross-entropy for estimators that mix bias corrections from different distributions, or methods that violate fundamental assumptions.
This is different from NotImplementedError, which indicates that implementation is planned but not yet done. TheoreticalInconsistencyError indicates that implementation is not theoretically sound or appropriate.
infomeasure.utils.types module#
Type definitions for the infomeasure package.
Module contents#
Utility functions for infomeasure.
- class infomeasure.utils.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.