tefs package
Submodules
tefs.core module
- class tefs.core.TEFS(features: ndarray, target: ndarray, k: int, lag_features: list[int], lag_target: list[int], direction: str, verbose: int = 1, var_names: list[str] = None, n_jobs: int = 1)
Bases:
object
- fit() None
Run the feature selection algorithm and return the results.
- get_result() List[Dict[str, Dict[int, float] | float | int]]
Return the result of the feature selection algorithm.
- map_output_to_var_names()
A decorator that modifies the output of the decorated method. Assumes the method returns a list of indices and uses these indices to return the corresponding values from self.var_names.
- plot_te_results(ax: Axes) None
Plot the results of the TE estimation for each iteration.
- Parameters:
scores_iterations (list[IterationResult]) – A list of results of the TE scores, one per iteration.
var_names (list[str]) – A list of variable names.
ax (matplotlib.axes.Axes) – The axis to plot the results on.
- select_features(*args, **kwargs)
- select_n_features(*args, **kwargs)
- tefs.core.score_features(features: ndarray, target: ndarray, conditioning: ndarray, k: int, lag_features: list[int], lag_target: list[int], direction: str, n_jobs=1) ndarray
Computes the transfer entropy score for each feature \(X_i\) in \(X\), to the target \(Y\), given the conditioning set \(X_A\).
- Parameters:
features (np.ndarray of shape (n_samples, n_features)) – Sample of a (multivariate) random variable representing the input
target (np.ndarray of shape (n_samples, n_targets)) – Sample of a (multivariate) random variable representing the target
conditioning (np.ndarray of shape (n_samples, n_conditioning)) – Sample of a (multivariate) random variable representing the conditioning
k (int) – number of nearest neighbors for the CMI estimation
lag_features (list[int]) – the lags applied on features and conditioning
lag_target (list[int]) – the lags applied on the target
direction (str) – the direction of the transfer entropy, either “forward” or “backward”
n_jobs (int) – number of parallel jobs to run
- Returns:
a dictionary with key = feature index and value = transfer entropy score
- tefs.core.score_features_parallel(args)
Helper function to compute the score of a single feature in parallel.
tefs.estimation module
- tefs.estimation.estimate_cmi(X: ndarray, Y: ndarray, Z: ndarray, k: int = 5, estimation_method: str = 'digamma') float
Estimate the Conditional Mutual Information (CMI) between \(X\) and \(Y\) given \(Z\), i.e. \(I(X;Y \mid Z)\), using the equivalance
\[I(X;Y \mid Z) = I(X,Z;Y) - I(Z;Y)\]Note that \(I(X;Y \mid Z) = I(Y;X \mid Z)\).
- Parameters:
X (numpy.ndarray) – The input variable X.
Y (numpy.ndarray) – The input variable Y.
Z (numpy.ndarray) – The input variable Z.
k (int) – The number of nearest neighbors for k-nearest neighbor estimation (default is 5).
estimation_method (str) – The estimation method to use (default is “digamma”).
- Returns:
The estimated CMI between X and Y given Z.
- Return type:
float
- tefs.estimation.estimate_conditional_transfer_entropy(X: ndarray, Y: ndarray, Z: ndarray, k: int, lag_features: list[int] = [1], lag_target: list[int] = [1], lag_conditioning: list[int] = None) float
Computes the conditional transfer entropy from X to Y given Z, using the specified lags.
- Parameters:
X (np.ndarray of shape (n_samples, n_features)) – Sample of a (multivariate) random variable representing the input
Y (np.ndarray of shape (n_samples, n_targets)) – Sample of a (multivariate) random variable representing the target
Z (np.ndarray of shape (n_samples, n_conditioning)) – Sample of a (multivariate) random variable representing the conditioning
lag_features (List[int]) – the lag applied on X
lag_target (List[int]) – the lag applied on Y
lag_conditioning (List[int]) – the lag applied on Z, if None it is set to lag_features
- Returns:
a scalar of the value of the transfer entropy
- tefs.estimation.estimate_mi(X: ndarray, Y: ndarray, k: int = 5, estimation_method: str = 'digamma') float
Estimate the Mutual Information (MI) between \(X\) and \(Y\), i.e. \(I(X;Y)\), based on Mixed Random Variable Mutual Information Estimator - Gao et al..
- Parameters:
X (numpy.ndarray) – The first input array.
Y (numpy.ndarray) – The second input array.
k (int, optional) – The number of nearest neighbors to consider, defaults to 5.
estimation_method (str, optional) – The estimation method to use, can be either ‘digamma’ or ‘log’, defaults to ‘digamma’.
- Returns:
The estimated mutual information.
- Return type:
float