MCPcopy
hub / github.com/stumpy-dev/stumpy / update

Method update

tests/naive.py:908–955  ·  view source on GitHub ↗
(self, t)

Source from the content-addressed store, hash-verified

906 self._n_appended = 0
907
908 def update(self, t):
909 self._T[:] = np.roll(self._T, -1)
910 self._T_isfinite[:] = np.roll(self._T_isfinite, -1)
911 if np.isfinite(t):
912 self._T_isfinite[-1] = True
913 self._T[-1] = t
914 else:
915 self._T_isfinite[-1] = False
916 self._T[-1] = 0
917 self._n_appended += 1
918
919 self._P = np.roll(self._P, -1, axis=0)
920 self._I = np.roll(self._I, -1, axis=0)
921 self._left_P[:] = np.roll(self._left_P, -1)
922 self._left_I[:] = np.roll(self._left_I, -1)
923
924 D = cdist(
925 core.rolling_window(self._T[-self._m :], self._m),
926 core.rolling_window(self._T, self._m),
927 metric="minkowski",
928 p=self._p,
929 )[0]
930 T_subseq_isfinite = np.all(
931 core.rolling_window(self._T_isfinite, self._m), axis=1
932 )
933 D[~T_subseq_isfinite] = np.inf
934 if np.any(~self._T_isfinite[-self._m :]):
935 D[:] = np.inf
936
937 apply_exclusion_zone(D, D.shape[0] - 1, self._excl_zone, np.inf)
938 for j in range(D.shape[0]):
939 if D[j] < self._P[j, -1]:
940 pos = np.searchsorted(self._P[j], D[j], side="right")
941 self._P[j] = np.insert(self._P[j], pos, D[j])[:-1]
942 self._I[j] = np.insert(
943 self._I[j], pos, D.shape[0] - 1 + self._n_appended
944 )[:-1]
945
946 # update top-k for the last, newly-updated index
947 I_last_topk = np.argsort(D, kind="mergesort")[: self._k]
948 self._P[-1] = D[I_last_topk]
949 self._I[-1] = I_last_topk + self._n_appended
950 self._I[-1][self._P[-1] == np.inf] = -1
951
952 # for the last index, the left matrix profile value is self.P_[-1, 0]
953 # and the same goes for the left matrix profile index
954 self._left_P[-1] = self._P[-1, 0]
955 self._left_I[-1] = self._I[-1, 0]
956
957 @property
958 def P_(self):

Callers 15

test_stimp_1_percentFunction · 0.45
test_stimp_max_mFunction · 0.45
test_stimp_100_percentFunction · 0.45
test_stimp_raw_mpFunction · 0.45
test_stimpedFunction · 0.45
test_scrumpFunction · 0.45
test_scrump_plus_plusFunction · 0.45
test_stumpiFunction · 0.45
test_stimpFunction · 0.45

Calls 1

apply_exclusion_zoneFunction · 0.70

Tested by 15

test_stimp_1_percentFunction · 0.36
test_stimp_max_mFunction · 0.36
test_stimp_100_percentFunction · 0.36
test_stimp_raw_mpFunction · 0.36
test_stimpedFunction · 0.36
test_scrumpFunction · 0.36
test_scrump_plus_plusFunction · 0.36
test_stumpiFunction · 0.36
test_stimpFunction · 0.36