Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 37 additions & 25 deletions tests/test_aamp_motifs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ def test_aamp_motifs_one_motif():
m = 3
max_motifs = 1

left_indices = [[0, 5]]
left_profile_values = [[0.0, 0.0]]
ref_indices = [[0, 5]]
ref_profile_values = [[0.0, 0.0]]

for p in [1.0, 2.0, 3.0]:
mp = naive.aamp(T, m, p=p)
right_distance_values, right_indices = aamp_motifs(
cmp_distance_values, cmp_indices = aamp_motifs(
T,
mp[:, 0],
max_motifs=max_motifs,
Expand All @@ -65,8 +65,8 @@ def test_aamp_motifs_one_motif():
p=p,
)

npt.assert_array_equal(left_indices, right_indices)
npt.assert_almost_equal(left_profile_values, right_distance_values, decimal=4)
npt.assert_array_equal(cmp_indices, ref_indices)
npt.assert_allclose(cmp_distance_values, ref_profile_values, atol=1.5e-04)


def test_aamp_motifs_two_motifs():
Expand Down Expand Up @@ -105,16 +105,16 @@ def test_aamp_motifs_two_motifs():

mp = naive.aamp(T, m)

# left_indices = [[70, 170], [10, 210]]
left_profile_values = [
# ref_indices = [[70, 170], [10, 210]]
ref_profile_values = [
[0.0, 0.0],
[
0.0,
naive.distance(T[10:30], T[210:230]),
],
]

right_distance_values, right_indices = aamp_motifs(
cmp_distance_values, cmp_indices = aamp_motifs(
T,
mp[:, 0],
max_motifs=max_motifs,
Expand All @@ -124,7 +124,7 @@ def test_aamp_motifs_two_motifs():

# We ignore indices because of sorting ambiguities for equal distances.
# As long as the distances are correct, the indices will be too.
npt.assert_almost_equal(left_profile_values, right_distance_values, decimal=6)
npt.assert_allclose(cmp_distance_values, ref_profile_values, atol=1.5e-06)


def test_aamp_naive_match_exact():
Expand All @@ -135,8 +135,8 @@ def test_aamp_naive_match_exact():
excl_zone = int(np.ceil(m / 4))

for p in [1.0, 2.0, 3.0]:
left = [[0, 0], [0, 5]]
right = list(
ref = [[0, 0], [0, 5]]
cmp = list(
naive_aamp_match(
Q,
T,
Expand All @@ -147,9 +147,13 @@ def test_aamp_naive_match_exact():
)
# To avoid sorting errors we first sort based on distance and then based on
# indices
right.sort(key=lambda x: (x[1], x[0]))
cmp.sort(key=lambda x: (x[1], x[0]))

npt.assert_almost_equal(left, right)
npt.assert_allclose(
np.array(cmp).astype(np.float64),
np.array(ref).astype(np.float64),
atol=1.5e-07,
)


def test_aamp_naive_match_exclusion_zone():
Expand All @@ -166,11 +170,11 @@ def test_aamp_naive_match_exclusion_zone():
excl_zone = m

for p in [1.0, 2.0, 3.0]:
left = [
ref = [
[0, 3],
[naive.distance(Q, T[7 : 7 + m], p=p), 7],
]
right = list(
cmp = list(
naive_aamp_match(
Q,
T,
Expand All @@ -181,9 +185,13 @@ def test_aamp_naive_match_exclusion_zone():
)
# To avoid sorting errors we first sort based on distance and then based on
# indices
right.sort(key=lambda x: (x[0], x[1]))
cmp.sort(key=lambda x: (x[0], x[1]))

npt.assert_almost_equal(left, right)
npt.assert_allclose(
np.array(cmp).astype(np.float64),
np.array(ref).astype(np.float64),
atol=1.5e-07,
)


@pytest.mark.parametrize("Q, T", test_data)
Expand All @@ -193,23 +201,25 @@ def test_aamp_match(Q, T):
max_distance = 0.3

for p in [1.0, 2.0, 3.0]:
left = naive_aamp_match(
ref = naive_aamp_match(
Q,
T,
p=p,
excl_zone=excl_zone,
max_distance=max_distance,
)

right = aamp_match(
cmp = aamp_match(
Q,
T,
p=p,
max_matches=None,
max_distance=max_distance,
)

npt.assert_almost_equal(left, right)
npt.assert_allclose(
cmp.astype(np.float64), ref.astype(np.float64), atol=1.5e-07
)


@pytest.mark.parametrize("Q, T", test_data)
Expand All @@ -220,15 +230,15 @@ def test_aamp_match_T_subseq_isfinite(Q, T):
T, T_subseq_isfinite = core.preprocess_non_normalized(T, len(Q))

for p in [1.0, 2.0, 3.0]:
left = naive_aamp_match(
ref = naive_aamp_match(
Q,
T,
p=p,
excl_zone=excl_zone,
max_distance=max_distance,
)

right = aamp_match(
cmp = aamp_match(
Q,
T,
T_subseq_isfinite,
Expand All @@ -237,7 +247,9 @@ def test_aamp_match_T_subseq_isfinite(Q, T):
max_distance=max_distance,
)

npt.assert_almost_equal(left, right)
npt.assert_allclose(
cmp.astype(np.float64), ref.astype(np.float64), atol=1.5e-07
)


def test_aamp_match_query_idx():
Expand All @@ -248,12 +260,12 @@ def test_aamp_match_query_idx():

# `mass_absolute` zeroes the self-match distance when told where `Q` lives.
D = core.mass_absolute(Q, T, query_idx=query_idx)
npt.assert_almost_equal(D[query_idx], 0.0)
npt.assert_allclose(D[query_idx], 0.0, atol=1.5e-07)

# A `Q` that is not the subsequence at `query_idx` must still return the
# self-match first, and must warn, exactly as `stumpy.match` does.
with pytest.warns(UserWarning):
out = aamp_match(Q + 0.5, T, query_idx=query_idx, max_distance=1.0)

assert out[0, 1] == query_idx
npt.assert_almost_equal(out[0, 0], 0.0)
npt.assert_allclose(out[0, 0], 0.0, atol=1.5e-07)
Loading