MCPcopy Index your code
hub / github.com/stumpy-dev/stumpy / across_series_nearest_neighbors

Function across_series_nearest_neighbors

tests/naive.py:1115–1172  ·  view source on GitHub ↗

For multiple time series find, per individual time series, the subsequences closest to a query. Parameters ---------- Ts : list A list of time series for which to find the nearest neighbor subsequences that are closest to the query subsequence `Ts[Ts_idx][subseq

(Ts, Ts_idx, subseq_idx, m, Ts_subseq_isconstant)

Source from the content-addressed store, hash-verified

1113
1114
1115def across_series_nearest_neighbors(Ts, Ts_idx, subseq_idx, m, Ts_subseq_isconstant):
1116 """
1117 For multiple time series find, per individual time series, the subsequences closest
1118 to a query.
1119
1120 Parameters
1121 ----------
1122 Ts : list
1123 A list of time series for which to find the nearest neighbor subsequences that
1124 are closest to the query subsequence `Ts[Ts_idx][subseq_idx : subseq_idx + m]`
1125
1126 Ts_idx : int
1127 The index of time series in `Ts` which contains the query subsequence
1128 `Ts[Ts_idx][subseq_idx : subseq_idx + m]`
1129
1130 subseq_idx : int
1131 The subsequence index in the time series `Ts[Ts_idx]` that contains the query
1132 subsequence `Ts[Ts_idx][subseq_idx : subseq_idx + m]`
1133
1134 m : int
1135 Subsequence window size
1136
1137 Ts_subseq_isconstant : list
1138 A list of `T_subseq_isconstant`, where the i-th item corresponds to `Ts[i]`
1139
1140 Returns
1141 -------
1142 nns_radii : ndarray
1143 Nearest neighbor radii to subsequences in `Ts` that are closest to the query
1144 `Ts[Ts_idx][subseq_idx : subseq_idx + m]`
1145
1146 nns_subseq_idx : ndarray
1147 Nearest neighbor indices to subsequences in `Ts` that are closest to the query
1148 `Ts[Ts_idx][subseq_idx : subseq_idx + m]`
1149 """
1150 k = len(Ts)
1151
1152 Q = Ts[Ts_idx][subseq_idx : subseq_idx + m]
1153 Q_subseq_isconstant = Ts_subseq_isconstant[Ts_idx][subseq_idx]
1154
1155 nns_radii = np.zeros(k, dtype=np.float64)
1156 nns_subseq_idx = np.zeros(k, dtype=np.int64)
1157
1158 for i in range(k):
1159 dist_profile = distance_profile(Q, Ts[i], len(Q))
1160 for j in range(len(dist_profile)):
1161 if np.isfinite(dist_profile[j]):
1162 if Q_subseq_isconstant and Ts_subseq_isconstant[i][j]:
1163 dist_profile[j] = 0
1164 elif Q_subseq_isconstant or Ts_subseq_isconstant[i][j]:
1165 dist_profile[j] = np.sqrt(m)
1166 else: # pragma: no cover
1167 pass
1168
1169 nns_subseq_idx[i] = np.argmin(dist_profile)
1170 nns_radii[i] = dist_profile[nns_subseq_idx[i]]
1171
1172 return nns_radii, nns_subseq_idx

Callers 1

get_central_motifFunction · 0.85

Calls 1

distance_profileFunction · 0.85

Tested by

no test coverage detected