How to use the stumpy.stamp function in stumpy

To help you get started, we’ve selected a few stumpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TDAmeritrade / stumpy / tests / test_stamp.py View on Github external
def test_stamp_self_join(T_A, T_B):
    m = 3
    zone = int(np.ceil(m / 2))
    left = np.array(
        [
            naive_mass(Q, T_B, m, i, zone)
            for i, Q in enumerate(core.rolling_window(T_B, m))
        ],
        dtype=object,
    )
    right = stamp.stamp(T_B, T_B, m, ignore_trivial=True)
    replace_inf(left)
    replace_inf(right)
    npt.assert_almost_equal(left, right)
github TDAmeritrade / stumpy / tests / test_stamp.py View on Github external
def test_stamp_A_B_join(T_A, T_B):
    m = 3
    left = np.array(
        [naive_mass(Q, T_A, m) for Q in core.rolling_window(T_B, m)], dtype=object
    )
    right = stamp.stamp(T_A, T_B, m)
    replace_inf(left)
    replace_inf(right)
    npt.assert_almost_equal(left, right)
github TDAmeritrade / stumpy / stumpy / stump.py View on Github external
Returns
    -------
    P : float64
        Matrix profile for the window with index equal to `start`

    I : Tuple[int64, int64, int64]
        Matrix profile index, left matrix profile index, and right matrix profile
        index for the window with index equal to `start`. The left and right matrix
        profile indices are automatically set to `-1` for self-joins (i.e., when
        `ignore_trivial` is set to `True`.
    """

    # Handle first subsequence, add exclusionary zone
    if ignore_trivial:
        P, I = stamp.mass(T_B[start : start + m], T_A, M_T, Σ_T, start, excl_zone)
        PL, IL = stamp.mass(
            T_B[start : start + m], T_A, M_T, Σ_T, start, excl_zone, left=True
        )
        PR, IR = stamp.mass(
            T_B[start : start + m], T_A, M_T, Σ_T, start, excl_zone, right=True
        )
    else:
        P, I = stamp.mass(T_B[start : start + m], T_A, M_T, Σ_T)
        # No left and right matrix profile available
        IL = -1
        IR = -1

    return P, (I, IL, IR)
github TDAmeritrade / stumpy / stumpy / stomp.py View on Github external
logger.warning("Try setting `ignore_trivial = False`.")

    n = T_B.shape[0]
    l = n - m + 1
    excl_zone = int(np.ceil(m / 4))  # See Definition 3 and Figure 3
    M_T, Σ_T = core.compute_mean_std(T_A, m)
    QT = core.sliding_dot_product(T_B[:m], T_A)
    QT_first = core.sliding_dot_product(T_A[:m], T_B)

    μ_Q, σ_Q = core.compute_mean_std(T_B, m)

    out = np.empty((l, 4), dtype=object)

    # Handle first subsequence, add exclusionary zone
    if ignore_trivial:
        P, I = stamp.mass(T_B[:m], T_A, M_T, Σ_T, 0, excl_zone)
        PR, IR = stamp.mass(T_B[:m], T_A, M_T, Σ_T, 0, excl_zone, right=True)
    else:
        P, I = stamp.mass(T_B[:m], T_A, M_T, Σ_T)
        IR = -1  # No left and right matrix profile available
    out[0] = P, I, -1, IR

    k = T_A.shape[0] - m + 1
    for i in range(1, l):
        QT[1:] = (
            QT[: k - 1] - T_B[i - 1] * T_A[: k - 1] + T_B[i - 1 + m] * T_A[-(k - 1) :]
        )
        QT[0] = QT_first[i]
        D = core.calculate_distance_profile(m, QT, μ_Q[i], σ_Q[i], M_T, Σ_T)
        if ignore_trivial:
            zone_start = max(0, i - excl_zone)
            zone_stop = min(k, i + excl_zone)
github TDAmeritrade / stumpy / stumpy / stump.py View on Github external
Returns
    -------
    P : float64
        Matrix profile for the window with index equal to `start`

    I : Tuple[int64, int64, int64]
        Matrix profile index, left matrix profile index, and right matrix profile
        index for the window with index equal to `start`. The left and right matrix
        profile indices are automatically set to `-1` for self-joins (i.e., when
        `ignore_trivial` is set to `True`.
    """

    # Handle first subsequence, add exclusionary zone
    if ignore_trivial:
        P, I = stamp.mass(T_B[start : start + m], T_A, M_T, Σ_T, start, excl_zone)
        PL, IL = stamp.mass(
            T_B[start : start + m], T_A, M_T, Σ_T, start, excl_zone, left=True
        )
        PR, IR = stamp.mass(
            T_B[start : start + m], T_A, M_T, Σ_T, start, excl_zone, right=True
        )
    else:
        P, I = stamp.mass(T_B[start : start + m], T_A, M_T, Σ_T)
        # No left and right matrix profile available
        IL = -1
        IR = -1

    return P, (I, IL, IR)
github TDAmeritrade / stumpy / stumpy / stomp.py View on Github external
l = n - m + 1
    excl_zone = int(np.ceil(m / 4))  # See Definition 3 and Figure 3
    M_T, Σ_T = core.compute_mean_std(T_A, m)
    QT = core.sliding_dot_product(T_B[:m], T_A)
    QT_first = core.sliding_dot_product(T_A[:m], T_B)

    μ_Q, σ_Q = core.compute_mean_std(T_B, m)

    out = np.empty((l, 4), dtype=object)

    # Handle first subsequence, add exclusionary zone
    if ignore_trivial:
        P, I = stamp.mass(T_B[:m], T_A, M_T, Σ_T, 0, excl_zone)
        PR, IR = stamp.mass(T_B[:m], T_A, M_T, Σ_T, 0, excl_zone, right=True)
    else:
        P, I = stamp.mass(T_B[:m], T_A, M_T, Σ_T)
        IR = -1  # No left and right matrix profile available
    out[0] = P, I, -1, IR

    k = T_A.shape[0] - m + 1
    for i in range(1, l):
        QT[1:] = (
            QT[: k - 1] - T_B[i - 1] * T_A[: k - 1] + T_B[i - 1 + m] * T_A[-(k - 1) :]
        )
        QT[0] = QT_first[i]
        D = core.calculate_distance_profile(m, QT, μ_Q[i], σ_Q[i], M_T, Σ_T)
        if ignore_trivial:
            zone_start = max(0, i - excl_zone)
            zone_stop = min(k, i + excl_zone)
            D[zone_start:zone_stop] = np.inf
        I = np.argmin(D)
        P = D[I]