Skip to content

Commit de76e1d

Browse files
authored
Merge pull request #80 from DynamicsAndNeuralSystems/jmoo2880-norm-detrend-fix
Change default detrend setting
2 parents 8d42f97 + 3969c28 commit de76e1d

File tree

7 files changed

+25
-27
lines changed

7 files changed

+25
-27
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "pyspi"
7-
version = "2.0.0"
7+
version = "2.0.1"
88
authors = [
99
{ name ="Oliver M. Cliff", email="[email protected]"},
1010
]

pyspi/calculator.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class Calculator:
1717
"""Compute all pairwise interactions.
1818
19-
The calculator takes in a multivariate time-series dataset, computes and stores all pairwise interactions for the dataset.
19+
The calculator takes in a multivariate time-series dataset (MTS), computes and stores all pairwise interactions for the dataset.
2020
It uses a YAML configuration file that can be modified in order to compute a reduced set of pairwise methods.
2121
2222
Example:
@@ -27,26 +27,25 @@ class Calculator:
2727
2828
Args:
2929
dataset (:class:`~pyspi.data.Data`, array_like, optional):
30-
The multivariate time series of M processes and T observations, defaults to None.
30+
The multivariate time series of M processes and T observations, default=None.
3131
name (str, optional):
32-
The name of the calculator. Mainly used for printing the results but can be useful if you have multiple instances, defaults to None.
32+
The name of the calculator. Mainly used for printing the results but can be useful if you have multiple instances, default=None.
3333
labels (array_like, optional):
34-
Any set of strings by which you want to label the calculator. This can be useful later for classification purposes, defaults to None.
34+
Any set of strings by which you want to label the calculator. This can be useful later for classification purposes, default=None.
3535
subset (str, optional):
36-
A pre-configured subset of SPIs to use. Options are "all", "fast", "sonnet", or "fabfour", defaults to "all".
36+
A pre-configured subset of SPIs to use. Options are "all", "fast", "sonnet", or "fabfour", default="all".
3737
configfile (str, optional):
3838
The location of the YAML configuration file for a user-defined subset. See :ref:`Using a reduced SPI set`, defaults to :code:`'</path/to/pyspi>/pyspi/config.yaml'`
3939
detrend (bool, optional):
40-
If True, detrend the dataset along the time axis before normalising (if enabled), defaults to True.
40+
If True, detrend each time series in the MTS dataset individually along the time axis, default=False.
4141
normalise (bool, optional):
42-
If True, z-score normalise the dataset along the time axis before computing SPIs, defaults to True.
43-
Detrending (if enabled) is always applied before normalisation.
42+
If True, z-score normalise each time series in the MTS dataset individually along the time axis, default=True.
4443
"""
4544
_optional_dependencies = None
4645

4746
def __init__(
4847
self, dataset=None, name=None, labels=None, subset="all", configfile=None,
49-
detrend=True, normalise=True
48+
detrend=False, normalise=True
5049
):
5150
self._spis = {}
5251
self._excluded_spis = list()
@@ -511,7 +510,7 @@ def init_from_list(self, datasets, names, labels, **kwargs):
511510
self.add_calculator(calc)
512511

513512
def init_from_yaml(
514-
self, document, detrend=True, normalise=True, n_processes=None, n_observations=None, **kwargs
513+
self, document, detrend=False, normalise=True, n_processes=None, n_observations=None, **kwargs
515514
):
516515
datasets = []
517516
names = []

pyspi/data.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,29 @@ class Data:
3838
3939
Args:
4040
data (array_like, optional):
41-
2-dimensional array with raw data, defaults to None.
41+
2-dimensional array with raw data, default=None.
4242
dim_order (str, optional):
43-
Order of dimensions, accepts two combinations of the characters 'p', and 's' for processes and observations, defaults to 'ps'.
43+
Order of dimensions, accepts two combinations of the characters 'p', and 's' for processes and observations, default='ps'.
4444
detrend (bool, optional):
45-
If True, detrend the dataset along the time axis before normalising (if enabled), defaults to True.
45+
If True, detrend each time series in the MTS dataset individually along the time axis, default=False.
4646
normalise (bool, optional):
47-
If True, z-score normalise the dataset along the time axis before computing SPIs, defaults to True.
48-
Detrending (if enabled) is always applied before normalisation.
47+
If True, z-score normalise each time series in the MTS dataset individually along the time axis, default=True.
4948
name (str, optional):
5049
Name of the dataset
5150
procnames (list, optional):
52-
List of process names with length the number of processes, defaults to None.
51+
List of process names with length the number of processes, default=None.
5352
n_processes (int, optional):
54-
Truncates data to this many processes, defaults to None.
53+
Truncates data to this many processes, default=None.
5554
n_observations (int, optional):
56-
Truncates data to this many observations, defaults to None.
55+
Truncates data to this many observations, default=None.
5756
5857
"""
5958

6059
def __init__(
6160
self,
6261
data=None,
6362
dim_order="ps",
64-
detrend=True,
63+
detrend=False,
6564
normalise=True,
6665
name=None,
6766
procnames=None,
@@ -183,19 +182,19 @@ def set_data(
183182
data = data[:, :n_observations]
184183

185184
if self.detrend:
186-
print(Fore.GREEN + "[1/2] De-trending the dataset...")
185+
print(Fore.GREEN + "[1/2] Detrending time series in the dataset...")
187186
try:
188187
data = detrend(data, axis=1)
189188
except ValueError as err:
190189
print(f"Could not detrend data: {err}")
191190
else:
192-
print(Fore.RED + "[1/2] Skipping detrending of the dataset...")
191+
print(Fore.RED + "[1/2] Skipping detrending of time series in the dataset...")
193192

194193
if self.normalise:
195-
print(Fore.GREEN + "[2/2] Normalising (z-scoring) the dataset...\n")
194+
print(Fore.GREEN + "[2/2] Normalising (z-scoring) each time series in the dataset...\n")
196195
data = zscore(data, axis=1, nan_policy="omit", ddof=1)
197196
else:
198-
print(Fore.RED + "[2/2] Skipping normalisation of the dataset...\n")
197+
print(Fore.RED + "[2/2] Skipping normalisation of time series in the dataset...\n")
199198

200199
nans = np.isnan(data)
201200
if nans.any():

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
'data/standard_normal.npy',
6565
'data/cml7.npy']},
6666
include_package_data=True,
67-
version='2.0.0',
67+
version='2.0.1',
6868
description='Library for pairwise analysis of time series data.',
6969
author='Oliver M. Cliff',
7070
author_email='[email protected]',

tests/CML7_benchmark_tables.pkl

0 Bytes
Binary file not shown.

tests/generate_benchmark_tables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def get_benchmark_tables(calc_list):
2929

3030
for i in range(10):
3131
np.random.seed(42)
32-
calc = Calculator(dataset=dataset, detrend=True, normalise=True)
32+
calc = Calculator(dataset=dataset)
3333
calc.compute()
3434
store_calcs.append(calc)
3535

tests/test_SPIs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def compute_new_tables():
2424
benchmark_dataset = load_benchmark_dataset()
2525
# Compute new tables on the benchmark dataset
2626
np.random.seed(42)
27-
calc = Calculator(dataset=benchmark_dataset, normalise=True, detrend=True)
27+
calc = Calculator(dataset=benchmark_dataset)
2828
calc.compute()
2929
table_dict = dict()
3030
for spi in calc.spis:

0 commit comments

Comments
 (0)