Skip to content

Commit

Permalink
Merge pull request #186 from jakobrunge/developer
Browse files Browse the repository at this point in the history
removed ValueError for constants in arrays
  • Loading branch information
jakobrunge authored Mar 16, 2022
2 parents 7546626 + b257377 commit 29c5579
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 21 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def run(self):
# Run the setup
setup(
name="tigramite",
version="5.0.0.5",
version="5.0.0.6",
packages=["tigramite", "tigramite.independence_tests", "tigramite.toymodels"],
license="GNU General Public License v3.0",
description="Tigramite causal discovery for time series",
Expand Down
24 changes: 16 additions & 8 deletions tigramite/independence_tests/cmiknn.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,16 @@ def _get_nearest_neighbors(self, array, xyz, knn):
# Standardize
array = array.astype(np.float64)
array -= array.mean(axis=1).reshape(dim, 1)
array /= array.std(axis=1).reshape(dim, 1)
std = array.std(axis=1)
for i in range(dim):
if std[i] != 0.:
array[i] /= std[i]
# array /= array.std(axis=1).reshape(dim, 1)
# FIXME: If the time series is constant, return nan rather than
# raising Exception
if np.isnan(array).sum() != 0:
raise ValueError("nans after standardizing, "
"possibly constant array!")
# if np.isnan(array).sum() != 0:
# raise ValueError("nans after standardizing, "
# "possibly constant array!")
elif self.transform == 'uniform':
array = self._trafo2uniform(array)
elif self.transform == 'ranks':
Expand Down Expand Up @@ -376,12 +380,16 @@ def get_conditional_entropy(self, array, xyz):
# Standardize
array = array.astype(np.float64)
array -= array.mean(axis=1).reshape(dim, 1)
array /= array.std(axis=1).reshape(dim, 1)
std = array.std(axis=1)
for i in range(dim):
if std[i] != 0.:
array[i] /= std[i]
# array /= array.std(axis=1).reshape(dim, 1)
# FIXME: If the time series is constant, return nan rather than
# raising Exception
if np.isnan(array).sum() != 0:
raise ValueError("nans after standardizing, "
"possibly constant array!")
# if np.isnan(array).sum() != 0:
# raise ValueError("nans after standardizing, "
# "possibly constant array!")
elif self.transform == 'uniform':
array = self._trafo2uniform(array)
elif self.transform == 'ranks':
Expand Down
12 changes: 8 additions & 4 deletions tigramite/independence_tests/gpdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,14 @@ def _get_single_residuals(self, array, target_var,
# Standardize
if standardize:
array -= array.mean(axis=1).reshape(dim, 1)
array /= array.std(axis=1).reshape(dim, 1)
if np.isnan(array).sum() != 0:
raise ValueError("nans after standardizing, "
"possibly constant array!")
std = array.std(axis=1)
for i in range(dim):
if std[i] != 0.:
array[i] /= std[i]
# array /= array.std(axis=1).reshape(dim, 1)
# if np.isnan(array).sum() != 0:
# raise ValueError("nans after standardizing, "
# "possibly constant array!")

target_series = array[target_var, :]
z = np.fastCopyAndTranspose(array[2:])
Expand Down
12 changes: 8 additions & 4 deletions tigramite/independence_tests/gpdc_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,14 @@ def _get_single_residuals(self, array, target_var,
# Standardize
if standardize:
array -= array.mean(axis=1).reshape(dim, 1)
array /= array.std(axis=1).reshape(dim, 1)
if np.isnan(array).any():
raise ValueError("Nans after standardizing, "
"possibly constant array!")
std = array.std(axis=1)
for i in range(dim):
if std[i] != 0.:
array[i] /= std[i]
# array /= array.std(axis=1).reshape(dim, 1)
# if np.isnan(array).any():
# raise ValueError("Nans after standardizing, "
# "possibly constant array!")

target_series = array[target_var, :]
z = np.fastCopyAndTranspose(array[2:])
Expand Down
12 changes: 8 additions & 4 deletions tigramite/independence_tests/parcorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ def _get_single_residuals(self, array, target_var,
# Standardize
if standardize:
array -= array.mean(axis=1).reshape(dim, 1)
array /= array.std(axis=1).reshape(dim, 1)
if np.isnan(array).sum() != 0:
raise ValueError("nans after standardizing, "
"possibly constant array!")
std = array.std(axis=1)
for i in range(dim):
if std[i] != 0.:
array[i] /= std[i]
# array /= array.std(axis=1).reshape(dim, 1)
# if np.isnan(array).sum() != 0:
# raise ValueError("nans after standardizing, "
# "possibly constant array!")

y = array[target_var, :]

Expand Down

0 comments on commit 29c5579

Please sign in to comment.