causalexplain.estimators.lingam package#
Submodules#
Python implementation of the LiNGAM algorithms. The LiNGAM Project: https://sites.google.com/site/sshimizu06/lingam
Python implementation of the LiNGAM algorithms. The LiNGAM Project: https://sites.google.com/site/sshimizu06/lingam
- class BootstrapMixin[source]#
Bases:
objectMixin class for all LiNGAM algorithms that implement the method of bootstrapping.
- bootstrap(X, n_sampling)[source]#
Evaluate the statistical reliability of DAG based on the bootstrapping.
- Parameters:
X (array-like, shape (n_samples, n_features)) – Training data, where
n_samplesis the number of samples andn_featuresis the number of features.n_sampling (int) – Number of bootstrapping samples.
- Returns:
result – Returns the result of bootstrapping.
- Return type:
- class BootstrapResult(adjacency_matrices, total_effects)[source]#
Bases:
objectThe result of bootstrapping.
- __init__(adjacency_matrices, total_effects)[source]#
Construct a BootstrapResult.
- Parameters:
adjacency_matrices (array-like, shape (n_sampling)) – The adjacency matrix list by bootstrapping.
total_effects (array-like, shape (n_sampling)) – The total effects list by bootstrapping.
- property adjacency_matrices_#
The adjacency matrix list by bootstrapping.
- Returns:
adjacency_matrices_ – The adjacency matrix list, where
n_samplingis the number of bootstrap sampling.- Return type:
array-like, shape (n_sampling)
- property total_effects_#
The total effect list by bootstrapping.
- Returns:
total_effects_ – The total effect list, where
n_samplingis the number of bootstrap sampling.- Return type:
array-like, shape (n_sampling)
- get_causal_direction_counts(n_directions=None, min_causal_effect=None, split_by_causal_effect_sign=False)[source]#
Get causal direction count as a result of bootstrapping.
- Parameters:
n_directions (int, optional (default=None)) – If int, then The top
n_directionsitems are included in the resultmin_causal_effect (float, optional (default=None)) – Threshold for detecting causal direction. If float, then causal directions with absolute values of causal effects less than
min_causal_effectare excluded.split_by_causal_effect_sign (boolean, optional (default=False)) – If True, then causal directions are split depending on the sign of the causal effect.
- Returns:
causal_direction_counts – List of causal directions sorted by count in descending order. The dictionary has the following format:
{'from': [n_directions], 'to': [n_directions], 'count': [n_directions]}
where
n_directionsis the number of causal directions.- Return type:
- get_directed_acyclic_graph_counts(n_dags=None, min_causal_effect=None, split_by_causal_effect_sign=False)[source]#
Get DAGs count as a result of bootstrapping.
- Parameters:
n_dags (int, optional (default=None)) – If int, then The top
n_dagsitems are included in the resultmin_causal_effect (float, optional (default=None)) – Threshold for detecting causal direction. If float, then causal directions with absolute values of causal effects less than
min_causal_effectare excluded.split_by_causal_effect_sign (boolean, optional (default=False)) – If True, then causal directions are split depending on the sign of the causal effect.
- Returns:
directed_acyclic_graph_counts – List of directed acyclic graphs sorted by count in descending order. The dictionary has the following format:
{'dag': [n_dags], 'count': [n_dags]}.
where
n_dagsis the number of directed acyclic graphs.- Return type:
- get_probabilities(min_causal_effect=None)[source]#
Get bootstrap probability.
- Parameters:
min_causal_effect (float, optional (default=None)) – Threshold for detecting causal direction. If float, then causal directions with absolute values of causal effects less than
min_causal_effectare excluded.- Returns:
probabilities – List of bootstrap probability matrix.
- Return type:
array-like
- get_total_causal_effects(min_causal_effect=None)[source]#
Get total effects list.
- Parameters:
min_causal_effect (float, optional (default=None)) – Threshold for detecting causal direction. If float, then causal directions with absolute values of causal effects less than
min_causal_effectare excluded.- Returns:
total_causal_effects – List of bootstrap total causal effect sorted by probability in descending order. The dictionary has the following format:
{'from': [n_directions], 'to': [n_directions], 'effect': [n_directions], 'probability': [n_directions]}
where
n_directionsis the number of causal directions.- Return type:
- get_paths(from_index, to_index, min_causal_effect=None)[source]#
Get all paths from the start variable to the end variable and their bootstrap probabilities.
- Parameters:
from_index (int) – Index of the variable at the start of the path.
to_index (int) – Index of the variable at the end of the path.
min_causal_effect (float, optional (default=None)) – Threshold for detecting causal direction. Causal directions with absolute values of causal effects less than
min_causal_effectare excluded.
- Returns:
paths – List of path and bootstrap probability. The dictionary has the following format:
{'path': [n_paths], 'effect': [n_paths], 'probability': [n_paths]}
where
n_pathsis the number of paths.- Return type:
Python implementation of the LiNGAM algorithms. The LiNGAM Project: https://sites.google.com/site/sshimizu06/lingam
- class DirectLiNGAM(name, random_state=None, prior_knowledge=None, apply_prior_knowledge_softly=False, measure='pwling', th=0.0, inverse=False, absolute_values=False, verbose=False)[source]#
Bases:
_BaseLiNGAMDirectLiNGAM estimator.
- is_fitted_ = False#
- metrics = None#
- dag = None#
- feature_names = None#
- __init__(name, random_state=None, prior_knowledge=None, apply_prior_knowledge_softly=False, measure='pwling', th=0.0, inverse=False, absolute_values=False, verbose=False)[source]#
Construct a DirectLiNGAM model.
- fit(X)[source]#
Fit the model to X.
- Parameters:
X (array-like, shape (n_samples, n_features)) – Training data, where
n_samplesis the number of samples andn_featuresis the number of features.- Returns:
self – Returns the instance itself.
- Return type:
- fit_predict(train, test, ref_graph=None)[source]#
Fit the model to X and return the estimated DAG.
- Parameters:
X (array-like, shape (n_samples, n_features)) – Training data, where
n_samplesis the number of samples andn_featuresis the number of features.- Returns:
self – Returns the instance itself.
- Return type:
- main(dataset_name, threshold=0.0, inverse=True, absolute_values=True, input_path='/Users/renero/phd/data/sachs/', output_path='/Users/renero/phd/output/RC4/sachs/compared/', save=False)[source]#
Python implementation of the LiNGAM algorithms. The LiNGAM Project: https://sites.google.com/site/sshimizu06/lingam
- find_all_paths(dag, from_index, to_index, min_causal_effect=0.0)[source]#
Find all paths from point to point in DAG.
- Parameters:
dag (array-like, shape (n_features, n_features)) – The adjacency matrix to fine all paths, where n_features is the number of features.
from_index (int) – Index of the variable at the start of the path.
to_index (int) – Index of the variable at the end of the path.
min_causal_effect (float, optional (default=0.0)) – Threshold for detecting causal direction. Causal directions with absolute values of causal effects less than
min_causal_effectare excluded.
- Returns:
paths (array-like, shape (n_paths)) – List of found path, where n_paths is the number of paths.
effects (array-like, shape (n_paths)) – List of causal effect, where n_paths is the number of paths.
- predict_adaptive_lasso(X, predictors, target, gamma=1.0)[source]#
Predict with Adaptive Lasso.
- Parameters:
X (array-like, shape (n_samples, n_features)) – Training data, where n_samples is the number of samples and n_features is the number of features.
predictors (array-like, shape (n_predictors)) – Indices of predictor variable.
target (int) – Index of target variable.
- Returns:
coef – Coefficients of predictor variable.
- Return type:
array-like, shape (n_features)