Beispiel #1
0
def test_preprocess():
    T = np.array([0, np.nan, 2, 3, 4, 5, 6, 7, np.inf, 9])
    m = 3

    ref_T = np.array([0, 0, 2, 3, 4, 5, 6, 7, 0, 9], dtype=float)
    ref_M, ref_Σ = naive_compute_mean_std(T, m)

    comp_T, comp_M, comp_Σ = core.preprocess(T, m)

    npt.assert_almost_equal(ref_T, comp_T)
    npt.assert_almost_equal(ref_M, comp_M)
    npt.assert_almost_equal(ref_Σ, comp_Σ)

    T = pd.Series(T)
    comp_T, comp_M, comp_Σ = core.preprocess(T, m)

    npt.assert_almost_equal(ref_T, comp_T)
    npt.assert_almost_equal(ref_M, comp_M)
    npt.assert_almost_equal(ref_Σ, comp_Σ)
Beispiel #2
0
def test_preprocess():
    T = np.array([0, np.nan, 2, 3, 4, 5, 6, 7, np.inf, 9])
    m = 3

    left_T = np.array([0, 0, 2, 3, 4, 5, 6, 7, 0, 9], dtype=float)
    left_M, left_Σ = naive_compute_mean_std(T, m)

    right_T, right_M, right_Σ = core.preprocess(T, m)

    npt.assert_almost_equal(left_T, right_T)
    npt.assert_almost_equal(left_M, right_M)
    npt.assert_almost_equal(left_Σ, right_Σ)

    T = pd.Series(T)
    right_T, right_M, right_Σ = core.preprocess(T, m)

    npt.assert_almost_equal(left_T, right_T)
    npt.assert_almost_equal(left_M, right_M)
    npt.assert_almost_equal(left_Σ, right_Σ)
Beispiel #3
0
    def __init__(self, T, m, excl_zone=None):
        """
        Initialize the `stumpi` object

        Parameters
        ----------
        T : ndarray
            The time series or sequence for which the matrix profile and matrix profile
            indices will be returned

        m : int
            Window size

        excl_zone : int
            The half width for the exclusion zone relative to the current
            sliding window
        """
        self._T = T
        self._m = m
        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._illegal = np.logical_or(np.isinf(self._T), np.isnan(self._T))

        mp = stumpy.stump(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, self._M_T, self._Σ_T = core.preprocess(self._T, self._m)
        # Retrieve the left matrix profile values
        for i, j in enumerate(self._left_I):
            if j >= 0:
                D = core.mass(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)