def __init__(self, T, m, excl_zone=None, egress=True): """ Initialize the `stumpi` object Parameters ---------- T : ndarray The time series or sequence for which the unnormalized matrix profile and matrix profile indices will be returned m : int Window size excl_zone : int, default None The half width for the exclusion zone relative to the current sliding window egress : bool, default True If set to `True`, the oldest data point in the time series is removed and the time series length remains constant rather than forever increasing """ self._T = T.copy() self._T = np.asarray(self._T) core.check_dtype(self._T) self._m = m self._n = self._T.shape[0] if excl_zone is not None: # pragma: no cover self._excl_zone = excl_zone else: self._excl_zone = int(np.ceil(self._m / 4)) self._egress = egress mp = stumpy.aamp(self._T, self._m) self._P = mp[:, 0] self._I = mp[:, 1] self._left_I = mp[:, 2] self._left_P = np.empty(self._P.shape) self._left_P[:] = np.inf self._T_isfinite = np.isfinite(self._T) self._T, self._T_subseq_isfinite = core.preprocess_non_normalized( self._T, self._m) self._T_squared = np.sum(core.rolling_window(self._T * self._T, self._m), axis=1) # Retrieve the left matrix profile values for i, j in enumerate(self._left_I): if j >= 0: D = core.mass_absolute(self._T[i:i + self._m], self._T[j:j + self._m]) self._left_P[i] = D[0] Q = self._T[-m:] self._QT = core.sliding_dot_product(Q, self._T) if self._egress: self._QT_new = np.empty(self._QT.shape[0]) self._n_appended = 0
def test_check_dtype_float64(): assert core.check_dtype(np.random.rand(10))
def test_check_dtype_float32(): assert core.check_dtype(np.random.rand(10).astype(np.float32))
def test_df_to_array(): a = np.random.rand(10) assert core.check_dtype(core.df_to_array(a)) df = pd.Series(a) assert core.check_dtype(core.df_to_array(df))
def test_check_bad_dtype(): for dtype in [np.int32, np.int64, np.float32]: with pytest.raises(TypeError): core.check_dtype(np.random.rand(10).astype(dtype))