ETIA.CausalLearning.algorithms.causalnex_algorithm package
Submodules
ETIA.CausalLearning.algorithms.causalnex_algorithm.NoTears module
- class NoTearsAlgorithm(algorithm='notears', verbose=False)[source]
Bases:
objectImplements the NOTEARS algorithm for learning causal structures from data.
- check_parameters(parameters, data_info)[source]
Checks if the provided parameters are valid for the NOTEARS algorithm.
- structure_model_to_matrix(StructureModel)[source]
Converts a causal structure model to an adjacency matrix.
- run(data, parameters, prepare_data=True)[source]
Runs the NOTEARS algorithm on the provided data and parameters.
- prepare_data(Data, parameters=None)[source]
Prepares data for the NOTEARS algorithm. This function can be adapted to include specific data preparation steps for NOTEARS.
- Parameters:
Data (object) – The dataset to be used in the algorithm.
parameters (dict, optional) – Additional parameters for data preparation, if any. Default is None.
- Returns:
Prepared dataset and additional preparation info, if any.
- Return type:
tuple
- check_parameters(parameters, data_info)[source]
Checks if the provided parameters are valid for the NOTEARS algorithm.
- Parameters:
parameters (dict) – Parameters to be used in the algorithm.
data_info (dict) – Information about the dataset, such as data type and time info.
- Returns:
True if parameters are valid, raises ValueError otherwise.
- Return type:
bool
- Raises:
ValueError – If an invalid parameter value is provided, such as a threshold outside the range [0, 1].
- structure_model_to_matrix(StructureModel)[source]
Converts a StructureModel to an adjacency matrix representation.
- Parameters:
StructureModel (causalnex.StructureModel) – A StructureModel object representing the learned structure.
- Returns:
matrix – A numpy array representing the adjacency matrix of the DAG, where 2 represents an edge from source to target, and 3 represents a reverse edge.
- Return type:
numpy.ndarray
- run(data, parameters, prepare_data=True)[source]
Runs the NoTears algorithm to learn a causal structure from the data.
- Parameters:
data (object) – The dataset to be used in the algorithm.
parameters (dict) – The parameters for the algorithm.
prepare_data (bool, optional) – If True, prepares the data before running the algorithm. Default is True.
- Returns:
A tuple containing the learned structure as a MEC graph (pywhy graph) and library results.
- Return type:
tuple
- Raises:
ValueError – If parameters are invalid or other issues arise during the algorithm run.