compute_mask#

tslearn.metrics.compute_mask(s1, s2, global_constraint=0, sakoe_chiba_radius=None, itakura_max_slope=None, be=None)[source]#

Compute the mask (region constraint).

Parameters:
s1array-like, shape=(sz1, d) or (sz1,) or int

A time series or integer. If shape is (sz1,), the time series is assumed to be univariate. If int, size sz1 used to dimension the mask.

s2array-like, shape=(sz2, d) or (sz2,) or int

Another time series or integer. If shape is (sz2,), the time series is assumed to be univariate. If int, size sz2 used to dimension the mask.

global_constraint{0, 1, 2} (default: 0)

Global constraint to restrict admissible paths for DTW: - “itakura” if 1 - “sakoe_chiba” if 2 - no constraint otherwise

sakoe_chiba_radiusint or None (default: None)

Radius to be used for Sakoe-Chiba band global constraint. The Sakoe-Chiba radius corresponds to the parameter \(\delta\) mentioned in [1]_, it controls how far in time we can go in order to match a given point from one time series to a point in another time series. If None and global_constraint is set to 2 (sakoe-chiba), a radius of 1 is used. If both sakoe_chiba_radius and itakura_max_slope are set, global_constraint is used to infer which constraint to use among the two. In this case, if global_constraint corresponds to no global constraint, a RuntimeWarning is raised and no global constraint is used.

itakura_max_slopefloat or None (default: None)

Maximum slope for the Itakura parallelogram constraint. If None and global_constraint is set to 1 (itakura), a maximum slope of 2. is used. If both sakoe_chiba_radius and itakura_max_slope are set, global_constraint is used to infer which constraint to use among the two. In this case, if global_constraint corresponds to no global constraint, a RuntimeWarning is raised and no global constraint is used.

beBackend object or string or None

Backend. If be is an instance of the class NumPyBackend or the string “numpy”, the NumPy backend is used. If be is an instance of the class PyTorchBackend or the string “pytorch”, the PyTorch backend is used. If be is None, the backend is determined by the input arrays. See our dedicated user-guide page for more information.

Returns:
maskarray-like, shape=(sz1, sz2)

Constraint region.

Examples

>>> compute_mask(4, 4)
array([[ True,  True,  True,  True],
       [ True,  True,  True,  True],
       [ True,  True,  True,  True],
       [ True,  True,  True,  True]])
>>> compute_mask(4, 4, sakoe_chiba_radius=1)
array([[ True,  True, False, False],
       [ True,  True,  True, False],
       [False,  True,  True,  True],
       [False, False,  True,  True]])
>>> compute_mask(4, 4, itakura_max_slope=2)
array([[ True, False, False, False],
       [False,  True,  True, False],
       [False,  True,  True, False],
       [False, False, False,  True]])