Skip to content

Commit

Permalink
adding renewed demo data
Browse files Browse the repository at this point in the history
  • Loading branch information
MacBook di Paolo authored and MacBook di Paolo committed Apr 25, 2024
1 parent b4ff42d commit fd211a6
Show file tree
Hide file tree
Showing 7 changed files with 914 additions and 914 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added hawk/.DS_Store
Binary file not shown.
89 changes: 44 additions & 45 deletions hawk/analysis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ def run_baseline_analysis(self):
baseline = {}

features_names = self.datasets["normal"]["var_names"]

print(f"features_names: {features_names}")

configs = []

# Only autoregressive baselines from 1 to the maximum target lag
# Only autoregressive baselines from 1 to the maximum target lag
for i in range(1, self.tefs_max_lag_target+1):
configs.append((f"AR({i})", {self.target_column_name: list(range(1, i + 1))}))

print(f"AR configs: {configs}")

# All features without AR
Expand All @@ -100,18 +100,19 @@ def run_baseline_analysis(self):
{feature: self.tefs_features_lags for feature in features_names if feature != self.target_column_name},
)
)

print(f"Full configs: {configs}")

# All features with AR
configs.append(
(
"All features and AR",
{feature: self.tefs_features_lags if feature != self.target_column_name else list(range(1, self.tefs_max_lag_target+1)) for feature in features_names},
{feature: self.tefs_features_lags if feature != self.target_column_name
else list(range(1, self.tefs_max_lag_target+1)) for feature in features_names},
)
)
print(f"Full configs: {configs}")

print(f"Full configs: {configs}")

for label, inputs_names_lags in configs:
baseline[label] = {
Expand All @@ -123,7 +124,7 @@ def run_baseline_analysis(self):
df_test=self.datasets["normal"]["test"],
),
}

print(f"Baselines: {baseline}")

target_file = os.path.join(self.workdir, "baseline.pkl")
Expand Down Expand Up @@ -170,7 +171,7 @@ def run_tefs_analysis(
"dataset_name": dataset_name,
}
configurations.append(configuration)

print(f"TEFS configurations: {configurations}")

# Run the analysis
Expand All @@ -183,7 +184,7 @@ def run_tefs_analysis(
config=config,
)
)

print(f"TEFS results: {results}")

return results
Expand All @@ -195,14 +196,14 @@ def run_pcmci_analysis(

# Define the tests
parcorr = ParCorr(significance="analytic")
#cmiknn = CMIknn(
# significance="shuffle_test",
# knn=0.1,
# shuffle_neighbors=5,
# transform="ranks",
# sig_samples=200,
#)
cmiknn = CMIknn()
cmiknn = CMIknn(
significance="shuffle_test",
knn=0.1,
shuffle_neighbors=5,
transform="ranks",
sig_samples=200,
)
# cmiknn = CMIknn()

# Create the dictionary of tests
independence_tests = {
Expand Down Expand Up @@ -238,7 +239,7 @@ def run_pcmci_analysis(
"dataset_name": dataset_name,
}
configurations.append(configuration)

print(f'PCMCI configurations: {configurations}')

# Run the analysis
Expand All @@ -252,9 +253,7 @@ def run_pcmci_analysis(
)
)
print(f"PCMCI+ results: {results}")

save_to_pkl_file("/work/bk1318/b382633/pcmci_results.pkl", results)


return results

def run(self):
Expand All @@ -264,19 +263,19 @@ def run(self):
if self.response:
self.response.update_status("Performing TEFS analysis", 33)
tefs_results = self.run_tefs_analysis()
#if self.response:
# self.response.update_status("Performing PCMCI analysis", 66)
#pcmci_results = self.run_pcmci_analysis()

#if self.response:
# self.response.update_status("Postprocessing PCMCI", 80)
#self.plot_pcmci, self.details_pcmci = run_postprocessing_pcmci(
# results_pcmci=pcmci_results,
# target_column_name=self.target_column_name,
# datasets=self.datasets,
# destination_path=self.workdir,
# image_formats=["pdf", "png"],
#)
if self.response:
self.response.update_status("Performing PCMCI analysis", 66)
pcmci_results = self.run_pcmci_analysis()

if self.response:
self.response.update_status("Postprocessing PCMCI", 80)
self.plot_pcmci, self.details_pcmci = run_postprocessing_pcmci(
results_pcmci=pcmci_results,
target_column_name=self.target_column_name,
datasets=self.datasets,
destination_path=self.workdir,
image_formats=["pdf", "png"],
)
if self.response:
self.response.update_status("Postprocessing TEFS", 90)
self.plot_tefs, self.details_tefs = run_postprocessing_tefs(
Expand All @@ -286,12 +285,12 @@ def run(self):
destination_path=self.workdir,
image_formats=["pdf", "png"],
)
#if self.response:
# self.response.update_status("Postprocessing TEFS Wrapper", 95)
#self.plot_tefs_wrapper, self.details_tefs_wrapper = run_postprocessing_tefs_wrapper(
# results_tefs=tefs_results,
# target_column_name=self.target_column_name,
# datasets=self.datasets,
# destination_path=self.workdir,
# image_formats=["pdf", "png"],
#)
if self.response:
self.response.update_status("Postprocessing TEFS Wrapper", 95)
self.plot_tefs_wrapper, self.details_tefs_wrapper = run_postprocessing_tefs_wrapper(
results_tefs=tefs_results,
target_column_name=self.target_column_name,
datasets=self.datasets,
destination_path=self.workdir,
image_formats=["pdf", "png"],
)
5 changes: 3 additions & 2 deletions hawk/analysis/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .file_management import save_to_pkl_file
from .pcmci_tools import get_connected_variables


# Adjusted custom sort key function to handle lag sequences and replace them with the last lag
def general_custom_sort_key(s):
# Find all sequences like [0,1], [1,2,3,5,6], etc.
Expand Down Expand Up @@ -262,7 +263,7 @@ def run_postprocessing_pcmci(
plt.savefig(target_file_plot, bbox_inches="tight")
target_file_plots[image_format] = target_file_plot
plt.close(fig)

print(f"PCMCI results details: {results_table_pcmci}")

return target_file_plots, target_file_results_details
Expand Down Expand Up @@ -349,7 +350,7 @@ def run_postprocessing_tefs(
# Export the file to pkl
target_file_results_details = os.path.join(destination_path, "results_details_te.pkl")
save_to_pkl_file(target_file_results_details, results_table_te)

print(f"results_table_te: {results_table_te}")

# Feature presences heatmap
Expand Down
Binary file added hawk/demo/.DS_Store
Binary file not shown.
Loading

0 comments on commit fd211a6

Please sign in to comment.