tslearn 0.6.2__tar.gz → 0.6.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tslearn-0.6.2 → tslearn-0.6.3}/PKG-INFO +1 -1
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/__init__.py +1 -1
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/backend/__init__.py +2 -1
- tslearn-0.6.3/tslearn/backend/backend.py +120 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/backend/numpy_backend.py +4 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/backend/pytorch_backend.py +4 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/bases/bases.py +3 -2
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/metrics/ctw.py +48 -26
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/metrics/cycc.py +17 -12
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/metrics/cysax.py +19 -12
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/metrics/dtw_variants.py +718 -209
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/metrics/sax.py +12 -8
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/metrics/soft_dtw_fast.py +96 -44
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/metrics/soft_dtw_loss_pytorch.py +7 -7
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/metrics/softdtw_variants.py +370 -111
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/metrics/utils.py +19 -10
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/shapelets/shapelets.py +13 -5
- tslearn-0.6.3/tslearn/tests/test_metrics.py +803 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/tests/test_shapelets.py +9 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/utils/utils.py +19 -8
- tslearn-0.6.2/tslearn/backend/backend.py +0 -153
- tslearn-0.6.2/tslearn/tests/test_metrics.py +0 -712
- {tslearn-0.6.2 → tslearn-0.6.3}/LICENSE +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/MANIFEST.in +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/README.md +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/conftest.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/pyproject.toml +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/setup.cfg +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/setup.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/.cached_datasets/Trace.npz +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/barycenters/__init__.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/barycenters/dba.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/barycenters/euclidean.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/barycenters/softdtw.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/barycenters/utils.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/bases/__init__.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/clustering/__init__.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/clustering/kmeans.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/clustering/kshape.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/clustering/utils.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/datasets/__init__.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/datasets/cached.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/datasets/datasets.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/datasets/ucr_uea.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/early_classification/__init__.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/early_classification/early_classification.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/generators/__init__.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/generators/generators.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/hdftools/__init__.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/hdftools/hdftools.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/matrix_profile/__init__.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/matrix_profile/matrix_profile.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/metrics/__init__.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/metrics/cycc.c +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/metrics/cysax.c +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/metrics/soft_dtw_fast.c +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/neighbors/__init__.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/neighbors/neighbors.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/neural_network/__init__.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/neural_network/neural_network.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/piecewise/__init__.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/piecewise/piecewise.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/preprocessing/__init__.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/preprocessing/preprocessing.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/shapelets/__init__.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/svm/__init__.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/svm/svm.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/tests/__init__.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/tests/sklearn_patches.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/tests/test_barycenters.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/tests/test_clustering.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/tests/test_estimators.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/tests/test_matrixprofile.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/tests/test_neighbors.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/tests/test_piecewise.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/tests/test_preprocessing.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/tests/test_serialize_models.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/tests/test_svm.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/tests/test_utils.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/tests/test_variablelength.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/utils/__init__.py +0 -0
- {tslearn-0.6.2 → tslearn-0.6.3}/tslearn/utils/cast.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import os
|
|
2
2
|
|
|
3
3
|
__author__ = 'Romain Tavenard romain.tavenard[at]univ-rennes2.fr'
|
|
4
|
-
__version__ = "0.6.
|
|
4
|
+
__version__ = "0.6.3"
|
|
5
5
|
__bibtex__ = r"""@article{JMLR:v21:20-091,
|
|
6
6
|
author = {Romain Tavenard and Johann Faouzi and Gilles Vandewiele and
|
|
7
7
|
Felix Divo and Guillaume Androz and Chester Holtz and
|
|
@@ -3,10 +3,11 @@ The :mod:`tslearn.backend` module provides multiple backends.
|
|
|
3
3
|
The backends provided are NumPy and PyTorch.
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
|
-
from .backend import Backend, instantiate_backend, select_backend
|
|
6
|
+
from .backend import Backend, cast, instantiate_backend, select_backend
|
|
7
7
|
|
|
8
8
|
__all__ = [
|
|
9
9
|
"Backend",
|
|
10
|
+
"cast",
|
|
10
11
|
"instantiate_backend",
|
|
11
12
|
"select_backend",
|
|
12
13
|
]
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""The generic backend."""
|
|
2
|
+
|
|
3
|
+
from tslearn.backend.numpy_backend import NumPyBackend
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
import torch
|
|
7
|
+
|
|
8
|
+
from tslearn.backend.pytorch_backend import PyTorchBackend
|
|
9
|
+
except ImportError:
|
|
10
|
+
|
|
11
|
+
class PyTorchBackend:
|
|
12
|
+
def __init__(self):
|
|
13
|
+
raise ValueError(
|
|
14
|
+
"Could not use pytorch backend since torch is not installed"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def instantiate_backend(*args):
|
|
19
|
+
"""Select backend.
|
|
20
|
+
|
|
21
|
+
Parameter
|
|
22
|
+
---------
|
|
23
|
+
*args : Input arguments can be Backend instance or string or array or None
|
|
24
|
+
Arguments used to define the backend instance.
|
|
25
|
+
|
|
26
|
+
Returns
|
|
27
|
+
-------
|
|
28
|
+
backend : Backend instance
|
|
29
|
+
The backend instance.
|
|
30
|
+
"""
|
|
31
|
+
for arg in args:
|
|
32
|
+
if isinstance(arg, Backend):
|
|
33
|
+
return arg
|
|
34
|
+
if "numpy" in f"{type(arg)}" or "numpy" in f"{arg}".lower():
|
|
35
|
+
return Backend("numpy")
|
|
36
|
+
if "torch" in f"{type(arg)}" or "torch" in f"{arg}".lower():
|
|
37
|
+
return Backend("pytorch")
|
|
38
|
+
return Backend("numpy")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def select_backend(data):
|
|
42
|
+
"""Select backend.
|
|
43
|
+
|
|
44
|
+
Parameter
|
|
45
|
+
---------
|
|
46
|
+
data : array-like or string or None
|
|
47
|
+
Indicates the backend to choose.
|
|
48
|
+
Optional, default equals None.
|
|
49
|
+
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
backend : class
|
|
53
|
+
The backend class.
|
|
54
|
+
If data is a Numpy array or data equals 'numpy' or data is None,
|
|
55
|
+
backend equals NumpyBackend().
|
|
56
|
+
If data is a PyTorch array or data equals 'pytorch',
|
|
57
|
+
backend equals PytorchBackend().
|
|
58
|
+
"""
|
|
59
|
+
if "torch" in f"{type(data)}" or "torch" in f"{data}".lower():
|
|
60
|
+
return PyTorchBackend()
|
|
61
|
+
return NumPyBackend()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class Backend(object):
|
|
65
|
+
"""Class for the backend.
|
|
66
|
+
|
|
67
|
+
Parameter
|
|
68
|
+
---------
|
|
69
|
+
data : array-like or string or None
|
|
70
|
+
Indicates the backend to choose.
|
|
71
|
+
If data is a Numpy array or data equals 'numpy' or data is None,
|
|
72
|
+
self.backend is set to NumpyBackend().
|
|
73
|
+
If data is a PyTorch array or data equals 'pytorch',
|
|
74
|
+
self.backend is set to PytorchBackend().
|
|
75
|
+
Optional, default equals None.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
def __init__(self, data=None):
|
|
79
|
+
self.backend = select_backend(data)
|
|
80
|
+
|
|
81
|
+
for element in dir(self.backend):
|
|
82
|
+
if "__" not in element:
|
|
83
|
+
setattr(self, element, getattr(self.backend, element))
|
|
84
|
+
|
|
85
|
+
self.is_numpy = self.backend_string == "numpy"
|
|
86
|
+
self.is_pytorch = self.backend_string == "pytorch"
|
|
87
|
+
|
|
88
|
+
def get_backend(self):
|
|
89
|
+
return self.backend
|
|
90
|
+
|
|
91
|
+
def set_backend(self, data=None):
|
|
92
|
+
self.backend = select_backend(data)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def cast(data, array_type="numpy"):
|
|
96
|
+
"""Cast data to list or specific backend.
|
|
97
|
+
|
|
98
|
+
Parameters
|
|
99
|
+
----------
|
|
100
|
+
data: array-like,
|
|
101
|
+
The input data should be a list or numpy array or torch array.
|
|
102
|
+
The data to cast.
|
|
103
|
+
array_type: string
|
|
104
|
+
The type to cast the data. It can be "numpy", "pytorch" or "list".
|
|
105
|
+
|
|
106
|
+
Returns
|
|
107
|
+
--------
|
|
108
|
+
data_cast: array-like
|
|
109
|
+
Data cast to array_type.
|
|
110
|
+
"""
|
|
111
|
+
data_type_string = f"{type(data)}".lower()
|
|
112
|
+
array_type = array_type.lower()
|
|
113
|
+
if array_type == "pytorch":
|
|
114
|
+
array_type = "torch"
|
|
115
|
+
if array_type in data_type_string:
|
|
116
|
+
return data
|
|
117
|
+
if array_type == "list":
|
|
118
|
+
return data.tolist()
|
|
119
|
+
be = Backend(array_type)
|
|
120
|
+
return be.array(data)
|
|
@@ -204,8 +204,9 @@ class BaseModelPackage:
|
|
|
204
204
|
model = cls._byte2string(model)
|
|
205
205
|
|
|
206
206
|
for k in model['hyper_params'].keys():
|
|
207
|
-
if model['hyper_params'][k]
|
|
208
|
-
model['hyper_params'][k]
|
|
207
|
+
if isinstance(model['hyper_params'][k], str):
|
|
208
|
+
if model['hyper_params'][k] == 'None':
|
|
209
|
+
model['hyper_params'][k] = None
|
|
209
210
|
|
|
210
211
|
return cls._organize_model(cls, model)
|
|
211
212
|
|
|
@@ -9,20 +9,21 @@ from .utils import _cdist_generic
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
def _get_warp_matrices(warp_path, be):
|
|
12
|
-
"""
|
|
13
|
-
Convert warping path sequence to matrices.
|
|
12
|
+
"""Convert warping path sequence to matrices.
|
|
14
13
|
|
|
15
14
|
Parameters
|
|
16
15
|
----------
|
|
17
|
-
warp_path : list of tuple of two indices that are matched together
|
|
16
|
+
warp_path : list of tuple of two indices that are matched together, length = m
|
|
18
17
|
First output of the dtw_path function.
|
|
19
18
|
be : Backend object or string
|
|
20
19
|
Backend.
|
|
21
20
|
|
|
22
21
|
Returns
|
|
23
22
|
-------
|
|
24
|
-
|
|
25
|
-
sequences
|
|
23
|
+
Wx : array-like, shape=(m, nx)
|
|
24
|
+
Matrix. The number of steps to match the two sequences is equal to m.
|
|
25
|
+
Wy : array-like, shape=(m, ny)
|
|
26
|
+
Matrix.
|
|
26
27
|
"""
|
|
27
28
|
be = instantiate_backend(be, warp_path[0][0])
|
|
28
29
|
# number of indices for the alignment
|
|
@@ -67,10 +68,10 @@ def ctw_path(
|
|
|
67
68
|
|
|
68
69
|
Parameters
|
|
69
70
|
----------
|
|
70
|
-
s1
|
|
71
|
-
A time series.
|
|
72
|
-
s2
|
|
73
|
-
Another time series.
|
|
71
|
+
s1 : array-like, shape=(sz1, d) or (sz1,)
|
|
72
|
+
A time series. If shape is (sz1,), the time series is assumed to be univariate.
|
|
73
|
+
s2 : array-like, shape=(sz2, d) or (sz2,)
|
|
74
|
+
Another time series. If shape is (sz2,), the time series is assumed to be univariate.
|
|
74
75
|
max_iter : int (default: 100)
|
|
75
76
|
Number of iterations for the CTW algorithm. Each iteration
|
|
76
77
|
n_components : int (default: None)
|
|
@@ -100,7 +101,12 @@ def ctw_path(
|
|
|
100
101
|
verbose : bool (default: True)
|
|
101
102
|
If True, scores are printed at each iteration of the algorithm.
|
|
102
103
|
be : Backend object or string or None
|
|
103
|
-
Backend.
|
|
104
|
+
Backend. If `be` is an instance of the class `NumPyBackend` or the string `"numpy"`,
|
|
105
|
+
the NumPy backend is used.
|
|
106
|
+
If `be` is an instance of the class `PyTorchBackend` or the string `"pytorch"`,
|
|
107
|
+
the PyTorch backend is used.
|
|
108
|
+
If `be` is `None`, the backend is determined by the input arrays.
|
|
109
|
+
See our :ref:`dedicated user-guide page <backend>` for more information.
|
|
104
110
|
|
|
105
111
|
Returns
|
|
106
112
|
-------
|
|
@@ -136,7 +142,7 @@ def ctw_path(
|
|
|
136
142
|
.. [1] F. Zhou and F. Torre, "Canonical time warping for alignment of
|
|
137
143
|
human behavior". NIPS 2009.
|
|
138
144
|
"""
|
|
139
|
-
be = instantiate_backend(be, s1)
|
|
145
|
+
be = instantiate_backend(be, s1, s2)
|
|
140
146
|
s1 = to_time_series(s1, remove_nans=True, be=be)
|
|
141
147
|
s2 = to_time_series(s2, remove_nans=True, be=be)
|
|
142
148
|
s1, s2 = be.array(s1, dtype=be.float64), be.array(s2, dtype=be.float64)
|
|
@@ -215,10 +221,10 @@ def ctw(
|
|
|
215
221
|
|
|
216
222
|
Parameters
|
|
217
223
|
----------
|
|
218
|
-
s1
|
|
219
|
-
A time series.
|
|
220
|
-
s2
|
|
221
|
-
Another time series.
|
|
224
|
+
s1 : array-like, shape=(sz1, d) or (sz1,)
|
|
225
|
+
A time series. If shape is (sz1,), the time series is assumed to be univariate.
|
|
226
|
+
s2 : array-like, shape=(sz2, d) or (sz2,)
|
|
227
|
+
Another time series. If shape is (sz2,), the time series is assumed to be univariate.
|
|
222
228
|
max_iter : int (default: 100)
|
|
223
229
|
Number of iterations for the CTW algorithm. Each iteration
|
|
224
230
|
n_components : int (default: None)
|
|
@@ -248,7 +254,12 @@ def ctw(
|
|
|
248
254
|
verbose : bool (default: True)
|
|
249
255
|
If True, scores are printed at each iteration of the algorithm.
|
|
250
256
|
be : Backend object or string or None
|
|
251
|
-
Backend.
|
|
257
|
+
Backend. If `be` is an instance of the class `NumPyBackend` or the string `"numpy"`,
|
|
258
|
+
the NumPy backend is used.
|
|
259
|
+
If `be` is an instance of the class `PyTorchBackend` or the string `"pytorch"`,
|
|
260
|
+
the PyTorch backend is used.
|
|
261
|
+
If `be` is `None`, the backend is determined by the input arrays.
|
|
262
|
+
See our :ref:`dedicated user-guide page <backend>` for more information.
|
|
252
263
|
|
|
253
264
|
Returns
|
|
254
265
|
-------
|
|
@@ -271,7 +282,9 @@ def ctw(
|
|
|
271
282
|
.. [1] F. Zhou and F. Torre, "Canonical time warping for alignment of
|
|
272
283
|
human behavior". NIPS 2009.
|
|
273
284
|
"""
|
|
274
|
-
be = instantiate_backend(be, s1)
|
|
285
|
+
be = instantiate_backend(be, s1, s2)
|
|
286
|
+
s1 = be.array(s1)
|
|
287
|
+
s2 = be.array(s2)
|
|
275
288
|
return ctw_path(
|
|
276
289
|
s1=s1,
|
|
277
290
|
s2=s2,
|
|
@@ -311,11 +324,15 @@ def cdist_ctw(
|
|
|
311
324
|
|
|
312
325
|
Parameters
|
|
313
326
|
----------
|
|
314
|
-
dataset1 : array-like
|
|
315
|
-
A dataset of time series
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
327
|
+
dataset1 : array-like, shape=(n_ts1, sz1, d) or (n_ts1, sz1) or (sz1,)
|
|
328
|
+
A dataset of time series.
|
|
329
|
+
If shape is (n_ts1, sz1), the dataset is composed of univariate time series.
|
|
330
|
+
If shape is (sz1,), the dataset is composed of a unique univariate time series.
|
|
331
|
+
dataset2 : None or array-like, shape=(n_ts2, sz2, d) or (n_ts2, sz2) or (sz2,) (default: None)
|
|
332
|
+
Another dataset of time series.
|
|
333
|
+
If `None`, self-similarity of `dataset1` is returned.
|
|
334
|
+
If shape is (n_ts2, sz2), the dataset is composed of univariate time series.
|
|
335
|
+
If shape is (sz2,), the dataset is composed of a unique univariate time series.
|
|
319
336
|
max_iter : int (default: 100)
|
|
320
337
|
Number of iterations for the CTW algorithm. Each iteration
|
|
321
338
|
n_components : int (default: None)
|
|
@@ -356,12 +373,17 @@ def cdist_ctw(
|
|
|
356
373
|
`Glossary <https://joblib.readthedocs.io/en/latest/parallel.html#parallel-reference-documentation>`__
|
|
357
374
|
for more details.
|
|
358
375
|
be : Backend object or string or None
|
|
359
|
-
Backend.
|
|
376
|
+
Backend. If `be` is an instance of the class `NumPyBackend` or the string `"numpy"`,
|
|
377
|
+
the NumPy backend is used.
|
|
378
|
+
If `be` is an instance of the class `PyTorchBackend` or the string `"pytorch"`,
|
|
379
|
+
the PyTorch backend is used.
|
|
380
|
+
If `be` is `None`, the backend is determined by the input arrays.
|
|
381
|
+
See our :ref:`dedicated user-guide page <backend>` for more information.
|
|
360
382
|
|
|
361
383
|
Returns
|
|
362
384
|
-------
|
|
363
|
-
cdist :
|
|
364
|
-
Cross-similarity matrix
|
|
385
|
+
cdist : array-like, shape=(n_ts1, n_ts2)
|
|
386
|
+
Cross-similarity matrix.
|
|
365
387
|
|
|
366
388
|
Examples
|
|
367
389
|
--------
|
|
@@ -382,7 +404,7 @@ def cdist_ctw(
|
|
|
382
404
|
.. [1] F. Zhou and F. Torre, "Canonical time warping for alignment of
|
|
383
405
|
human behavior". NIPS 2009.
|
|
384
406
|
""" # noqa: E501
|
|
385
|
-
be = instantiate_backend(be, dataset1)
|
|
407
|
+
be = instantiate_backend(be, dataset1, dataset2)
|
|
386
408
|
return _cdist_generic(
|
|
387
409
|
dist_fun=ctw,
|
|
388
410
|
dataset1=dataset1,
|
|
@@ -12,14 +12,16 @@ def normalized_cc(s1, s2, norm1=-1.0, norm2=-1.0):
|
|
|
12
12
|
|
|
13
13
|
Parameters
|
|
14
14
|
----------
|
|
15
|
-
s1 : array-like, shape=
|
|
16
|
-
|
|
15
|
+
s1 : array-like, shape=(sz, d), dtype=float64
|
|
16
|
+
A time series.
|
|
17
|
+
s2 : array-like, shape=(sz, d), dtype=float64
|
|
18
|
+
Another time series.
|
|
17
19
|
norm1 : float64, default=-1.0
|
|
18
20
|
norm2 : float64, default=-1.0
|
|
19
21
|
|
|
20
22
|
Returns
|
|
21
23
|
-------
|
|
22
|
-
norm_cc : array-like, shape=
|
|
24
|
+
norm_cc : array-like, shape=(2 * sz - 1), dtype=float64
|
|
23
25
|
"""
|
|
24
26
|
assert s1.shape[1] == s2.shape[1]
|
|
25
27
|
sz = s1.shape[0]
|
|
@@ -54,15 +56,17 @@ def cdist_normalized_cc(dataset1, dataset2, norms1, norms2, self_similarity):
|
|
|
54
56
|
|
|
55
57
|
Parameters
|
|
56
58
|
----------
|
|
57
|
-
dataset1 : array-like, shape=
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
dataset1 : array-like, shape=(n_ts1, sz, d), dtype=float64
|
|
60
|
+
A dataset of time series.
|
|
61
|
+
dataset2 : array-like, shape=(n_ts2, sz, d), dtype=float64
|
|
62
|
+
Another dataset of time series.
|
|
63
|
+
norms1 : array-like, shape=(n_ts1,), dtype=float64
|
|
64
|
+
norms2 : array-like, shape=(n_ts2,), dtype=float64
|
|
61
65
|
self_similarity : bool
|
|
62
66
|
|
|
63
67
|
Returns
|
|
64
68
|
-------
|
|
65
|
-
dists : array-like, shape=
|
|
69
|
+
dists : array-like, shape=(n_ts1, n_ts2), dtype=float64
|
|
66
70
|
"""
|
|
67
71
|
n_ts1, sz, d = dataset1.shape
|
|
68
72
|
n_ts2 = dataset2.shape[0]
|
|
@@ -97,17 +101,18 @@ def y_shifted_sbd_vec(ref_ts, dataset, norm_ref, norms_dataset):
|
|
|
97
101
|
|
|
98
102
|
Parameters
|
|
99
103
|
----------
|
|
100
|
-
ref_ts : array-like, shape=
|
|
104
|
+
ref_ts : array-like, shape=(sz, d), dtype=float64
|
|
101
105
|
Time series of reference.
|
|
102
|
-
dataset : array-like, shape=
|
|
106
|
+
dataset : array-like, shape=(n_ts, sz, d), dtype=float64
|
|
103
107
|
Time series dataset.
|
|
104
108
|
norm_ref : float64
|
|
105
|
-
norms_dataset : array-like, shape=
|
|
109
|
+
norms_dataset : array-like, shape=(n_ts,), dtype=float64
|
|
106
110
|
Norms of the time series dataset.
|
|
107
111
|
|
|
108
112
|
Returns
|
|
109
113
|
-------
|
|
110
|
-
dataset_shifted : array-like, shape=
|
|
114
|
+
dataset_shifted : array-like, shape=(n_ts, sz, d), dtype=float64
|
|
115
|
+
Shifted dataset.
|
|
111
116
|
"""
|
|
112
117
|
n_ts = dataset.shape[0]
|
|
113
118
|
sz = dataset.shape[1]
|
|
@@ -13,13 +13,14 @@ def inv_transform_paa(dataset_paa, original_size):
|
|
|
13
13
|
|
|
14
14
|
Parameters
|
|
15
15
|
----------
|
|
16
|
-
dataset_paa : array-like, shape=
|
|
16
|
+
dataset_paa : array-like, shape=(n_ts, sz, d), dtype=float64
|
|
17
17
|
A dataset of PAA series.
|
|
18
18
|
original_size : int32
|
|
19
|
+
Length of the original time series.
|
|
19
20
|
|
|
20
21
|
Returns
|
|
21
22
|
-------
|
|
22
|
-
dataset_out : array-like, shape=
|
|
23
|
+
dataset_out : array-like, shape=(n_ts, original_size, d), dtype=float64
|
|
23
24
|
A dataset of time series corresponding to the provided
|
|
24
25
|
representation.
|
|
25
26
|
"""
|
|
@@ -39,12 +40,14 @@ def cydist_sax(sax1, sax2, breakpoints, original_size):
|
|
|
39
40
|
|
|
40
41
|
Parameters
|
|
41
42
|
----------
|
|
42
|
-
sax1 : array-like, shape=
|
|
43
|
+
sax1 : array-like, shape=(sz, d), dtype=float64 (Linux and MacOS) or float32 (Windows)
|
|
43
44
|
SAX representation of a time series.
|
|
44
|
-
sax2 : array-like, shape=
|
|
45
|
+
sax2 : array-like, shape=(sz, d), dtype=float64 (Linux and MacOS) or float32 (Windows)
|
|
45
46
|
SAX representation of another time series.
|
|
46
47
|
breakpoints : array-like, ndim=1, dtype=float64
|
|
48
|
+
The breakpoints used to assign the alphabet symbols.
|
|
47
49
|
original_size : int64 (Linux and MacOS) or int32 (Windows)
|
|
50
|
+
Length of the original time series.
|
|
48
51
|
|
|
49
52
|
Returns
|
|
50
53
|
-------
|
|
@@ -77,14 +80,15 @@ def inv_transform_sax(dataset_sax, breakpoints_middle_, original_size):
|
|
|
77
80
|
|
|
78
81
|
Parameters
|
|
79
82
|
----------
|
|
80
|
-
dataset_sax : array-like, shape=
|
|
83
|
+
dataset_sax : array-like, shape=(n_ts, sz, d), dtype=float64 (Linux and MacOS) or float32 (Windows)
|
|
81
84
|
A dataset of SAX series.
|
|
82
85
|
breakpoints_middle_ : array-like, ndim=1, dtype=float64
|
|
83
86
|
original_size : int64 (Linux and MacOS) or int32 (Windows)
|
|
87
|
+
Length of the original time series.
|
|
84
88
|
|
|
85
89
|
Returns
|
|
86
90
|
-------
|
|
87
|
-
dataset_out : array-like, shape=
|
|
91
|
+
dataset_out : array-like, shape=(n_ts, original_size, d), dtype=float64
|
|
88
92
|
"""
|
|
89
93
|
n_ts, sz, d = dataset_sax.shape
|
|
90
94
|
seg_sz = original_size // sz
|
|
@@ -105,12 +109,12 @@ def cyslopes(dataset, t0):
|
|
|
105
109
|
|
|
106
110
|
Parameters
|
|
107
111
|
----------
|
|
108
|
-
dataset : array-like, shape=
|
|
112
|
+
dataset : array-like, shape=(n_ts, sz, d), dtype=float64
|
|
109
113
|
t0 : int32
|
|
110
114
|
|
|
111
115
|
Returns
|
|
112
116
|
-------
|
|
113
|
-
dataset_out : array-like, shape=
|
|
117
|
+
dataset_out : array-like, shape=(n_ts, d), dtype=float64
|
|
114
118
|
"""
|
|
115
119
|
n_ts, sz, d = dataset.shape
|
|
116
120
|
dataset_out = np.empty((n_ts, d))
|
|
@@ -135,17 +139,19 @@ def cydist_1d_sax(
|
|
|
135
139
|
|
|
136
140
|
Parameters
|
|
137
141
|
----------
|
|
138
|
-
sax1 : array-like, shape=
|
|
142
|
+
sax1 : array-like, shape=(sz, 2 * d), dtype=float64 (Linux and MacOS) or float32 (Windows)
|
|
139
143
|
1d-SAX representation of a time series.
|
|
140
|
-
sax2 : array-like, shape=
|
|
144
|
+
sax2 : array-like, shape=(sz, 2 * d), dtype=float64 (Linux and MacOS) or float32 (Windows)
|
|
141
145
|
1d-SAX representation of another time series.
|
|
142
146
|
breakpoints_avg_middle_ : array-like, ndim=1, dtype=float64
|
|
143
147
|
breakpoints_slope_middle_ : array-like, ndim=1, dtype=float64
|
|
144
148
|
original_size : int64 (Linux and MacOS) or int32 (Windows)
|
|
149
|
+
Length of the original time series.
|
|
145
150
|
|
|
146
151
|
Returns
|
|
147
152
|
-------
|
|
148
153
|
dist_1d_sax : float64
|
|
154
|
+
1d-SAX distance.
|
|
149
155
|
|
|
150
156
|
Notes
|
|
151
157
|
-----
|
|
@@ -187,15 +193,16 @@ def inv_transform_1d_sax(
|
|
|
187
193
|
|
|
188
194
|
Parameters
|
|
189
195
|
----------
|
|
190
|
-
dataset_sax : array-like, shape=
|
|
196
|
+
dataset_sax : array-like, shape=(n_ts, sz, 2 * d), dtype=float64 (Linux and MacOS) or float32 (Windows)
|
|
191
197
|
A dataset of SAX series.
|
|
192
198
|
breakpoints_avg_middle_ : array-like, ndim=1, dtype=float64
|
|
193
199
|
breakpoints_slope_middle_ : array-like, ndim=1, dtype=float64
|
|
194
200
|
original_size : int64 (Linux and MacOS) or int32 (Windows)
|
|
201
|
+
Length of the original time series.
|
|
195
202
|
|
|
196
203
|
Returns
|
|
197
204
|
-------
|
|
198
|
-
dataset_out : array-like, shape=
|
|
205
|
+
dataset_out : array-like, shape=(n_ts, original_size, d), dtype=float64
|
|
199
206
|
A dataset of time series corresponding to the provided
|
|
200
207
|
representation.
|
|
201
208
|
"""
|