Skip to content

Commit

Permalink
Merge branch 'main' into dev_docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nilshempelmann authored May 29, 2024
2 parents 8f1e354 + 81ede17 commit 89dcf32
Show file tree
Hide file tree
Showing 12 changed files with 990 additions and 1,026 deletions.
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Hawk
:alt: Join the chat at https://gitter.im/bird-house/birdhouse

Hawk (the bird)
*Hawk is a bird designed to perform causal analysis for climate data or, in general, for spatio-temporal data.*
*Hawk is a bird designed to perform causal analysis for climate data or, in general, for time-series.*


Documentation
Expand All @@ -44,7 +44,7 @@ License
-------

* Free software: GNU General Public License v3
* Documentation: https://hawk.readthedocs.io.
* Documentation: https://clint-hawk.readthedocs.io.


Credits
Expand All @@ -59,4 +59,4 @@ The two Python libraries TEFS_ and tigramite_ have been exploited to perform the
.. _`Developer Guide`: https://hawk.readthedocs.io/en/latest/dev_guide.html
.. _bump2version: https://hawk.readthedocs.io/en/latest/dev_guide.html#bump-a-new-version
.. _tigramite: https://github.com/jakobrunge/tigramite
.. _TEFS: https://github.com/teobucci/tefs
.. _TEFS: https://github.com/teobucci/tefs
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- psutil
- birdy
#- tigramite
#- tefs
#- tefs==0.3.1
- pandas
- scikit-learn
- numpy
Expand Down
25 changes: 18 additions & 7 deletions hawk/analysis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import os

import pandas as pd
from tefs.metrics import regression_analysis
from tigramite.independence_tests.cmiknn import CMIknn
from tigramite.independence_tests.parcorr import ParCorr

from .file_management import save_to_pkl_file
from .metrics import regression_analysis
from .pcmci_tools import initialize_tigramite_df
from .postprocessing import (
run_postprocessing_pcmci,
Expand Down Expand Up @@ -63,7 +63,8 @@ def __init__(
self.tefs_features_lags = []
if self.tefs_use_contemporary_features:
self.tefs_features_lags.append(0)
self.tefs_features_lags.extend(list(range(1, self.tefs_max_lag_features + 1)))
if self.tefs_max_lag_features > 0:
self.tefs_features_lags.extend(list(range(1, self.tefs_max_lag_features + 1)))

self.tefs_target_lags = list(range(1, self.tefs_max_lag_target + 1))

Expand All @@ -84,15 +85,24 @@ def run_baseline_analysis(self):

configs = []

# Autoregressive baselines
for i in range(1, self.tefs_max_lag_target):
# 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))}))

# With all features
# All features without AR
configs.append(
(
"All features",
{feature: self.tefs_features_lags for feature in features_names},
{feature: self.tefs_features_lags for feature in features_names if feature != self.target_column_name},
)
)

# 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},
)
)

Expand Down Expand Up @@ -168,7 +178,7 @@ def run_tefs_analysis(
def run_pcmci_analysis(
self,
):
lag_options = self.pcmci_features_lags # max lag
lag_options = self.pcmci_features_lags # list from 0 to max_lag

# Define the tests
parcorr = ParCorr(significance="analytic")
Expand All @@ -179,6 +189,7 @@ def run_pcmci_analysis(
transform="ranks",
sig_samples=200,
)
# cmiknn = CMIknn()

# Create the dictionary of tests
independence_tests = {
Expand Down
124 changes: 0 additions & 124 deletions hawk/analysis/metrics.py

This file was deleted.

8 changes: 5 additions & 3 deletions hawk/analysis/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import numpy as np
import pandas as pd
import seaborn as sns
from tefs.metrics import regression_analysis

# from tigramite import plotting as tp
from .file_management import save_to_pkl_file
from .metrics import regression_analysis
from .pcmci_tools import get_connected_variables


Expand Down Expand Up @@ -257,7 +257,7 @@ def run_postprocessing_pcmci(
target_file_plots = {}
for image_format in image_formats:
target_file_plot = os.path.join(
destination_path, "algorithm_results", "pcmci", f"feature_presence.{image_format}"
destination_path, "algorithm_results", "pcmci", f"feature_presence_pcmci.{image_format}"
)
os.makedirs(os.path.dirname(target_file_plot), exist_ok=True)
plt.savefig(target_file_plot, bbox_inches="tight")
Expand Down Expand Up @@ -384,7 +384,9 @@ def run_postprocessing_tefs(
)
target_file_plots = {}
for image_format in image_formats:
target_file_plot = os.path.join(destination_path, "algorithm_results", "te", f"feature_presence.{image_format}")
target_file_plot = os.path.join(
destination_path, "algorithm_results", "te", f"feature_presence_tefs.{image_format}"
)
os.makedirs(os.path.dirname(target_file_plot), exist_ok=True)
plt.savefig(target_file_plot, bbox_inches="tight")
target_file_plots[image_format] = target_file_plot
Expand Down
Loading

0 comments on commit 89dcf32

Please sign in to comment.