ETIA.CausalLearning.algorithms.tetrad_algorithm package

Submodules

ETIA.CausalLearning.algorithms.tetrad_algorithm.TetradAlgorithm module

class TetradAlgorithm(algorithm, verbose=False)[source]

Bases: object

A class that implements various causal discovery algorithms using the Tetrad library.

mute_java_output()[source]

Mutes Java’s standard output and error streams.

configure_java_logging()[source]

Configures Java’s Log4j logging for the Tetrad package.

init_algo(data_info)[source]

Initializes algorithm-specific data, such as lags and time information.

prepare_data(Data, parameters=None)[source]

Prepares the data in a format suitable for the Tetrad algorithms.

time_knowledge(ds)[source]

Defines the time-knowledge for time-lagged datasets.

_ci_test(ds, parameters)[source]

Configures the appropriate conditional independence test for the algorithm.

_score(ds, parameters)[source]

Configures the appropriate score-based test for the algorithm.

_algo(parameters, ind_test, score)[source]

Configures and returns the specified causal discovery algorithm.

output_to_array(tetrad_graph_, var_map)[source]

Converts the Tetrad graph to a numpy array representing the causal structure.

check_parameters(parameters, data_info)[source]

Validates the parameters required to run the Tetrad algorithm.

run(data, parameters, prepare_data=True)[source]

Runs the specified Tetrad algorithm on the provided data and returns the results.

mute_java_output()[source]

Mutes Java’s standard output and error streams to suppress logs and output.

configure_java_logging()[source]

Configures Java’s Log4j logging level for Tetrad algorithms.

init_algo(data_info)[source]

Initializes the algorithm with data type and time information.

Parameters:

data_info (dict) – Dictionary containing information about data types and time lags.

prepare_data(Data, parameters=None)[source]

Prepares the dataset for use in the Tetrad algorithms.

Parameters:
  • Data (object) – The dataset to be used in the algorithm.

  • parameters (dict, optional) – Additional parameters for data preparation. Default is None.

Returns:

A tuple containing the prepared dataset and a mapping of variable names.

Return type:

tuple

time_knowledge(ds)[source]

Generates temporal knowledge for time-lagged data.

Parameters:

ds (object) – The dataset in Tetrad format.

Returns:

knowledge – A Tetrad Knowledge object that encodes the temporal relationships in the data.

Return type:

object

add_knowledge(ds, var_map, prior_knowledge)[source]
output_to_array(tetrad_graph_, var_map)[source]

Converts the Tetrad graph to a numpy array representation.

Parameters:
  • tetrad_graph (object) – The Tetrad graph object to be converted.

  • var_map (pd.DataFrame) – A DataFrame mapping Tetrad variable names to original variable names.

Returns:

matrix_pd – A pandas DataFrame representing the adjacency matrix of the learned graph.

Return type:

pd.DataFrame

check_parameters(parameters, data_info)[source]

Checks the validity of the parameters for running the Tetrad algorithm.

Parameters:
  • parameters (dict) – The algorithm parameters.

  • data_info (dict) – Information about the dataset, such as variable types.

Returns:

True if all parameters are valid, raises RuntimeError otherwise.

Return type:

bool

run(data, parameters, prepare_data=True)[source]

Runs the Tetrad algorithm on the provided data.

Parameters:
  • data (object) – The dataset to be used in the algorithm.

  • parameters (dict) – The parameters for running the algorithm.

  • prepare_data (bool, optional) – If True, prepares the data before running the algorithm. Default is True.

Returns:

A tuple containing the learned MEC graph and a dictionary of results.

Return type:

tuple