|
43 | 43 | }, |
44 | 44 | { |
45 | 45 | "cell_type": "code", |
46 | | - "execution_count": 2, |
| 46 | + "execution_count": 1, |
47 | 47 | "id": "c9564cff", |
48 | 48 | "metadata": {}, |
49 | 49 | "outputs": [], |
|
69 | 69 | }, |
70 | 70 | { |
71 | 71 | "cell_type": "code", |
72 | | - "execution_count": 3, |
| 72 | + "execution_count": 18, |
73 | 73 | "id": "409dad09", |
74 | 74 | "metadata": {}, |
75 | 75 | "outputs": [], |
|
128 | 128 | }, |
129 | 129 | { |
130 | 130 | "cell_type": "code", |
131 | | - "execution_count": 4, |
| 131 | + "execution_count": 3, |
132 | 132 | "id": "c21c4587", |
133 | 133 | "metadata": {}, |
134 | 134 | "outputs": [], |
135 | 135 | "source": [ |
136 | 136 | "def next_pow2(val):\n", |
137 | 137 | " \"\"\"\n", |
138 | | - " Compute the smallest \"power of two\" number that is greater than/ equal to `v`\n", |
| 138 | + " Compute the smallest \"power of two\" number that is greater than/ equal to `val`\n", |
139 | 139 | " \n", |
140 | 140 | " Parameters\n", |
141 | 141 | " ----------\n", |
|
152 | 152 | }, |
153 | 153 | { |
154 | 154 | "cell_type": "code", |
155 | | - "execution_count": 5, |
| 155 | + "execution_count": 19, |
156 | 156 | "id": "dd1f7b3d", |
157 | 157 | "metadata": {}, |
158 | 158 | "outputs": [], |
|
214 | 214 | " out.append([max(chunk_start, start), chunk_stop])\n", |
215 | 215 | " chunk_stop = chunk_start + m - 1\n", |
216 | 216 | " \n", |
217 | | - " if chunk_start <= 0:\n", |
| 217 | + " if chunk_start <= start:\n", |
218 | 218 | " break\n", |
219 | 219 | " \n", |
220 | 220 | " return np.array(out)" |
221 | 221 | ] |
222 | 222 | }, |
223 | 223 | { |
224 | 224 | "cell_type": "code", |
225 | | - "execution_count": 6, |
| 225 | + "execution_count": 20, |
226 | 226 | "id": "5e45d72c", |
227 | 227 | "metadata": {}, |
228 | 228 | "outputs": [ |
|
235 | 235 | " [ 0, 56]])" |
236 | 236 | ] |
237 | 237 | }, |
238 | | - "execution_count": 6, |
| 238 | + "execution_count": 20, |
239 | 239 | "metadata": {}, |
240 | 240 | "output_type": "execute_result" |
241 | 241 | } |
|
256 | 256 | }, |
257 | 257 | { |
258 | 258 | "cell_type": "code", |
259 | | - "execution_count": 7, |
| 259 | + "execution_count": 6, |
260 | 260 | "id": "79663447", |
261 | 261 | "metadata": {}, |
262 | 262 | "outputs": [], |
|
269 | 269 | " M_T, \n", |
270 | 270 | " Σ_T, \n", |
271 | 271 | " T_subseq_isconstant, \n", |
| 272 | + " chunks_range,\n", |
272 | 273 | " bsf,\n", |
273 | | - " chunks_range=None,\n", |
274 | 274 | "):\n", |
275 | 275 | " \"\"\"\n", |
276 | 276 | " Compute the (approximate) distance between the subsequence `T[query_idx:query_idx+m]`\n", |
|
300 | 300 | " A numpy boolean array whose i-th element indicates whether the subsequence\n", |
301 | 301 | " `T[i : i+m]` is constant (True)\n", |
302 | 302 | " \n", |
303 | | - " bsf : float\n", |
304 | | - " The best-so-far discord distance\n", |
305 | | - " \n", |
306 | | - " chunks_range : numpy.ndarray, default None\n", |
| 303 | + " chunks_range : numpy.ndarray\n", |
307 | 304 | " A 2D numpy array consisting of rows, each represents\n", |
308 | 305 | " the (start, stop) range of a chunk\n", |
309 | 306 | " \n", |
| 307 | + " bsf : float\n", |
| 308 | + " The best-so-far discord distance\n", |
| 309 | + " \n", |
310 | 310 | " Returns\n", |
311 | 311 | " -------\n", |
312 | 312 | " nn_distance : float\n", |
|
316 | 316 | " bsf : float\n", |
317 | 317 | " The best-so-far discord distance \n", |
318 | 318 | " \"\"\"\n", |
319 | | - " if chunks_range is None:\n", |
320 | | - " # The avoid the trivial (left) neighbors of `T[query_idx : query_idx+m]`,\n", |
321 | | - " # the stop index of non-trivial subsequences is `query_idx - excl_zone + m`\n", |
322 | | - " chunks_range = naive_get_range_damp(query_idx - excl_zone + m, m, start=0)\n", |
323 | | - " \n", |
324 | 319 | " nn_distance = np.inf\n", |
325 | 320 | " for (start, stop) in chunks_range:\n", |
326 | 321 | " QT = core.sliding_dot_product(\n", |
|
350 | 345 | }, |
351 | 346 | { |
352 | 347 | "cell_type": "code", |
353 | | - "execution_count": 8, |
| 348 | + "execution_count": 21, |
354 | 349 | "id": "c76317b5", |
355 | 350 | "metadata": {}, |
356 | 351 | "outputs": [], |
|
429 | 424 | }, |
430 | 425 | { |
431 | 426 | "cell_type": "code", |
432 | | - "execution_count": 9, |
| 427 | + "execution_count": 32, |
433 | 428 | "id": "769bddad", |
434 | 429 | "metadata": {}, |
435 | 430 | "outputs": [], |
|
470 | 465 | " \n", |
471 | 466 | " excl_zone = int(math.ceil(m / stumpy.core.config.STUMPY_EXCL_ZONE_DENOM))\n", |
472 | 467 | " chunks_range = get_damp_range(split_idx - excl_zone + m, m, start=0)\n", |
473 | | - " \n", |
474 | 468 | " last_chunk_size = chunks_range[-1, 1] - chunks_range[-1, 0]\n", |
475 | 469 | " last_chunk_size_cutoff = next_pow2(last_chunk_size)\n", |
476 | 470 | " \n", |
|
487 | 481 | " excl_zone, \n", |
488 | 482 | " M_T, \n", |
489 | 483 | " Σ_T, \n", |
490 | | - " T_subseq_isconstant, \n", |
491 | | - " bsf, \n", |
492 | | - " chunks_range=chunks_range\n", |
| 484 | + " T_subseq_isconstant, \n", |
| 485 | + " chunks_range,\n", |
| 486 | + " bsf,\n", |
493 | 487 | " )\n", |
494 | 488 | " _foreward_process(T, m, excl_zone, M_T, Σ_T, T_subseq_isconstant, i, lookahead, PL)\n", |
495 | 489 | " \n", |
496 | | - " chunks_range = chunks_range + 1 \n", |
497 | | - " # make a decision on whether to create new chunk or not for the subsequence [0, m]\n", |
| 490 | + " chunks_range[:] = chunks_range + 1 \n", |
498 | 491 | " if last_chunk_size < last_chunk_size_cutoff:\n", |
499 | 492 | " chunks_range[-1, 0] = 0 \n", |
500 | 493 | " last_chunk_size += 1\n", |
|
521 | 514 | }, |
522 | 515 | { |
523 | 516 | "cell_type": "code", |
524 | | - "execution_count": 10, |
| 517 | + "execution_count": 23, |
525 | 518 | "id": "2cfbc771", |
526 | 519 | "metadata": {}, |
527 | 520 | "outputs": [], |
|
536 | 529 | }, |
537 | 530 | { |
538 | 531 | "cell_type": "code", |
539 | | - "execution_count": 11, |
| 532 | + "execution_count": 24, |
540 | 533 | "id": "a935f31f", |
541 | 534 | "metadata": {}, |
542 | 535 | "outputs": [ |
|
546 | 539 | "text": [ |
547 | 540 | "discord_dist: 8.500883427933504\n", |
548 | 541 | "discord_index: 209\n", |
549 | | - "running time [sec]: 5.248243093490601\n" |
| 542 | + "running time [sec]: 4.881464958190918\n" |
550 | 543 | ] |
551 | 544 | } |
552 | 545 | ], |
|
566 | 559 | }, |
567 | 560 | { |
568 | 561 | "cell_type": "code", |
569 | | - "execution_count": 12, |
| 562 | + "execution_count": 25, |
570 | 563 | "id": "2b461592", |
571 | 564 | "metadata": {}, |
572 | 565 | "outputs": [ |
|
576 | 569 | "text": [ |
577 | 570 | "discord_dist: 8.500883427933504\n", |
578 | 571 | "discord_index: 209\n", |
579 | | - "running time [sec]: 2.2584328651428223\n" |
| 572 | + "running time [sec]: 2.2210960388183594\n" |
580 | 573 | ] |
581 | 574 | } |
582 | 575 | ], |
|
605 | 598 | }, |
606 | 599 | { |
607 | 600 | "cell_type": "code", |
608 | | - "execution_count": 13, |
| 601 | + "execution_count": 26, |
609 | 602 | "id": "d8e9fa63", |
610 | 603 | "metadata": {}, |
611 | 604 | "outputs": [], |
|
620 | 613 | }, |
621 | 614 | { |
622 | 615 | "cell_type": "code", |
623 | | - "execution_count": 14, |
| 616 | + "execution_count": 27, |
624 | 617 | "id": "263bca9c", |
625 | 618 | "metadata": {}, |
626 | 619 | "outputs": [ |
|
630 | 623 | "text": [ |
631 | 624 | "discord_dist: 7.606279752022369\n", |
632 | 625 | "discord_index: 8109\n", |
633 | | - "running time [sec]: 5.100044012069702\n" |
| 626 | + "running time [sec]: 4.996989965438843\n" |
634 | 627 | ] |
635 | 628 | } |
636 | 629 | ], |
|
651 | 644 | }, |
652 | 645 | { |
653 | 646 | "cell_type": "code", |
654 | | - "execution_count": 15, |
| 647 | + "execution_count": 28, |
655 | 648 | "id": "78d09bda", |
656 | 649 | "metadata": {}, |
657 | 650 | "outputs": [ |
|
661 | 654 | "text": [ |
662 | 655 | "discord_dist: 7.606279752022363\n", |
663 | 656 | "discord_index: 8109\n", |
664 | | - "running time [sec]: 6.70897912979126\n" |
| 657 | + "running time [sec]: 6.67956805229187\n" |
665 | 658 | ] |
666 | 659 | } |
667 | 660 | ], |
|
690 | 683 | }, |
691 | 684 | { |
692 | 685 | "cell_type": "code", |
693 | | - "execution_count": 16, |
| 686 | + "execution_count": 33, |
694 | 687 | "id": "6d64f488", |
695 | 688 | "metadata": {}, |
696 | 689 | "outputs": [], |
|
705 | 698 | }, |
706 | 699 | { |
707 | 700 | "cell_type": "code", |
708 | | - "execution_count": 17, |
| 701 | + "execution_count": 34, |
709 | 702 | "id": "159e03dc", |
710 | 703 | "metadata": {}, |
711 | 704 | "outputs": [ |
|
715 | 708 | "text": [ |
716 | 709 | "discord_dist: 29.42331306408431\n", |
717 | 710 | "discord_index: 6110\n", |
718 | | - "running time [sec]: 5.572257995605469\n" |
| 711 | + "running time [sec]: 5.483174085617065\n" |
719 | 712 | ] |
720 | 713 | } |
721 | 714 | ], |
|
736 | 729 | }, |
737 | 730 | { |
738 | 731 | "cell_type": "code", |
739 | | - "execution_count": 18, |
| 732 | + "execution_count": 35, |
740 | 733 | "id": "9ef28e10", |
741 | 734 | "metadata": {}, |
742 | 735 | "outputs": [ |
|
746 | 739 | "text": [ |
747 | 740 | "discord_dist: 29.423313064084333\n", |
748 | 741 | "discord_index: 6110\n", |
749 | | - "running time [sec]: 55.545814990997314\n" |
| 742 | + "running time [sec]: 55.60335397720337\n" |
750 | 743 | ] |
751 | 744 | } |
752 | 745 | ], |
|
0 commit comments