Skip to content

Commit 350ce60

Browse files
committed
Fixed #979 Normalize subsequences before plotting
1 parent d278a6a commit 350ce60

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

docs/Tutorial_AB_Joins.ipynb

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,11 @@
336336
}
337337
],
338338
"source": [
339-
"plt.plot(queen_df.iloc[queen_motif_index : queen_motif_index + m].values, label='Under Pressure')\n",
340-
"plt.plot(vanilla_ice_df.iloc[vanilla_ice_motif_index:vanilla_ice_motif_index+m].values, label='Ice Ice Baby')\n",
339+
"queen_z_norm_motif = core.z_norm(queen_df.iloc[queen_motif_index : queen_motif_index + m].values)\n",
340+
"vanilla_ice_z_norm_motif = core.z_norm(vanilla_ice_df.iloc[vanilla_ice_motif_index:vanilla_ice_motif_index+m].values)\n",
341+
"\n",
342+
"plt.plot(queen_z_norm_motif, label='Under Pressure')\n",
343+
"plt.plot(vanilla_ice_z_norm_motif, label='Ice Ice Baby')\n",
341344
"\n",
342345
"plt.xlabel('Time')\n",
343346
"plt.ylabel('Frequency')\n",
@@ -347,6 +350,26 @@
347350
"plt.show()"
348351
]
349352
},
353+
{
354+
"cell_type": "markdown",
355+
"metadata": {},
356+
"source": [
357+
"[comment]: <> (Myst)\n",
358+
":::{admonition} **Z-normalizing Your Subsequences Before Plotting**\n",
359+
":class: note\n",
360+
"\n",
361+
"By default, `stumpy` z-normalizes **all** subsequences before comparing their matrix profile distances (i.e., `normalize=True`). Thus, before we visualize the matching subsequences, we must also z-normalize them first. Failure to do so would result in subsequences being plotted with non-normalized amplitudes. Subsequence z-normalization can be easily accomplished by using the `core.z_norm` helper function:\n",
362+
"\n",
363+
"```\n",
364+
"from stumpy import core\n",
365+
"\n",
366+
"core.z_norm(T[idx : idx + m])\n",
367+
"```\n",
368+
"\n",
369+
"However, this z-normalization step should be omitted whenever the `normalize` parameter has been set to `False` when computing matrix profile distances.\n",
370+
":::"
371+
]
372+
},
350373
{
351374
"cell_type": "markdown",
352375
"metadata": {},
@@ -385,7 +408,7 @@
385408
"name": "python",
386409
"nbconvert_exporter": "python",
387410
"pygments_lexer": "ipython3",
388-
"version": "3.12.3"
411+
"version": "3.12.4"
389412
}
390413
},
391414
"nbformat": 4,

0 commit comments

Comments
 (0)