ETIA.CausalLearning.algorithms.cdt_algorithms package
Submodules
ETIA.CausalLearning.algorithms.cdt_algorithms.SAMAlgorithm module
- class SAMAlgorithm(algorithm='sam', verbose=False)[source]
Bases:
objectA class that implements the SAM (Structural Agnostic Model) algorithm for causal discovery.
- prepare_data(data)[source]
Prepares the data for the SAM algorithm by converting it to a pandas DataFrame.
- set_parameters(parameters)[source]
Sets the algorithm’s parameters from a provided dictionary, using defaults where necessary.
- run(data, parameters, prepare_data=True)[source]
Runs the SAM algorithm on the provided data and parameters, and returns the learned causal structure.
- check_parameters()[source]
Validates the parameters required for running the SAM algorithm.
- Returns:
True if all parameters are valid, raises ValueError otherwise.
- Return type:
bool
- Raises:
ValueError – If any parameter is out of the valid range or not of the expected type.
- prepare_data(data)[source]
Prepares the data for the SAM algorithm by converting it to a pandas DataFrame if necessary.
- Parameters:
data (any) – The dataset to be used. Can be a pandas DataFrame or an object that implements the get_dataset method.
- Returns:
data – The prepared dataset as a pandas DataFrame.
- Return type:
pandas.DataFrame
- set_parameters(parameters)[source]
Sets the parameters for the SAM algorithm, using default values where necessary.
- Parameters:
parameters (dict) – A dictionary containing the parameters to set, such as learning rates, lambda values, number of hidden units, etc.
- Raises:
ValueError – If any of the parameters are invalid.
- run(data, parameters, prepare_data=True)[source]
Runs the SAM algorithm on the provided data and parameters.
- Parameters:
data (any) – The dataset to be used, either as a pandas DataFrame or an object implementing get_dataset.
parameters (dict) – The parameters to configure the SAM algorithm.
prepare_data (bool, optional) – If True, the data will be prepared before running the algorithm. Default is True.
- Returns:
A tuple containing: - mec_graph : DAGWrapper
The learned causal structure represented as a graph.
- library_resultsdict
A dictionary containing the resulting graph and additional results.
- Return type:
tuple
- Raises:
ValueError – If any of the parameters are invalid.