Beispiel #1
0
def test_calc_curdistance():
    ts = np.array([1, 2, 3, 4, 5, 6, 7, 8])
    m = 4

    # test index 2
    idx = 2
    profile_len = scrimp.calc_profile_len(len(ts), m)
    X, n, sumx2, sumx, meanx, sigmax2, sigmax = scrimp.fast_find_nn_pre(ts, m)
    curlastz = np.zeros(profile_len)
    curlastz = scrimp.calc_curlastz(ts, m, n, idx, profile_len, curlastz)

    curdistance = np.zeros(profile_len)
    curdistance = scrimp.calc_curdistance(curlastz, meanx, sigmax, idx,
                                          profile_len, m, curdistance)

    expected_result = np.array([
        0,
        0,
        0.4215e-07,
        0.4215e-07,
        0.4215e-07,
    ])

    np.testing.assert_almost_equal(curdistance, expected_result)

    # test index 3
    idx = 3
    curlastz = np.zeros(profile_len)
    curlastz = scrimp.calc_curlastz(ts, m, n, idx, profile_len, curlastz)
    curdistance = np.zeros(profile_len)
    curdistance = scrimp.calc_curdistance(curlastz, meanx, sigmax, idx,
                                          profile_len, m, curdistance)

    np.testing.assert_almost_equal(curdistance, expected_result)
Beispiel #2
0
def test_calc_refine_distance_begin_idx():
    ts = [1, 2, 3, 4, 5, 6, 7, 8]
    m = 4
    step_size = 0.25

    # test index 0
    idx = 0
    profile_len = scrimp.calc_profile_len(len(ts), m)
    exclusion_zone = scrimp.calc_exclusion_zone(m)
    subsequence = scrimp.next_subsequence(ts, idx, m)
    X, n, sumx2, sumx, meanx, sigmax2, sigmax = scrimp.fast_find_nn_pre(ts, m)
    dp = scrimp.calc_distance_profile(X, subsequence, n, m, meanx, sigmax)
    dp = scrimp.apply_exclusion_zone(idx, exclusion_zone, profile_len, dp)
    mp = np.zeros(profile_len)
    mp_index = np.zeros(profile_len, dtype='int32')
    mp, mp_index, idx_nn = scrimp.find_and_store_nn(0, idx, mp, mp_index, dp)
    idx_diff = scrimp.calc_idx_diff(idx, idx_nn)
    step_size = scrimp.calc_step_size(m, step_size)
    beginidx = scrimp.calc_begin_idx(idx, step_size, idx_diff)

    refine_distance = np.full(profile_len, np.inf)
    result = scrimp.calc_refine_distance_begin_idx(refine_distance, dp,
                                                   beginidx, idx, idx_diff,
                                                   idx_nn, sigmax, meanx, m)
    expected_result = np.array([np.inf, np.inf, np.inf, np.inf, np.inf])

    np.testing.assert_almost_equal(result, expected_result)
Beispiel #3
0
def test_find_and_store_nn():
    ts = [1, 2, 3, 4, 5, 6, 7, 8]
    m = 4

    # test index 0
    idx = 0
    profile_len = scrimp.calc_profile_len(len(ts), m)
    exclusion_zone = scrimp.calc_exclusion_zone(m)
    subsequence = scrimp.next_subsequence(ts, idx, m)
    X, n, sumx2, sumx, meanx, sigmax2, sigmax = scrimp.fast_find_nn_pre(ts, m)
    dp = scrimp.calc_distance_profile(X, subsequence, n, m, meanx, sigmax)
    dp = scrimp.apply_exclusion_zone(idx, exclusion_zone, profile_len, dp)

    mp = np.zeros(profile_len)
    mp_index = np.zeros(profile_len, dtype='int32')

    mp, mp_index, idx_nn = scrimp.find_and_store_nn(0, idx, mp, mp_index, dp)
    expected_mp = np.array([
        0.4215e-07,
        np.inf,
        0.4215e-07,
        0.4215e-07,
        0.4215e-07,
    ])
    expected_idx_nn = 2
    expected_mp_index = np.array([
        2,
        0,
        0,
        0,
        0,
    ])

    np.testing.assert_almost_equal(mp, expected_mp)
    np.testing.assert_almost_equal(mp_index, expected_mp_index)
    assert (idx_nn == expected_idx_nn)

    # test index 0
    idx = 1
    subsequence = scrimp.next_subsequence(ts, idx, m)
    dp = scrimp.calc_distance_profile(X, subsequence, n, m, meanx, sigmax)
    dp = scrimp.apply_exclusion_zone(idx, exclusion_zone, profile_len, dp)

    mp, mp_index, idx_nn = scrimp.find_and_store_nn(1, idx, mp, mp_index, dp)
    expected_idx_nn = 3
    assert (idx_nn == expected_idx_nn)
