| 431 | |
| 432 | |
| 433 | def test_floss_with_isconstant(): |
| 434 | data = np.random.uniform(-1, 1, [64]) |
| 435 | m = 5 |
| 436 | n = 30 |
| 437 | old_data = data[:n] |
| 438 | |
| 439 | quantile_threshold = 0.5 |
| 440 | sliding_stddev = naive.rolling_nanstd(old_data, m) |
| 441 | stddev_threshold = np.quantile(sliding_stddev, quantile_threshold) |
| 442 | isconstant_custom_func = functools.partial( |
| 443 | naive.isconstant_func_stddev_threshold, |
| 444 | stddev_threshold=stddev_threshold, |
| 445 | ) |
| 446 | |
| 447 | mp = naive_right_mp(T=old_data, m=m, T_subseq_isconstant=isconstant_custom_func) |
| 448 | comp_mp = stump(T_A=old_data, m=m, T_A_subseq_isconstant=isconstant_custom_func) |
| 449 | k = mp.shape[0] |
| 450 | |
| 451 | rolling_Ts = core.rolling_window(data[1:], n) |
| 452 | L = 5 |
| 453 | excl_factor = 1 |
| 454 | custom_iac = _iac(k, bidirectional=False) |
| 455 | stream = floss( |
| 456 | comp_mp, |
| 457 | old_data, |
| 458 | m, |
| 459 | L, |
| 460 | excl_factor, |
| 461 | custom_iac=custom_iac, |
| 462 | T_subseq_isconstant_func=isconstant_custom_func, |
| 463 | ) |
| 464 | last_idx = n - m + 1 |
| 465 | excl_zone = int(np.ceil(m / 4)) |
| 466 | zone_start = max(0, k - excl_zone) |
| 467 | for i, ref_T in enumerate(rolling_Ts): |
| 468 | mp[:, 1] = -1 |
| 469 | mp[:, 2] = -1 |
| 470 | mp[:] = np.roll(mp, -1, axis=0) |
| 471 | mp[-1, 0] = np.inf |
| 472 | mp[-1, 3] = last_idx + i |
| 473 | |
| 474 | ref_Q = ref_T[-m:] |
| 475 | ref_Q_isconstant = isconstant_custom_func(ref_Q, m)[0] |
| 476 | ref_T_subseq_isconstant = isconstant_custom_func(ref_T, m) |
| 477 | D = naive.distance_profile(ref_Q, ref_T, m) |
| 478 | for j in range(len(D)): |
| 479 | if ref_Q_isconstant and ref_T_subseq_isconstant[j]: |
| 480 | D[j] = 0 |
| 481 | elif ref_Q_isconstant or ref_T_subseq_isconstant[j]: |
| 482 | D[j] = np.sqrt(m) |
| 483 | else: |
| 484 | pass |
| 485 | D[zone_start:] = np.inf |
| 486 | |
| 487 | update_idx = np.argwhere(D < mp[:, 0]).flatten() |
| 488 | mp[update_idx, 0] = D[update_idx] |
| 489 | mp[update_idx, 3] = last_idx + i |
| 490 | |