示例#1
0
def test_cac(I):
    L = 5
    excl_factor = 1
    custom_iac = _iac(I.shape[0])
    ref = naive_cac(I, L, excl_factor, custom_iac)
    bidirectional = True
    comp = _cac(I, L, bidirectional, excl_factor)
    npt.assert_almost_equal(ref, comp)
示例#2
0
def test_cac(I):
    L = 5
    excl_factor = 1
    custom_iac = _iac(I.shape[0])
    left = naive_cac(I, L, excl_factor, custom_iac)
    bidirectional = True
    right = _cac(I, L, bidirectional, excl_factor)
    npt.assert_almost_equal(left, right)
示例#3
0
def test_floss():
    data = np.random.uniform(-1000, 1000, [64])
    m = 5
    old_data = data[:30]
    n = old_data.shape[0]
    add_data = data[30:]

    mp = naive_right_mp(old_data, m)
    comp_mp = stump(old_data, m)
    k = mp.shape[0]

    rolling_Ts = core.rolling_window(data[1:], n)
    L = 5
    excl_factor = 1
    custom_iac = _iac(k, bidirectional=False)
    stream = floss(comp_mp, old_data, m, L, excl_factor, custom_iac=custom_iac)
    last_idx = n - m + 1
    excl_zone = int(np.ceil(m / 4))
    zone_start = max(0, k - excl_zone)
    for i, ref_T in enumerate(rolling_Ts):
        mp[:, 1] = -1
        mp[:, 2] = -1
        mp[:] = np.roll(mp, -1, axis=0)
        mp[-1, 0] = np.inf
        mp[-1, 3] = last_idx + i

        D = naive_distance_profile(ref_T[-m:], ref_T, m)
        D[zone_start:] = np.inf

        update_idx = np.argwhere(D < mp[:, 0]).flatten()
        mp[update_idx, 0] = D[update_idx]
        mp[update_idx, 3] = last_idx + i

        ref_cac_1d = _cac(
            mp[:, 3] - i - 1,
            L,
            bidirectional=False,
            excl_factor=excl_factor,
            custom_iac=custom_iac,
        )

        ref_mp = mp.copy()
        ref_P = ref_mp[:, 0]
        ref_I = ref_mp[:, 3]

        stream.update(ref_T[-1])
        comp_cac_1d = stream.cac_1d_
        comp_P = stream.P_
        comp_I = stream.I_
        comp_T = stream.T_

        naive.replace_inf(ref_P)
        naive.replace_inf(comp_P)

        npt.assert_almost_equal(ref_cac_1d, comp_cac_1d)
        npt.assert_almost_equal(ref_P, comp_P)
        npt.assert_almost_equal(ref_I, comp_I)
        npt.assert_almost_equal(ref_T, comp_T)
示例#4
0
def test_floss():
    data = np.random.uniform(-1000, 1000, [64])
    m = 5
    old_data = data[:30]
    n = old_data.shape[0]
    add_data = data[30:]

    left_mp = naive_right_mp(old_data, m)
    right_mp = stump(old_data, m)
    k = left_mp.shape[0]

    rolling_Ts = core.rolling_window(data[1:], n)
    L = 5
    excl_factor = 1
    custom_iac = _iac(k, bidirectional=False)
    right_gen = floss(
        right_mp, old_data, add_data, m, L, excl_factor, custom_iac=custom_iac
    )
    last_idx = n - m + 1
    excl_zone = int(np.ceil(m / 4))
    zone_start = max(0, k - excl_zone)
    for i, T in enumerate(rolling_Ts):
        left_mp[:] = np.roll(left_mp, -1, axis=0)
        left_mp[-1, 0] = np.inf
        left_mp[-1, 3] = last_idx + i

        D = naive_distance_profile(T[-m:], T, m)
        D[zone_start:] = np.inf

        update_idx = np.argwhere(D < left_mp[:, 0]).flatten()
        left_mp[update_idx, 0] = D[update_idx]
        left_mp[update_idx, 3] = last_idx + i

        left_cac = _cac(
            left_mp[:, 3] - i - 1,
            L,
            bidirectional=False,
            excl_factor=excl_factor,
            custom_iac=custom_iac,
        )
        right_cac, right_mp, tmp_T = next(right_gen)
        npt.assert_almost_equal(left_cac, right_cac)