Beispiel #4
0
def test_calc_curlastz():
    ts = np.array([1, 2, 3, 4, 5, 6, 7, 8])
    m = 4
    n = len(ts)
    profile_len = scrimp.calc_profile_len(n, m)

    # test index 2
    idx = 2
    curlastz = np.zeros(profile_len)
    curlastz = scrimp.calc_curlastz(ts, m, n, idx, profile_len, curlastz)
    expected_result = np.array([0, 0, 50, 82, 122])

    np.testing.assert_almost_equal(curlastz, expected_result)

    # test index 3
    idx = 3
    curlastz = np.zeros(profile_len)
    curlastz = scrimp.calc_curlastz(ts, m, n, idx, profile_len, curlastz)
    expected_result = np.array([0, 0, 0, 60, 96])

    np.testing.assert_almost_equal(curlastz, expected_result)
Beispiel #5
0
def test_calc_dotproduct_idx():
    ts = [1, 2, 3, 4, 5, 6, 7, 8]
    m = 4

    # test index 0
    idx = 0
    profile_len = scrimp.calc_profile_len(len(ts), m)
    exclusion_zone = scrimp.calc_exclusion_zone(m)
    subsequence = scrimp.next_subsequence(ts, idx, m)
    X, n, sumx2, sumx, meanx, sigmax2, sigmax = scrimp.fast_find_nn_pre(ts, m)
    dp = scrimp.calc_distance_profile(X, subsequence, n, m, meanx, sigmax)
    dp = scrimp.apply_exclusion_zone(idx, exclusion_zone, profile_len, dp)
    mp = np.zeros(profile_len)
    mp_index = np.zeros(profile_len, dtype='int32')
    mp, mp_index, idx_nn = scrimp.find_and_store_nn(0, idx, mp, mp_index, dp)
    dotproduct = np.zeros(profile_len)
    val = scrimp.calc_dotproduct_idx(dotproduct, m, mp, idx, sigmax, idx_nn,
                                     meanx)
    expected_val = np.array([50, 0, 0, 0, 0])

    np.testing.assert_almost_equal(val, expected_val)
Beispiel #6
0
def test_calc_idx_diff():
    ts = [1, 2, 3, 4, 5, 6, 7, 8]
    m = 4

    # test index 0
    idx = 0
    profile_len = scrimp.calc_profile_len(len(ts), m)
    exclusion_zone = scrimp.calc_exclusion_zone(m)
    subsequence = scrimp.next_subsequence(ts, idx, m)
    X, n, sumx2, sumx, meanx, sigmax2, sigmax = scrimp.fast_find_nn_pre(ts, m)
    dp = scrimp.calc_distance_profile(X, subsequence, n, m, meanx, sigmax)
    dp = scrimp.apply_exclusion_zone(idx, exclusion_zone, profile_len, dp)

    mp = np.zeros(profile_len)
    mp_index = np.zeros(profile_len, dtype='int32')

    mp, mp_index, idx_nn = scrimp.find_and_store_nn(0, idx, mp, mp_index, dp)

    idx_diff = scrimp.calc_idx_diff(idx, idx_nn)
    expected_idx_diff = 2

    assert (idx_diff == expected_idx_diff)
