Brute force consensus motif from See Table 1 Note that there is a bug in the pseudocode at line 8 where `i` should be `j`. This implementation fixes it.
(Ts, m, Ts_subseq_isconstant)
| 1234 | |
| 1235 | |
| 1236 | def consensus_search(Ts, m, Ts_subseq_isconstant): |
| 1237 | """ |
| 1238 | Brute force consensus motif from |
| 1239 | <https://www.cs.ucr.edu/~eamonn/consensus_Motif_ICDM_Long_version.pdf> |
| 1240 | |
| 1241 | See Table 1 |
| 1242 | |
| 1243 | Note that there is a bug in the pseudocode at line 8 where `i` should be `j`. |
| 1244 | This implementation fixes it. |
| 1245 | """ |
| 1246 | k = len(Ts) |
| 1247 | |
| 1248 | bsf_radius = np.inf |
| 1249 | bsf_Ts_idx = 0 |
| 1250 | bsf_subseq_idx = 0 |
| 1251 | |
| 1252 | for j in range(k): |
| 1253 | radii = np.zeros(len(Ts[j]) - m + 1) |
| 1254 | for i in range(k): |
| 1255 | if i != j: |
| 1256 | mp = stump( |
| 1257 | Ts[j], |
| 1258 | m, |
| 1259 | Ts[i], |
| 1260 | T_A_subseq_isconstant=Ts_subseq_isconstant[j], |
| 1261 | T_B_subseq_isconstant=Ts_subseq_isconstant[i], |
| 1262 | ) |
| 1263 | radii = np.maximum(radii, mp[:, 0]) |
| 1264 | min_radius_idx = np.argmin(radii) |
| 1265 | min_radius = radii[min_radius_idx] |
| 1266 | if min_radius < bsf_radius: |
| 1267 | bsf_radius = min_radius |
| 1268 | bsf_Ts_idx = j |
| 1269 | bsf_subseq_idx = min_radius_idx |
| 1270 | |
| 1271 | return bsf_radius, bsf_Ts_idx, bsf_subseq_idx |
| 1272 | |
| 1273 | |
| 1274 | def ostinato(Ts, m, Ts_subseq_isconstant=None): |