diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b954f22..8af2c7c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 @@ -43,7 +43,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 diff --git a/lingam/longitudinal_lingam.py b/lingam/longitudinal_lingam.py index 8a697c9..7a91da3 100644 --- a/lingam/longitudinal_lingam.py +++ b/lingam/longitudinal_lingam.py @@ -191,7 +191,7 @@ def fit(self, X_list): return self - def bootstrap(self, X_list, n_sampling, start_from_t=1): + def bootstrap(self, X_list, n_sampling, start_from_t=None): """Evaluate the statistical reliability of DAG based on the bootstrapping. Parameters @@ -202,6 +202,8 @@ def bootstrap(self, X_list, n_sampling, start_from_t=1): where ``n_samples`` is the number of samples and ``n_features`` is the number of features. n_sampling : int Number of bootstrapping samples. + start_from_t : int, optional + The time step to calculate total effects from. If None, defaults to the number of lags. Returns ------- @@ -225,6 +227,13 @@ def bootstrap(self, X_list, n_sampling, start_from_t=1): raise ValueError("X_list must be a list with the same shape") X_t.append(X) + # Check and set start_from_t + if start_from_t is None: + start_from_t = self._n_lags + else: + if start_from_t < self._n_lags: + raise ValueError(f"start_from_t must be greater than or equal to n_lags ({self._n_lags})") + # Bootstrapping adjacency_matrices = np.zeros( (n_sampling, self._T, 1 + self._n_lags, self._p, self._p) diff --git a/pyproject.toml b/pyproject.toml index ac1ad15..f67d672 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,11 +17,11 @@ authors = [ { name = "Shohei Shimizu" } ] license = { file = "LICENSE" } -requires-python = ">=3.9" +requires-python = ">=3.10" dependencies = [ "numpy", - "scipy", - "scikit-learn", + "scipy<=1.13.1", + "scikit-learn>=1.6", "graphviz", "statsmodels", "networkx", diff --git a/requirements.txt b/requirements.txt index d3cd678..2f2d4cc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ numpy -scipy<=1.13.1 -scikit-learn>=1.2 +scipy<=1.13.1 # Scipy version limitation due to semopy using the deprecated scipy.stats.mvn. +scikit-learn>=1.6 # sklearn.utils.check_array with the ensure_all_finite argument. graphviz statsmodels networkx diff --git a/tests/test_longitudinal_lingam.py b/tests/test_longitudinal_lingam.py index be16cfe..c363508 100644 --- a/tests/test_longitudinal_lingam.py +++ b/tests/test_longitudinal_lingam.py @@ -289,7 +289,7 @@ def test_bootstrap_success(): # fit by list X_list = [X1, X2, X3] model = LongitudinalLiNGAM() - result = model.bootstrap(X_list, n_sampling=3) + result = model.bootstrap(X_list, n_sampling=3, start_from_t=1) result.adjacency_matrices_ result.total_effects_ @@ -532,6 +532,15 @@ def test_bootstrap_invalid_data(): else: raise AssertionError + # Invalid argument: start_from_t must be greater than or equal to n_lags + model = LongitudinalLiNGAM(n_lags=2) + try: + result = model.bootstrap(X_list, n_sampling=3, start_from_t=1) + except ValueError: + pass + else: + raise AssertionError + # Invalid argument: get_causal_direction_counts(n_directions=-1) model = LongitudinalLiNGAM() result = model.bootstrap(X_list, n_sampling=5)