Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion lingam/longitudinal_lingam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
-------
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 10 additions & 1 deletion tests/test_longitudinal_lingam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down Expand Up @@ -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)
Expand Down