Skip to content

Commit 80fe436

Browse files
committed
Improved coverage. Back to 100% for FLOSS
1 parent 2637a82 commit 80fe436

File tree

3 files changed

+57
-30
lines changed

3 files changed

+57
-30
lines changed

docs/Tutorial_Semantic_Segmentation.ipynb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
{
167167
"data": {
168168
"text/plain": [
169-
"<matplotlib.patches.Rectangle at 0x1a1b22ac50>"
169+
"<matplotlib.patches.Rectangle at 0x1a1af70c50>"
170170
]
171171
},
172172
"execution_count": 4,
@@ -216,7 +216,7 @@
216216
{
217217
"data": {
218218
"text/plain": [
219-
"<matplotlib.patches.FancyArrowPatch at 0x1a1bbfbe50>"
219+
"<matplotlib.patches.FancyArrowPatch at 0x1a1b942f50>"
220220
]
221221
},
222222
"execution_count": 5,
@@ -336,7 +336,7 @@
336336
{
337337
"data": {
338338
"text/plain": [
339-
"<matplotlib.lines.Line2D at 0x1a1eeeaa50>"
339+
"<matplotlib.lines.Line2D at 0x1a1ecba590>"
340340
]
341341
},
342342
"execution_count": 8,
@@ -397,7 +397,7 @@
397397
{
398398
"data": {
399399
"text/plain": [
400-
"[<matplotlib.lines.Line2D at 0x1a1f5a1210>]"
400+
"[<matplotlib.lines.Line2D at 0x1a1f6e48d0>]"
401401
]
402402
},
403403
"execution_count": 10,
@@ -491,8 +491,9 @@
491491
"You can now update the `stream` with a new data points `t` via the `stream.update(t)` function and this will slide your window over by one data point and it will automatically update:\n",
492492
"\n",
493493
"1. the `CAC_1D` (accessed via the `.cac_` attribute)\n",
494-
"2. the matrix profile (accessed via the `.mp_` attribute)\n",
495-
"3. the sliding window of data used to produce the `CAC_1D` (accessed via the `.T_` attribute - this should be the same size as the length of the `old_data\\)\n",
494+
"2. the matrix profile (accessed via the `.P_` attribute)\n",
495+
"3. the matrix profile indices (accessed via the `.I_` attribute)\n",
496+
"4. the sliding window of data used to produce the `CAC_1D` (accessed via the `.T_` attribute - this should be the same size as the length of the `old_data\\)\n",
496497
"\n",
497498
"Let's continuosly update our `stream` with the `new_data` one value at a time and store them in a list (you'll see why in a second):"
498499
]

stumpy/floss.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,13 @@ class floss(object):
341341
A corrected arc curve (CAC) updated as a result of ingressing a single
342342
new data point and egressing a single old data point.
343343
344-
mp_ : ndarray
345-
The first column consists of the matrix profile and the second column
346-
consists of the matrix profile indices. This updated matrix profile and
347-
matrix profile indices are a result of ingressing a single new data
348-
point and egressing a single old data point. Note that this array does
349-
not contain the left and right matrix profile indices.
344+
P_ : ndarray
345+
The matrix profile updated as a result of ingressing a single new data
346+
point and egressing a single old data point.
347+
348+
I_ : ndarray
349+
The (right) matrix profile indices updated as a result of ingressing a single
350+
new data point and egressing a single old data point.
350351
351352
T_ : ndarray
352353
The updated time series, `T`
@@ -519,18 +520,25 @@ def update(self, t):
519520
self._n_appended += 1
520521

521522
@property
522-
def mp_(self):
523+
def cac_(self):
524+
"""
525+
Get the updated corrected arc curve (CAC)
526+
"""
527+
return self._cac.astype(np.float)
528+
529+
@property
530+
def P_(self):
523531
"""
524532
Get the updated matrix profile
525533
"""
526-
return self._mp.astype(np.float)
534+
return self._mp[:, 0].astype(np.float)
527535

528536
@property
529-
def cac_(self):
537+
def I_(self):
530538
"""
531-
Get the updated corrected arc curve (CAC)
539+
Get the updated (right) matrix profile indices
532540
"""
533-
return self._cac.astype(np.float)
541+
return self._mp[:, 3].astype(np.float)
534542

535543
@property
536544
def T_(self):

tests/test_floss.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from stumpy import _nnmark, _iac, _cac, _rea, fluss, stump, core, floss
44
import copy
55
import pytest
6+
import naive
67

78

89
def naive_nnmark(I):
@@ -141,9 +142,9 @@ def test_floss():
141142
n = old_data.shape[0]
142143
add_data = data[30:]
143144

144-
left_mp = naive_right_mp(old_data, m)
145+
mp = naive_right_mp(old_data, m)
145146
right_mp = stump(old_data, m)
146-
k = left_mp.shape[0]
147+
k = mp.shape[0]
147148

148149
rolling_Ts = core.rolling_window(data[1:], n)
149150
L = 5
@@ -153,25 +154,42 @@ def test_floss():
153154
last_idx = n - m + 1
154155
excl_zone = int(np.ceil(m / 4))
155156
zone_start = max(0, k - excl_zone)
156-
for i, T in enumerate(rolling_Ts):
157-
left_mp[:] = np.roll(left_mp, -1, axis=0)
158-
left_mp[-1, 0] = np.inf
159-
left_mp[-1, 3] = last_idx + i
160-
161-
D = naive_distance_profile(T[-m:], T, m)
157+
for i, left_T in enumerate(rolling_Ts):
158+
mp[:, 1] = -1
159+
mp[:, 2] = -1
160+
mp[:] = np.roll(mp, -1, axis=0)
161+
mp[-1, 0] = np.inf
162+
mp[-1, 3] = last_idx + i
163+
164+
D = naive_distance_profile(left_T[-m:], left_T, m)
162165
D[zone_start:] = np.inf
163166

164-
update_idx = np.argwhere(D < left_mp[:, 0]).flatten()
165-
left_mp[update_idx, 0] = D[update_idx]
166-
left_mp[update_idx, 3] = last_idx + i
167+
update_idx = np.argwhere(D < mp[:, 0]).flatten()
168+
mp[update_idx, 0] = D[update_idx]
169+
mp[update_idx, 3] = last_idx + i
167170

168171
left_cac = _cac(
169-
left_mp[:, 3] - i - 1,
172+
mp[:, 3] - i - 1,
170173
L,
171174
bidirectional=False,
172175
excl_factor=excl_factor,
173176
custom_iac=custom_iac,
174177
)
175-
stream.update(T[-1])
178+
179+
left_mp = mp.copy()
180+
left_P = left_mp[:, 0]
181+
left_I = left_mp[:, 3]
182+
183+
stream.update(left_T[-1])
176184
right_cac = stream.cac_
185+
right_P = stream.P_
186+
right_I = stream.I_
187+
right_T = stream.T_
188+
189+
naive.replace_inf(left_P)
190+
naive.replace_inf(right_P)
191+
177192
npt.assert_almost_equal(left_cac, right_cac)
193+
npt.assert_almost_equal(left_P, right_P)
194+
npt.assert_almost_equal(left_I, right_I)
195+
npt.assert_almost_equal(left_T, right_T)

0 commit comments

Comments
 (0)