Beispiel #7
0
def test_calc_exclusion_stop():
    ts = [1, 2, 3, 4, 5, 6, 7, 8]
    m = 4
    idx = 0
    profile_len = scrimp.calc_profile_len(len(ts), m)  # 4
    exclusion_zone = scrimp.calc_exclusion_zone(m)  # 1
    stop = scrimp.calc_exclusion_stop(idx, exclusion_zone, profile_len)
    expected_stop = 1
    assert (expected_stop == stop)

    idx = 2
    stop = scrimp.calc_exclusion_stop(idx, exclusion_zone, profile_len)
    expected_stop = 3
    assert (expected_stop == stop)

    idx = 3
    stop = scrimp.calc_exclusion_stop(idx, exclusion_zone, profile_len)
    expected_stop = 4
    assert (expected_stop == stop)

    idx = 4
    stop = scrimp.calc_exclusion_stop(idx, exclusion_zone, profile_len)
    expected_stop = 5
    assert (expected_stop == stop)
Beispiel #8
0
def test_calc_profile_len():
    assert (scrimp.calc_profile_len(8, 4) == 5)
Beispiel #9
0
def test_apply_exclusion_zone():
    ts = [1, 2, 3, 4, 5, 6, 7, 8]
    m = 4

    # test index 0
    idx = 0
    profile_len = scrimp.calc_profile_len(len(ts), m)  # 4
    exclusion_zone = scrimp.calc_exclusion_zone(m)  # 1
    subsequence = scrimp.next_subsequence(ts, idx, m)
    X, n, sumx2, sumx, meanx, sigmax2, sigmax = scrimp.fast_find_nn_pre(ts, m)
    dp = scrimp.calc_distance_profile(X, subsequence, n, m, meanx, sigmax)
    dp = scrimp.apply_exclusion_zone(idx, exclusion_zone, profile_len, dp)

    expected_dp = np.array([
        np.inf,
        np.inf,
        0.4215e-07,
        0.4215e-07,
        0.4215e-07,
    ])

    np.testing.assert_almost_equal(dp, expected_dp)

    # test idx 1
    idx = 1
    subsequence = scrimp.next_subsequence(ts, idx, m)
    dp = scrimp.calc_distance_profile(X, subsequence, n, m, meanx, sigmax)
    dp = scrimp.apply_exclusion_zone(idx, exclusion_zone, profile_len, dp)

    expected_dp = np.array([
        np.inf,
        np.inf,
        np.inf,
        0.4215e-07,
        0.4215e-07,
    ])

    np.testing.assert_almost_equal(dp, expected_dp)

    # test idx 2
    idx = 2
    subsequence = scrimp.next_subsequence(ts, idx, m)
    dp = scrimp.calc_distance_profile(X, subsequence, n, m, meanx, sigmax)
    dp = scrimp.apply_exclusion_zone(idx, exclusion_zone, profile_len, dp)

    expected_dp = np.array([
        0.4215e-07,
        np.inf,
        np.inf,
        np.inf,
        0.4215e-07,
    ])

    np.testing.assert_almost_equal(dp, expected_dp)

    # test idx 3
    idx = 3
    subsequence = scrimp.next_subsequence(ts, idx, m)
    dp = scrimp.calc_distance_profile(X, subsequence, n, m, meanx, sigmax)
    dp = scrimp.apply_exclusion_zone(idx, exclusion_zone, profile_len, dp)

    expected_dp = np.array([
        0.1115e-06,
        0.0421e-06,
        np.inf,
        np.inf,
        np.inf,
    ])

    np.testing.assert_almost_equal(dp, expected_dp)