Skip to content

Fix #890 Fix number of contiguous windows in snippet #894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
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
134 changes: 66 additions & 68 deletions docs/Tutorial_Time_Series_Snippets.ipynb

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions stumpy/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def _get_all_profiles(

right_pad = 0
T_subseq_isconstant = core.process_isconstant(T, s, mpdist_T_subseq_isconstant)
n_contiguous_windows = int(T.shape[0] // m)
if T.shape[0] % m != 0:
right_pad = int(m * np.ceil(T.shape[0] / m) - T.shape[0])
pad_width = (0, right_pad)
Expand All @@ -111,12 +112,12 @@ def _get_all_profiles(
)

n_padded = T.shape[0]
D = np.empty(((n_padded // m) - 1, n_padded - m + 1), dtype=np.float64)
D = np.empty((n_contiguous_windows, n_padded - m + 1), dtype=np.float64)

M_T, Σ_T = core.compute_mean_std(T, s)

# Iterate over non-overlapping subsequences, see Definition 3
for i in range((n_padded // m) - 1):
for i in range(n_contiguous_windows):
start = i * m
stop = (i + 1) * m
S_i = T[start:stop]
Expand Down Expand Up @@ -290,17 +291,13 @@ def snippets(
mpdist_T_subseq_isconstant=mpdist_T_subseq_isconstant,
)

pad_width = (0, int(m * np.ceil(T.shape[0] / m) - T.shape[0]))
T_padded = np.pad(T, pad_width, mode="constant", constant_values=np.nan)
n_padded = T_padded.shape[0]

snippets = np.empty((k, m), dtype=np.float64)
snippets_indices = np.empty(k, dtype=np.int64)
snippets_profiles = np.empty((k, D.shape[-1]), dtype=np.float64)
snippets_fractions = np.empty(k, dtype=np.float64)
snippets_areas = np.empty(k, dtype=np.float64)
Q = np.full(D.shape[-1], np.inf, dtype=np.float64)
indices = np.arange(0, n_padded - m, m, dtype=np.int64)
indices = np.arange(D.shape[0], dtype=np.int64) * m
snippets_regimes_list = []

for i in range(k):
Expand Down
11 changes: 4 additions & 7 deletions tests/naive.py
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,7 @@ def get_all_mpdist_profiles(

T_subseq_isconstant = rolling_isconstant(T, s, mpdist_T_subseq_isconstant)
right_pad = 0
n_contiguous_windows = int(T.shape[0] // m)
if T.shape[0] % m != 0:
right_pad = int(m * np.ceil(T.shape[0] / m) - T.shape[0])
pad_width = (0, right_pad)
Expand All @@ -1557,10 +1558,10 @@ def get_all_mpdist_profiles(
)

n_padded = T.shape[0]
D = np.empty(((n_padded // m) - 1, n_padded - m + 1))
D = np.empty((n_contiguous_windows, n_padded - m + 1))

# Iterate over non-overlapping subsequences, see Definition 3
for i in range((n_padded // m) - 1):
for i in range(n_contiguous_windows):
start = i * m
stop = (i + 1) * m
S_i = T[start:stop]
Expand Down Expand Up @@ -1601,17 +1602,13 @@ def mpdist_snippets(
mpdist_T_subseq_isconstant=mpdist_T_subseq_isconstant,
)

pad_width = (0, int(m * np.ceil(T.shape[0] / m) - T.shape[0]))
T_padded = np.pad(T, pad_width, mode="constant", constant_values=np.nan)
n_padded = T_padded.shape[0]

snippets = np.empty((k, m))
snippets_indices = np.empty(k, dtype=np.int64)
snippets_profiles = np.empty((k, D.shape[-1]))
snippets_fractions = np.empty(k)
snippets_areas = np.empty(k)
Q = np.inf
indices = np.arange(0, n_padded - m, m)
indices = np.arange(0, D.shape[0] * m, m)
snippets_regimes_list = []

for snippet_idx in range(k):
Expand Down