-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuickstart.html
833 lines (651 loc) · 39.5 KB
/
Quickstart.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quickstart Guide — MatrixProfile</title>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/custom.css" type="text/css" />
<!--[if lt IE 9]>
<script src="_static/js/html5shiv.min.js"></script>
<![endif]-->
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["$", "$"], ["\\(", "\\)"]], "processEscapes": true, "ignoreClass": "document", "processClass": "math|output_area"}})</script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="API" href="api.html" />
<link rel="prev" title="Mac OS Installation" href="installation/Mac_OS_Installation.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" style="background: white" >
<a href="index.html" class="icon icon-home" alt="Documentation Home"> matrixprofile
<img src="_static/mpf-logo.png" class="logo" alt="Logo"/>
</a>
<div class="version">
1.1.6
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="install.html">Installation</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Quickstart Guide</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#Import-Modules">Import Modules</a></li>
<li class="toctree-l2"><a class="reference internal" href="#Analyzing-Pan-MatrixProfile">Analyzing Pan-MatrixProfile</a></li>
<li class="toctree-l2"><a class="reference internal" href="#Pan-MatrixProfile-Data-Structure">Pan-MatrixProfile Data Structure</a></li>
<li class="toctree-l2"><a class="reference internal" href="#Picking-a-MatrixProfile-From-Pan-MatrixProfile">Picking a MatrixProfile From Pan-MatrixProfile</a></li>
<li class="toctree-l2"><a class="reference internal" href="#Analyzing-MatrixProfile">Analyzing MatrixProfile</a></li>
<li class="toctree-l2"><a class="reference internal" href="#MatrixProfile-Data-Structure">MatrixProfile Data Structure</a></li>
<li class="toctree-l2"><a class="reference internal" href="#Computing-MatrixProfile-and-Pan-MatrixProfile">Computing MatrixProfile and Pan-MatrixProfile</a></li>
<li class="toctree-l2"><a class="reference internal" href="#Discover-Motifs-and-Discords">Discover Motifs and Discords</a></li>
<li class="toctree-l2"><a class="reference internal" href="#Visualize">Visualize</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples.html">Examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="Algorithms.html">Algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="help.html">Getting Help</a></li>
<li class="toctree-l1"><a class="reference internal" href="contributing.html">Contributing</a></li>
<li class="toctree-l1"><a class="reference internal" href="code_of_conduct.html">Code of Conduct</a></li>
<li class="toctree-l1"><a class="reference internal" href="citations.html">Citations</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/matrix-profile-foundation/matrixprofile">Code Repository (Github)</a></li>
<li class="toctree-l1"><a class="reference external" href="https://matrixprofile.org">Website</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">matrixprofile</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html" class="icon icon-home"></a> »</li>
<li>Quickstart Guide</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/Quickstart.ipynb.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<style>
/* CSS for nbsphinx extension */
/* remove conflicting styling from Sphinx themes */
div.nbinput.container div.prompt *,
div.nboutput.container div.prompt *,
div.nbinput.container div.input_area pre,
div.nboutput.container div.output_area pre,
div.nbinput.container div.input_area .highlight,
div.nboutput.container div.output_area .highlight {
border: none;
padding: 0;
margin: 0;
box-shadow: none;
}
div.nbinput.container > div[class*=highlight],
div.nboutput.container > div[class*=highlight] {
margin: 0;
}
div.nbinput.container div.prompt *,
div.nboutput.container div.prompt * {
background: none;
}
div.nboutput.container div.output_area .highlight,
div.nboutput.container div.output_area pre {
background: unset;
}
div.nboutput.container div.output_area div.highlight {
color: unset; /* override Pygments text color */
}
/* avoid gaps between output lines */
div.nboutput.container div[class*=highlight] pre {
line-height: normal;
}
/* input/output containers */
div.nbinput.container,
div.nboutput.container {
display: -webkit-flex;
display: flex;
align-items: flex-start;
margin: 0;
width: 100%;
}
@media (max-width: 540px) {
div.nbinput.container,
div.nboutput.container {
flex-direction: column;
}
}
/* input container */
div.nbinput.container {
padding-top: 5px;
}
/* last container */
div.nblast.container {
padding-bottom: 5px;
}
/* input prompt */
div.nbinput.container div.prompt pre {
color: #307FC1;
}
/* output prompt */
div.nboutput.container div.prompt pre {
color: #BF5B3D;
}
/* all prompts */
div.nbinput.container div.prompt,
div.nboutput.container div.prompt {
width: 4.5ex;
padding-top: 5px;
position: relative;
user-select: none;
}
div.nbinput.container div.prompt > div,
div.nboutput.container div.prompt > div {
position: absolute;
right: 0;
margin-right: 0.3ex;
}
@media (max-width: 540px) {
div.nbinput.container div.prompt,
div.nboutput.container div.prompt {
width: unset;
text-align: left;
padding: 0.4em;
}
div.nboutput.container div.prompt.empty {
padding: 0;
}
div.nbinput.container div.prompt > div,
div.nboutput.container div.prompt > div {
position: unset;
}
}
/* disable scrollbars on prompts */
div.nbinput.container div.prompt pre,
div.nboutput.container div.prompt pre {
overflow: hidden;
}
/* input/output area */
div.nbinput.container div.input_area,
div.nboutput.container div.output_area {
-webkit-flex: 1;
flex: 1;
overflow: auto;
}
@media (max-width: 540px) {
div.nbinput.container div.input_area,
div.nboutput.container div.output_area {
width: 100%;
}
}
/* input area */
div.nbinput.container div.input_area {
border: 1px solid #e0e0e0;
border-radius: 2px;
/*background: #f5f5f5;*/
}
/* override MathJax center alignment in output cells */
div.nboutput.container div[class*=MathJax] {
text-align: left !important;
}
/* override sphinx.ext.imgmath center alignment in output cells */
div.nboutput.container div.math p {
text-align: left;
}
/* standard error */
div.nboutput.container div.output_area.stderr {
background: #fdd;
}
/* ANSI colors */
.ansi-black-fg { color: #3E424D; }
.ansi-black-bg { background-color: #3E424D; }
.ansi-black-intense-fg { color: #282C36; }
.ansi-black-intense-bg { background-color: #282C36; }
.ansi-red-fg { color: #E75C58; }
.ansi-red-bg { background-color: #E75C58; }
.ansi-red-intense-fg { color: #B22B31; }
.ansi-red-intense-bg { background-color: #B22B31; }
.ansi-green-fg { color: #00A250; }
.ansi-green-bg { background-color: #00A250; }
.ansi-green-intense-fg { color: #007427; }
.ansi-green-intense-bg { background-color: #007427; }
.ansi-yellow-fg { color: #DDB62B; }
.ansi-yellow-bg { background-color: #DDB62B; }
.ansi-yellow-intense-fg { color: #B27D12; }
.ansi-yellow-intense-bg { background-color: #B27D12; }
.ansi-blue-fg { color: #208FFB; }
.ansi-blue-bg { background-color: #208FFB; }
.ansi-blue-intense-fg { color: #0065CA; }
.ansi-blue-intense-bg { background-color: #0065CA; }
.ansi-magenta-fg { color: #D160C4; }
.ansi-magenta-bg { background-color: #D160C4; }
.ansi-magenta-intense-fg { color: #A03196; }
.ansi-magenta-intense-bg { background-color: #A03196; }
.ansi-cyan-fg { color: #60C6C8; }
.ansi-cyan-bg { background-color: #60C6C8; }
.ansi-cyan-intense-fg { color: #258F8F; }
.ansi-cyan-intense-bg { background-color: #258F8F; }
.ansi-white-fg { color: #C5C1B4; }
.ansi-white-bg { background-color: #C5C1B4; }
.ansi-white-intense-fg { color: #A1A6B2; }
.ansi-white-intense-bg { background-color: #A1A6B2; }
.ansi-default-inverse-fg { color: #FFFFFF; }
.ansi-default-inverse-bg { background-color: #000000; }
.ansi-bold { font-weight: bold; }
.ansi-underline { text-decoration: underline; }
div.nbinput.container div.input_area div[class*=highlight] > pre,
div.nboutput.container div.output_area div[class*=highlight] > pre,
div.nboutput.container div.output_area div[class*=highlight].math,
div.nboutput.container div.output_area.rendered_html,
div.nboutput.container div.output_area > div.output_javascript,
div.nboutput.container div.output_area:not(.rendered_html) > img{
padding: 5px;
margin: 0;
}
/* fix copybtn overflow problem in chromium (needed for 'sphinx_copybutton') */
div.nbinput.container div.input_area > div[class^='highlight'],
div.nboutput.container div.output_area > div[class^='highlight']{
overflow-y: hidden;
}
/* hide copybtn icon on prompts (needed for 'sphinx_copybutton') */
.prompt a.copybtn {
display: none;
}
/* Some additional styling taken form the Jupyter notebook CSS */
div.rendered_html table {
border: none;
border-collapse: collapse;
border-spacing: 0;
color: black;
font-size: 12px;
table-layout: fixed;
}
div.rendered_html thead {
border-bottom: 1px solid black;
vertical-align: bottom;
}
div.rendered_html tr,
div.rendered_html th,
div.rendered_html td {
text-align: right;
vertical-align: middle;
padding: 0.5em 0.5em;
line-height: normal;
white-space: normal;
max-width: none;
border: none;
}
div.rendered_html th {
font-weight: bold;
}
div.rendered_html tbody tr:nth-child(odd) {
background: #f5f5f5;
}
div.rendered_html tbody tr:hover {
background: rgba(66, 165, 245, 0.2);
}
/* CSS overrides for sphinx_rtd_theme */
/* 24px margin */
.nbinput.nblast.container,
.nboutput.nblast.container {
margin-bottom: 19px; /* padding has already 5px */
}
/* ... except between code cells! */
.nblast.container + .nbinput.container {
margin-top: -19px;
}
.admonition > p:before {
margin-right: 4px; /* make room for the exclamation icon */
}
/* Fix math alignment, see https://github.com/rtfd/sphinx_rtd_theme/pull/686 */
.math {
text-align: unset;
}
</style>
<div class="section" id="Quickstart-Guide">
<h1>Quickstart Guide<a class="headerlink" href="#Quickstart-Guide" title="Permalink to this headline">¶</a></h1>
<p><strong>If you are new to MatrixProfile concepts, please read the following article before continuing:</strong> <a class="reference external" href="https://towardsdatascience.com/introduction-to-matrix-profiles-5568f3375d90">Introduction To Matrix Profiles</a></p>
<p>MatrixProfile enables you to quickly and easily analyze a time series. At it’s core, the module is made of 4 primary concepts.</p>
<p><strong>1.</strong><a class="reference internal" href="api.html#matrixprofile.analyze"><span class="std std-ref">Analyze</span></a></p>
<p>Analyze is a “pipeline” that lets you quickly compute the MatrixProfile or Pan-MatrixProfile, discover motifs, discover discords and visualize the results.</p>
<p><strong>2.</strong><a class="reference internal" href="api.html#matrixprofile.compute"><span class="std std-ref">Compute</span></a></p>
<p>Compute simply computes the MatrixProfile or Pan-MatrixProfile.</p>
<p><strong>3.</strong><a class="reference internal" href="api.html#matrixprofile.discover.motifs"><span class="std std-ref">Discover</span></a></p>
<p>Discover is a module composed of algorithms that are used on top of a computed MatrixProfile or Pan-MatrixProfile. For example, you cannot find any discords or motifs without first computing the MatrixProfile or Pan-MatrixProfile.</p>
<p><strong>4.</strong><a class="reference internal" href="api.html#matrixprofile.visualize"><span class="std std-ref">Visualize</span></a></p>
<p>Visualize provides some out of the box plots. Currently, plots for the MatrixProfile, Pan-MatrixProfile, Motifs and Discords is supported.</p>
<p>In this quickstart guide, you will learn how to apply these concepts and start analyzing your time series data. We also cover the core data structures generated from the “compute” algorithms. These data structures are critical in order for the other higher level functions to work (discover and visualize).</p>
<div class="section" id="Import-Modules">
<h2>Import Modules<a class="headerlink" href="#Import-Modules" title="Permalink to this headline">¶</a></h2>
<p>By convention, we import the MatrixProfile library as <strong>mp</strong>; similar to importing numpy as <strong>np</strong>. Here we simply import matrixprofile, import numpy and load a synthetic time series. We also import matplotlib to visualize the data.</p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[1]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">matplotlib</span> <span class="kn">import</span> <span class="n">pyplot</span> <span class="k">as</span> <span class="n">plt</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">matrixprofile</span> <span class="k">as</span> <span class="nn">mp</span>
<span class="o">%</span><span class="k">matplotlib</span> inline
</pre></div>
</div>
</div>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[2]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">dataset</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">datasets</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="s1">'motifs-discords-small'</span><span class="p">)</span>
<span class="n">ts</span> <span class="o">=</span> <span class="n">dataset</span><span class="p">[</span><span class="s1">'data'</span><span class="p">]</span>
</pre></div>
</div>
</div>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[3]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span><span class="mi">5</span><span class="p">))</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">ts</span><span class="p">)),</span> <span class="n">ts</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s1">'Synthetic Time Series'</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="_images/Quickstart_4_0.png" src="_images/Quickstart_4_0.png" />
</div>
</div>
</div>
<div class="section" id="Analyzing-Pan-MatrixProfile">
<h2>Analyzing Pan-MatrixProfile<a class="headerlink" href="#Analyzing-Pan-MatrixProfile" title="Permalink to this headline">¶</a></h2>
<p>In this section, we illustrate how to use the analyze function to compute the Pan-MatrixProfile, discover the motifs, discover the discords and to visualize this information. When a time series is passed to the analyze function without any windows, the <strong>maximum_subsequence</strong> algorithm is used to determine what makes sense. It uses <strong>Pearson Correlation</strong> to determine when the upper window is found based on a default threshold of <strong>0.98</strong>. This is the quickest way to obtain interesting insights
into your time series.</p>
<p>This example only illustrates passing in no windows, however you should spend time reading the <a class="reference internal" href="api.html#matrixprofile.analyze"><span class="std std-ref">analyze API docs</span></a> for details on arguments.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[4]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">profile</span><span class="p">,</span> <span class="n">figures</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">analyze</span><span class="p">(</span><span class="n">ts</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area stderr docutils container">
<div class="highlight"><pre>
/home/tyler/src/matrixprofile/matrixprofile/visualize.py:318: UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
fig.tight_layout()
</pre></div></div>
</div>
<div class="nboutput docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="_images/Quickstart_6_1.png" src="_images/Quickstart_6_1.png" />
</div>
</div>
<div class="nboutput docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="_images/Quickstart_6_2.png" src="_images/Quickstart_6_2.png" />
</div>
</div>
<div class="nboutput docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="_images/Quickstart_6_3.png" src="_images/Quickstart_6_3.png" />
</div>
</div>
<div class="nboutput docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="_images/Quickstart_6_4.png" src="_images/Quickstart_6_4.png" />
</div>
</div>
<div class="nboutput docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="_images/Quickstart_6_5.png" src="_images/Quickstart_6_5.png" />
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="_images/Quickstart_6_6.png" src="_images/Quickstart_6_6.png" />
</div>
</div>
<p>A lot of useful plots are shown about the time series. The first plot shows all of the computed matrix profiles over the given window sizes. We can see that there are motifs where the shapes are similar. For example, at window sizes 200 and 32. The other plots show the top 3 discords and motifs across all of the computed MatrixProfiles.</p>
</div>
<div class="section" id="Pan-MatrixProfile-Data-Structure">
<h2>Pan-MatrixProfile Data Structure<a class="headerlink" href="#Pan-MatrixProfile-Data-Structure" title="Permalink to this headline">¶</a></h2>
<p>The Pan-MatrixProfile is a Python dictionary with critical keys. These keys and values are expected to exist when using the visualize and discover functions.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
<span class="c1"># The computed matrix profiles as a 2D numpy array row-wise aligned with the</span>
<span class="c1"># windows array.</span>
<span class="s1">'pmp'</span><span class="p">:</span> <span class="n">pmp</span><span class="p">,</span>
<span class="c1"># The matrix profile index as a 2D numpy array row-wise aligned with the</span>
<span class="c1"># windows array.</span>
<span class="s1">'pmpi'</span><span class="p">:</span> <span class="n">pmpi</span><span class="p">,</span>
<span class="c1"># The original data passed in.</span>
<span class="s1">'data'</span><span class="p">:</span> <span class="p">{</span>
<span class="s1">'ts'</span><span class="p">:</span> <span class="n">ts</span><span class="p">,</span>
<span class="p">},</span>
<span class="c1"># The windows used to compute the matrix profiles.</span>
<span class="s1">'windows'</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">windows</span><span class="p">),</span>
<span class="c1"># The samples computed as a float from 0 to 1 of the windows.</span>
<span class="s1">'sample_pct'</span><span class="p">:</span> <span class="n">sample_pct</span><span class="p">,</span>
<span class="c1"># Euclidean or Pearson</span>
<span class="s1">'metric'</span><span class="p">:</span> <span class="n">metric</span><span class="p">,</span>
<span class="c1"># The internal algorithm used to compute the pan-matrixprofile.</span>
<span class="s1">'algorithm'</span><span class="p">:</span> <span class="s1">'skimp'</span><span class="p">,</span>
<span class="c1"># The type of data structure. A matrixprofile is MatrixProfile.</span>
<span class="s1">'class'</span><span class="p">:</span> <span class="s1">'PMP'</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="Picking-a-MatrixProfile-From-Pan-MatrixProfile">
<h2>Picking a MatrixProfile From Pan-MatrixProfile<a class="headerlink" href="#Picking-a-MatrixProfile-From-Pan-MatrixProfile" title="Permalink to this headline">¶</a></h2>
<p>You may find a specific MatrixProfile that you would like to examine further. You can easily extract a MatrixProfile from a Pan-MatrixProfile using the <a class="reference internal" href="api.html#matrixprofile.utils.pick_mp"><span class="std std-ref">mp.utils.pick_mp</span></a> function.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[5]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">mp_profile</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">utils</span><span class="o">.</span><span class="n">pick_mp</span><span class="p">(</span><span class="n">profile</span><span class="p">,</span> <span class="mi">32</span><span class="p">)</span>
<span class="n">mp_figures</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">visualize</span><span class="p">(</span><span class="n">mp_profile</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="_images/Quickstart_10_0.png" src="_images/Quickstart_10_0.png" />
</div>
</div>
</div>
<div class="section" id="Analyzing-MatrixProfile">
<h2>Analyzing MatrixProfile<a class="headerlink" href="#Analyzing-MatrixProfile" title="Permalink to this headline">¶</a></h2>
<p>Similar to analyzing a Pan-MatrixProfile, the analyze function enables you to review a MatrixProfile. The only difference here is that we pass in a single window and obtain results for the given MatrixProfile.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[6]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">mp_profile</span><span class="p">,</span> <span class="n">mp_figures</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">analyze</span><span class="p">(</span><span class="n">ts</span><span class="p">,</span> <span class="n">windows</span><span class="o">=</span><span class="mi">32</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area stderr docutils container">
<div class="highlight"><pre>
/home/tyler/src/matrixprofile/matrixprofile/visualize.py:262: UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
fig.tight_layout()
</pre></div></div>
</div>
<div class="nboutput docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="_images/Quickstart_12_1.png" src="_images/Quickstart_12_1.png" />
</div>
</div>
<div class="nboutput docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="_images/Quickstart_12_2.png" src="_images/Quickstart_12_2.png" />
</div>
</div>
<div class="nboutput docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="_images/Quickstart_12_3.png" src="_images/Quickstart_12_3.png" />
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="_images/Quickstart_12_4.png" src="_images/Quickstart_12_4.png" />
</div>
</div>
</div>
<div class="section" id="MatrixProfile-Data-Structure">
<h2>MatrixProfile Data Structure<a class="headerlink" href="#MatrixProfile-Data-Structure" title="Permalink to this headline">¶</a></h2>
<p>The MatrixProfile data structure is a Python dictionary with critical keys and values. The values must exist for discover and visualize functions to work properly.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
<span class="c1"># A numpy array of the matrix profile.</span>
<span class="s1">'mp'</span><span class="p">:</span> <span class="n">The</span> <span class="n">matrix</span> <span class="n">profile</span><span class="p">,</span>
<span class="c1"># The profile index as a numpy array.</span>
<span class="s1">'pi'</span><span class="p">:</span> <span class="n">The</span> <span class="n">matrix</span> <span class="n">profile</span> <span class="mi">1</span><span class="n">NN</span> <span class="n">indices</span><span class="p">,</span>
<span class="c1"># The right matrix profile as a numpy array.</span>
<span class="s1">'rmp'</span><span class="p">:</span> <span class="n">The</span> <span class="n">right</span> <span class="n">matrix</span> <span class="n">profile</span><span class="p">,</span>
<span class="c1"># The right matrix profile indices as a numpy array.</span>
<span class="s1">'rpi'</span><span class="p">:</span> <span class="n">The</span> <span class="n">right</span> <span class="n">matrix</span> <span class="n">profile</span> <span class="mi">1</span><span class="n">NN</span> <span class="n">indices</span><span class="p">,</span>
<span class="c1"># The left matrix profile as a numpy array.</span>
<span class="s1">'lmp'</span><span class="p">:</span> <span class="n">The</span> <span class="n">left</span> <span class="n">matrix</span> <span class="n">profile</span><span class="p">,</span>
<span class="c1"># The left matrix profile indices as a numpy array.</span>
<span class="s1">'lpi'</span><span class="p">:</span> <span class="n">The</span> <span class="n">left</span> <span class="n">matrix</span> <span class="n">profile</span> <span class="mi">1</span><span class="n">NN</span> <span class="n">indices</span><span class="p">,</span>
<span class="c1"># The distance metric in the matrix profile (Euclidean or Pearson).</span>
<span class="s1">'metric'</span><span class="p">:</span> <span class="n">The</span> <span class="n">distance</span> <span class="n">metric</span> <span class="n">computed</span> <span class="k">for</span> <span class="n">the</span> <span class="n">mp</span><span class="p">,</span>
<span class="c1"># The window size used.</span>
<span class="s1">'w'</span><span class="p">:</span> <span class="n">The</span> <span class="n">window</span> <span class="n">size</span> <span class="n">used</span> <span class="n">to</span> <span class="n">compute</span> <span class="n">the</span> <span class="n">matrix</span> <span class="n">profile</span><span class="p">,</span>
<span class="c1"># The exclusion zone for non-trivial matches.</span>
<span class="s1">'ez'</span><span class="p">:</span> <span class="n">The</span> <span class="n">exclusion</span> <span class="n">zone</span> <span class="n">used</span><span class="p">,</span>
<span class="c1"># A flag specifying if a self-join or similarity join was computed.</span>
<span class="s1">'join'</span><span class="p">:</span> <span class="n">Flag</span> <span class="n">indicating</span> <span class="k">if</span> <span class="n">a</span> <span class="n">similarity</span> <span class="n">join</span> <span class="n">was</span> <span class="n">computed</span><span class="p">,</span>
<span class="c1"># A float from 0 to 1 indicating how many samples were taken to compute the MP.</span>
<span class="s1">'sample_pct'</span><span class="p">:</span> <span class="n">Percentage</span> <span class="n">of</span> <span class="n">samples</span> <span class="n">used</span> <span class="ow">in</span> <span class="n">computing</span> <span class="n">the</span> <span class="n">MP</span><span class="p">,</span>
<span class="c1"># The original data where ts is the time series and query is the query.</span>
<span class="s1">'data'</span><span class="p">:</span> <span class="p">{</span>
<span class="s1">'ts'</span><span class="p">:</span> <span class="n">Time</span> <span class="n">series</span> <span class="n">data</span><span class="p">,</span>
<span class="s1">'query'</span><span class="p">:</span> <span class="n">Query</span> <span class="n">data</span> <span class="k">if</span> <span class="n">supplied</span>
<span class="p">}</span>
<span class="c1"># This is used internally to determine what this data structure is.</span>
<span class="s1">'class'</span><span class="p">:</span> <span class="s2">"MatrixProfile"</span>
<span class="c1"># The algorithm used to compute this matrix profile.</span>
<span class="s1">'algorithm'</span><span class="p">:</span> <span class="s2">"stomp"</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="Computing-MatrixProfile-and-Pan-MatrixProfile">
<h2>Computing MatrixProfile and Pan-MatrixProfile<a class="headerlink" href="#Computing-MatrixProfile-and-Pan-MatrixProfile" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference internal" href="api.html#matrixprofile.compute"><span class="std std-ref">mp.compute</span></a> function works identically to the analyze function. The exception is that plots are not provided. To keep this section brief, I will only show a short example for both.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># compute the Pan-MatrixProfile no windows</span>
<span class="n">profile</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">compute</span><span class="p">(</span><span class="n">ts</span><span class="p">)</span>
<span class="c1"># compute the Pan-MatrixProfile with windows</span>
<span class="n">profile</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">compute</span><span class="p">(</span><span class="n">ts</span><span class="p">,</span> <span class="n">windows</span><span class="o">=</span><span class="p">[</span><span class="mi">32</span><span class="p">,</span> <span class="mi">64</span><span class="p">,</span> <span class="mi">128</span><span class="p">])</span>
<span class="c1"># compute the MatrixProfile</span>
<span class="n">profile</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">compute</span><span class="p">(</span><span class="n">ts</span><span class="p">,</span> <span class="n">windows</span><span class="o">=</span><span class="p">[</span><span class="mi">32</span><span class="p">])</span>
<span class="c1"># specify all cpu cores</span>
<span class="n">profile</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">compute</span><span class="p">(</span><span class="n">ts</span><span class="p">,</span> <span class="n">windows</span><span class="o">=</span><span class="p">[</span><span class="mi">32</span><span class="p">],</span> <span class="n">n_jobs</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="Discover-Motifs-and-Discords">
<h2>Discover Motifs and Discords<a class="headerlink" href="#Discover-Motifs-and-Discords" title="Permalink to this headline">¶</a></h2>
<p>Both the Pan-MatrixProfile and MatrixProfile data structures enable motif and discord discovery. A quick example follows, but please read the API docs to understand the parameters that may be tuned. Note that the functions understand which method to use based on the data structure. Calling the motifs and discords function is the same for Pan-MatrixProfile and MatrixProfile. These algorithms return the same “profile data structure” with an additional key of “motifs” or “discords”.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">profile</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">discover</span><span class="o">.</span><span class="n">motifs</span><span class="p">(</span><span class="n">profile</span><span class="p">)</span>
<span class="n">profile</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">discover</span><span class="o">.</span><span class="n">discords</span><span class="p">(</span><span class="n">profile</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="Visualize">
<h2>Visualize<a class="headerlink" href="#Visualize" title="Permalink to this headline">¶</a></h2>
<p>Visualize is a high level function that when given a “profile data structure”, it will provide plots accordingly. For example, when you only have the profile and not discords or motifs, it only plots the profile. A list of Matplotlib figures is returned to you so that you can save them if you wish.</p>
<p>Here is an example of visualizing a profile and saving figures to a file.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">figures</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">visualize</span><span class="p">(</span><span class="n">profile</span><span class="p">)</span>
<span class="k">for</span> <span class="n">count</span><span class="p">,</span> <span class="n">figure</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">figures</span><span class="p">):</span>
<span class="n">figure</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1">.png'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">count</span><span class="p">))</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="api.html" class="btn btn-neutral float-right" title="API" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="installation/Mac_OS_Installation.html" class="btn btn-neutral float-left" title="Mac OS Installation" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2020, Matrix Profile Foundation
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>