Skip to content

Commit

Permalink
Cleanup run simulation file PCMCI
Browse files Browse the repository at this point in the history
  • Loading branch information
teobucci committed Mar 25, 2024
1 parent 43532a2 commit 6bcdccf
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 109 deletions.
109 changes: 0 additions & 109 deletions hawk/analysis/run_simulation_pcmci.py

This file was deleted.

58 changes: 58 additions & 0 deletions hawk/analysis/simulation_pcmci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import time

from tigramite.pcmci import PCMCI


def run(
datasets,
config,
independence_tests,
):
params = config["params"]
dataset_name = config["dataset_name"]
dataframe = datasets[dataset_name]

independence_test = independence_tests[params["independencetest"]]
algorithm = params["algorithm"]
lag = params["lag"]

# Construct a unique identifier for the configuration
# param_str = "_".join(f"{k}{v}" for k, v in params.items())
# config_id = f"dataset{dataset_name}_{param_str}"

print(f"Running experiment with config: {config}")

pcmci = PCMCI(dataframe=dataframe["full_tigramite"], cond_ind_test=independence_test, verbosity=2)

start_time = time.time()
if algorithm == "pcmci":
results = pcmci.run_pcmci(tau_max=lag, pc_alpha=0.05, alpha_level=0.01)
elif algorithm == "pcmci_plus":
results = pcmci.run_pcmciplus(tau_min=0, tau_max=lag)
else:
raise ValueError(f"Invalid algorithm {algorithm}")
end_time = time.time()
execution_time = end_time - start_time

q_matrix = pcmci.get_corrected_pvalues(
p_matrix=results["p_matrix"],
tau_max=lag,
fdr_method="fdr_bh",
)

graph = pcmci.get_graph_from_pmatrix(
p_matrix=q_matrix,
alpha_level=0.01,
tau_min=0,
tau_max=lag,
link_assumptions=None,
)

results["graph"] = graph

return {
"results": results,
"params": params,
"dataset_name": dataset_name,
"execution_time": execution_time,
}

0 comments on commit 6bcdccf

Please sign in to comment.