Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Changelogs for this project are recorded in this file since v0.2.0.

* `lcss` and `lcss_path_from_metric` now respect the `global_constraint` / Sakoe-Chiba / Itakura band, which was previously ignored. ([#526](https://github.com/tslearn-team/tslearn/issues/526))
* `gak` and `cdist_gak` no longer return `NaN` for time series longer than about 405 samples. They are now normalized in log space, and the Global Alignment Kernel recursion falls back to a log-space accumulation when its value leaves the range of a 64-bit float. This also fixes `TimeSeriesSVC` / `TimeSeriesSVR` and `KernelKMeans` with `kernel="gak"` on long time series. ([#450](https://github.com/tslearn-team/tslearn/issues/450))
* Fixed double scaling in `OneD_SymbolicAggregateApproximation`. ([#722](https://github.com/tslearn-team/tslearn/issues/722))

## [v0.9.0]

Expand Down
17 changes: 17 additions & 0 deletions tests/test_piecewise.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,20 @@ def test_sax_scale():
np.testing.assert_array_almost_equal(X, X_scale_unscale)

knn_sax.predict(X)


def test_1dsax_scale_matches_sax_average():
# With scale=True the average symbols of 1d-SAX must match those of SAX:
# both scale the series once, using the same fitted mean and std.
n, sz, d = 4, 12, 1
rng = np.random.RandomState(0)
X = rng.randn(n, sz, d) * 5 + 10

sax = SymbolicAggregateApproximation(n_segments=4, alphabet_size_avg=5,
scale=True)
one_d_sax = OneD_SymbolicAggregateApproximation(n_segments=4,
alphabet_size_avg=5,
alphabet_size_slope=5,
scale=True)
np.testing.assert_array_equal(sax.fit_transform(X),
one_d_sax.fit_transform(X)[:, :, :d])
4 changes: 2 additions & 2 deletions tslearn/piecewise/piecewise.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,15 +687,15 @@ def _get_slopes(self, X):
return X_slopes

def _transform(self, X, y=None):
X = self._scale(X)
n_ts, sz_raw, d = X.shape
X_1d_sax = numpy.empty((n_ts, self.n_segments, 2 * d), dtype=int)

# Average
# `SymbolicAggregateApproximation._transform` scales `X` itself.
X_1d_sax_avg = SymbolicAggregateApproximation._transform(self, X)

# Slope
X_slopes = self._get_slopes(X)
X_slopes = self._get_slopes(self._scale(X))
X_1d_sax_slope = _paa_to_symbols(X_slopes, self.breakpoints_slope_)

X_1d_sax[:, :, :d] = X_1d_sax_avg
Expand Down