Compare subsequences with the same radius and return the most central motif Parameters ---------- Ts : list List of time series for which to find the most central motif bsf_radius : float Best radius found by a consensus search algorithm bsf_Ts_idx : int
(
Ts, bsf_radius, bsf_Ts_idx, bsf_subseq_idx, m, Ts_subseq_isconstant
)
| 1173 | |
| 1174 | |
| 1175 | def get_central_motif( |
| 1176 | Ts, bsf_radius, bsf_Ts_idx, bsf_subseq_idx, m, Ts_subseq_isconstant |
| 1177 | ): |
| 1178 | """ |
| 1179 | Compare subsequences with the same radius and return the most central motif |
| 1180 | |
| 1181 | Parameters |
| 1182 | ---------- |
| 1183 | Ts : list |
| 1184 | List of time series for which to find the most central motif |
| 1185 | |
| 1186 | bsf_radius : float |
| 1187 | Best radius found by a consensus search algorithm |
| 1188 | |
| 1189 | bsf_Ts_idx : int |
| 1190 | Index of time series in which `radius` was first found |
| 1191 | |
| 1192 | bsf_subseq_idx : int |
| 1193 | Start index of the subsequence in `Ts[Ts_idx]` that has radius `radius` |
| 1194 | |
| 1195 | m : int |
| 1196 | Window size |
| 1197 | |
| 1198 | Ts_subseq_isconstant : list |
| 1199 | A list of boolean arrays, each corresponds to a time series in `Ts` |
| 1200 | |
| 1201 | Returns |
| 1202 | ------- |
| 1203 | bsf_radius : float |
| 1204 | The updated radius of the most central consensus motif |
| 1205 | |
| 1206 | bsf_Ts_idx : int |
| 1207 | The updated index of time series which contains the most central consensus motif |
| 1208 | |
| 1209 | bsf_subseq_idx : int |
| 1210 | The update subsequence index of most central consensus motif within the time |
| 1211 | series `bsf_Ts_idx` that contains it |
| 1212 | """ |
| 1213 | bsf_nns_radii, bsf_nns_subseq_idx = across_series_nearest_neighbors( |
| 1214 | Ts, bsf_Ts_idx, bsf_subseq_idx, m, Ts_subseq_isconstant |
| 1215 | ) |
| 1216 | bsf_nns_mean_radii = bsf_nns_radii.mean() |
| 1217 | |
| 1218 | candidate_nns_Ts_idx = np.flatnonzero(np.isclose(bsf_nns_radii, bsf_radius)) |
| 1219 | candidate_nns_subseq_idx = bsf_nns_subseq_idx[candidate_nns_Ts_idx] |
| 1220 | |
| 1221 | for Ts_idx, subseq_idx in zip(candidate_nns_Ts_idx, candidate_nns_subseq_idx): |
| 1222 | candidate_nns_radii, _ = across_series_nearest_neighbors( |
| 1223 | Ts, Ts_idx, subseq_idx, m, Ts_subseq_isconstant |
| 1224 | ) |
| 1225 | if ( |
| 1226 | np.isclose(candidate_nns_radii.max(), bsf_radius) |
| 1227 | and candidate_nns_radii.mean() < bsf_nns_mean_radii |
| 1228 | ): |
| 1229 | bsf_Ts_idx = Ts_idx |
| 1230 | bsf_subseq_idx = subseq_idx |
| 1231 | bsf_nns_mean_radii = candidate_nns_radii.mean() |
| 1232 |
no test coverage detected