GMM-HMM
continuous observation 에 대해서 단일 Gaussian 이 아닌 Gaussian Mixture Model 로 모델링을 하면 복잡한 분포를 모델링하여 더욱 성능을 높일 수 있다.
이번에는 그 방법에 대해서 알아보자.
In [1]:
1
2
3
4
5
6
import numpy as np
import matplotlib.pyplot as plt
from hmmlearn.hmm import GMMHMM
np.set_printoptions(precision=3, suppress=True)
Define Model
In [2]:
1
2
3
4
5
6
model = GMMHMM(n_components=2, n_mix=2, covariance_type="diag")
model.startprob_ = np.array([0.9, 0.1])
model.transmat_ = np.array([[0.95, 0.05], [0.15, 0.85]])
model.means_ = np.array([[[5.0], [10.0]], [[-10.], [-5.]]])
model.covars_ = np.array([[[9.0], [4.0]], [[4.0], [9.0]]])
model.weights_ = np.array([[0.6, 0.4], [0.4, 0.6]])
Generate Samples
In [3]:
1
2
3
4
5
def get_random_lengths(N, K):
Y = np.sort(np.random.choice(np.arange(1, N-1), K-1, replace=False))
Y = np.concatenate([[0],Y,[N]])
ans = Y[1:] - Y[:-1]
return ans
In [4]:
1
2
3
N, K = 1000, 50
X, Z = model.sample(N)
L = get_random_lengths(N, K)
Visualize Distribution of Samples
In [5]:
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
count, bins_count = np.histogram(X, bins=15)
pdf = count / sum(count)
# using numpy np.cumsum to calculate the CDF
# We can also find using the PDF values by looping and adding
cdf = np.cumsum(pdf)
# plotting PDF and CDF
plt.plot(bins_count[1:], pdf, color="y", label="PDF")
plt.plot(bins_count[1:], cdf, color="g", label="CDF")
plt.vlines(x=5, ymin=0, ymax=1.0, color='cyan', ls='--')
plt.vlines(x=10, ymin=0, ymax=1.0, color='cyan', ls='--')
plt.vlines(x=-10, ymin=0, ymax=1.0, color='magenta', ls='--')
plt.vlines(x=-5, ymin=0, ymax=1.0, color='magenta', ls='--')
mask = Z == 0
count, bins_count = np.histogram(X[mask], bins=15)
pdf = count / sum(count)
plt.plot(bins_count[1:], pdf, color="b", label="PDF1")
count, bins_count = np.histogram(X[~mask], bins=15)
pdf = count / sum(count)
plt.plot(bins_count[1:], pdf, color="r", label="PDF2")
plt.scatter(X[mask], Z[mask], color='cyan')
plt.scatter(X[~mask], Z[~mask], color='magenta')
plt.legend()
1
<matplotlib.legend.Legend at 0x7f1b3d23dad0>
In [6]:
1
2
3
4
5
6
X_cumsum = X.cumsum()
X_cumsum_hat = X_cumsum.copy()
X_cumsum_hat[mask] = np.nan
plt.plot(X_cumsum, lw=5)
plt.plot(X_cumsum_hat, 'r-', lw=5)
plt.title("X cumulated")
1
Text(0.5, 1.0, 'X cumulated')
Train Model
In [7]:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
trained_model = GMMHMM(n_components=2, n_mix=2, covariance_type="diag", n_iter=len(X), verbose=True, tol=1e-10)
print("initial model parameters:\n"
f'startprob : {trained_model.startprob_prior}\n'
f'transmat_: {trained_model.transmat_prior}\n'
f'means: {trained_model.means_prior}\n'
f'covars: {trained_model.covars_prior}\n'
f'weights: {trained_model.weights_prior}\n')
trained_model.fit(X, L)
print("GT model parameters:\n"
f'startprob : {model.startprob_}\n'
f'transmat_: {model.transmat_}\n'
f'means: {model.means_}\n'
f'covars: {model.covars_}\n'
f'weights: {model.weights_}\n')
print("final model parameters:\n"
f'startprob : {trained_model.startprob_}\n'
f'transmat_: {trained_model.transmat_}\n'
f'means: {trained_model.means_}\n'
f'covars: {trained_model.covars_}\n'
f'weights: {trained_model.weights_}\n')
1
2
3
4
5
6
7
8
initial model parameters:
startprob : 1.0
transmat_: 1.0
means: 0.0
covars: None
weights: 1.0
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
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
1 -3504.9896 +nan
2 -3231.4905 +273.4991
3 -3087.2951 +144.1954
4 -3001.7934 +85.5017
5 -2972.2649 +29.5285
6 -2962.5591 +9.7058
7 -2959.7933 +2.7658
8 -2959.0166 +0.7767
9 -2958.6978 +0.3188
10 -2958.4769 +0.2209
11 -2958.2714 +0.2055
12 -2958.0593 +0.2121
13 -2957.8333 +0.2260
14 -2957.5904 +0.2429
15 -2957.3288 +0.2616
16 -2957.0474 +0.2814
17 -2956.7452 +0.3022
18 -2956.4216 +0.3236
19 -2956.0766 +0.3451
20 -2955.7107 +0.3658
21 -2955.3259 +0.3848
22 -2954.9255 +0.4004
23 -2954.5146 +0.4109
24 -2954.1004 +0.4143
25 -2953.6915 +0.4089
26 -2953.2978 +0.3938
27 -2952.9285 +0.3693
28 -2952.5912 +0.3373
29 -2952.2900 +0.3012
30 -2952.0251 +0.2649
31 -2951.7926 +0.2324
32 -2951.5861 +0.2065
33 -2951.3976 +0.1886
34 -2951.2188 +0.1788
35 -2951.0425 +0.1763
36 -2950.8624 +0.1800
37 -2950.6735 +0.1889
38 -2950.4716 +0.2019
39 -2950.2531 +0.2185
40 -2950.0150 +0.2381
41 -2949.7545 +0.2605
42 -2949.4692 +0.2852
43 -2949.1572 +0.3121
44 -2948.8167 +0.3404
45 -2948.4473 +0.3695
46 -2948.0491 +0.3982
47 -2947.6241 +0.4250
48 -2947.1761 +0.4480
49 -2946.7112 +0.4649
50 -2946.2377 +0.4735
51 -2945.7662 +0.4716
52 -2945.3084 +0.4577
53 -2944.8767 +0.4317
54 -2944.4822 +0.3945
55 -2944.1336 +0.3487
56 -2943.8359 +0.2977
57 -2943.5903 +0.2456
58 -2943.3943 +0.1960
59 -2943.2427 +0.1516
60 -2943.1286 +0.1141
61 -2943.0448 +0.0838
62 -2942.9844 +0.0604
63 -2942.9414 +0.0430
64 -2942.9110 +0.0304
65 -2942.8896 +0.0215
66 -2942.8742 +0.0154
67 -2942.8630 +0.0112
68 -2942.8546 +0.0084
69 -2942.8481 +0.0065
70 -2942.8428 +0.0053
71 -2942.8384 +0.0045
72 -2942.8345 +0.0039
73 -2942.8309 +0.0035
74 -2942.8276 +0.0033
75 -2942.8245 +0.0031
76 -2942.8216 +0.0030
77 -2942.8187 +0.0029
78 -2942.8159 +0.0028
79 -2942.8132 +0.0027
80 -2942.8106 +0.0026
81 -2942.8080 +0.0026
82 -2942.8055 +0.0025
83 -2942.8030 +0.0025
84 -2942.8005 +0.0024
85 -2942.7981 +0.0024
86 -2942.7958 +0.0024
87 -2942.7934 +0.0023
88 -2942.7912 +0.0023
89 -2942.7889 +0.0022
90 -2942.7867 +0.0022
91 -2942.7846 +0.0022
92 -2942.7825 +0.0021
93 -2942.7804 +0.0021
94 -2942.7784 +0.0020
95 -2942.7763 +0.0020
96 -2942.7744 +0.0020
97 -2942.7724 +0.0019
98 -2942.7705 +0.0019
99 -2942.7687 +0.0019
100 -2942.7668 +0.0018
101 -2942.7650 +0.0018
102 -2942.7633 +0.0018
103 -2942.7615 +0.0017
104 -2942.7598 +0.0017
105 -2942.7581 +0.0017
106 -2942.7565 +0.0017
107 -2942.7548 +0.0016
108 -2942.7532 +0.0016
109 -2942.7517 +0.0016
110 -2942.7501 +0.0015
111 -2942.7486 +0.0015
112 -2942.7471 +0.0015
113 -2942.7457 +0.0015
114 -2942.7442 +0.0014
115 -2942.7428 +0.0014
116 -2942.7414 +0.0014
117 -2942.7400 +0.0014
118 -2942.7387 +0.0013
119 -2942.7374 +0.0013
120 -2942.7361 +0.0013
121 -2942.7348 +0.0013
122 -2942.7335 +0.0013
123 -2942.7323 +0.0012
124 -2942.7311 +0.0012
125 -2942.7299 +0.0012
126 -2942.7287 +0.0012
127 -2942.7276 +0.0012
128 -2942.7264 +0.0011
129 -2942.7253 +0.0011
130 -2942.7242 +0.0011
131 -2942.7231 +0.0011
132 -2942.7221 +0.0011
133 -2942.7210 +0.0010
134 -2942.7200 +0.0010
135 -2942.7190 +0.0010
136 -2942.7180 +0.0010
137 -2942.7170 +0.0010
138 -2942.7160 +0.0010
139 -2942.7151 +0.0009
140 -2942.7142 +0.0009
141 -2942.7132 +0.0009
142 -2942.7123 +0.0009
143 -2942.7114 +0.0009
144 -2942.7106 +0.0009
145 -2942.7097 +0.0009
146 -2942.7089 +0.0008
147 -2942.7080 +0.0008
148 -2942.7072 +0.0008
149 -2942.7064 +0.0008
150 -2942.7056 +0.0008
151 -2942.7048 +0.0008
152 -2942.7040 +0.0008
153 -2942.7033 +0.0008
154 -2942.7025 +0.0008
155 -2942.7018 +0.0007
156 -2942.7010 +0.0007
157 -2942.7003 +0.0007
158 -2942.6996 +0.0007
159 -2942.6989 +0.0007
160 -2942.6982 +0.0007
161 -2942.6976 +0.0007
162 -2942.6969 +0.0007
163 -2942.6962 +0.0007
164 -2942.6956 +0.0006
165 -2942.6949 +0.0006
166 -2942.6943 +0.0006
167 -2942.6937 +0.0006
168 -2942.6931 +0.0006
169 -2942.6925 +0.0006
170 -2942.6919 +0.0006
171 -2942.6913 +0.0006
172 -2942.6907 +0.0006
173 -2942.6901 +0.0006
174 -2942.6896 +0.0006
175 -2942.6890 +0.0006
176 -2942.6885 +0.0005
177 -2942.6879 +0.0005
178 -2942.6874 +0.0005
179 -2942.6869 +0.0005
180 -2942.6864 +0.0005
181 -2942.6859 +0.0005
182 -2942.6854 +0.0005
183 -2942.6849 +0.0005
184 -2942.6844 +0.0005
185 -2942.6839 +0.0005
186 -2942.6834 +0.0005
187 -2942.6829 +0.0005
188 -2942.6825 +0.0005
189 -2942.6820 +0.0005
190 -2942.6815 +0.0005
191 -2942.6811 +0.0004
192 -2942.6807 +0.0004
193 -2942.6802 +0.0004
194 -2942.6798 +0.0004
195 -2942.6794 +0.0004
196 -2942.6789 +0.0004
197 -2942.6785 +0.0004
198 -2942.6781 +0.0004
199 -2942.6777 +0.0004
200 -2942.6773 +0.0004
201 -2942.6769 +0.0004
202 -2942.6765 +0.0004
203 -2942.6761 +0.0004
204 -2942.6757 +0.0004
205 -2942.6754 +0.0004
206 -2942.6750 +0.0004
207 -2942.6746 +0.0004
208 -2942.6742 +0.0004
209 -2942.6739 +0.0004
210 -2942.6735 +0.0004
211 -2942.6732 +0.0004
212 -2942.6728 +0.0004
213 -2942.6725 +0.0003
214 -2942.6721 +0.0003
215 -2942.6718 +0.0003
216 -2942.6714 +0.0003
217 -2942.6711 +0.0003
218 -2942.6708 +0.0003
219 -2942.6705 +0.0003
220 -2942.6701 +0.0003
221 -2942.6698 +0.0003
222 -2942.6695 +0.0003
223 -2942.6692 +0.0003
224 -2942.6689 +0.0003
225 -2942.6686 +0.0003
226 -2942.6683 +0.0003
227 -2942.6680 +0.0003
228 -2942.6677 +0.0003
229 -2942.6674 +0.0003
230 -2942.6671 +0.0003
231 -2942.6668 +0.0003
232 -2942.6665 +0.0003
233 -2942.6662 +0.0003
234 -2942.6659 +0.0003
235 -2942.6657 +0.0003
236 -2942.6654 +0.0003
237 -2942.6651 +0.0003
238 -2942.6648 +0.0003
239 -2942.6646 +0.0003
240 -2942.6643 +0.0003
241 -2942.6640 +0.0003
242 -2942.6638 +0.0003
243 -2942.6635 +0.0003
244 -2942.6632 +0.0003
245 -2942.6630 +0.0003
246 -2942.6627 +0.0003
247 -2942.6625 +0.0003
248 -2942.6622 +0.0002
249 -2942.6620 +0.0002
250 -2942.6617 +0.0002
251 -2942.6615 +0.0002
252 -2942.6613 +0.0002
253 -2942.6610 +0.0002
254 -2942.6608 +0.0002
255 -2942.6605 +0.0002
256 -2942.6603 +0.0002
257 -2942.6601 +0.0002
258 -2942.6598 +0.0002
259 -2942.6596 +0.0002
260 -2942.6594 +0.0002
261 -2942.6592 +0.0002
262 -2942.6589 +0.0002
263 -2942.6587 +0.0002
264 -2942.6585 +0.0002
265 -2942.6583 +0.0002
266 -2942.6581 +0.0002
267 -2942.6578 +0.0002
268 -2942.6576 +0.0002
269 -2942.6574 +0.0002
270 -2942.6572 +0.0002
271 -2942.6570 +0.0002
272 -2942.6568 +0.0002
273 -2942.6566 +0.0002
274 -2942.6564 +0.0002
275 -2942.6562 +0.0002
276 -2942.6560 +0.0002
277 -2942.6558 +0.0002
278 -2942.6556 +0.0002
279 -2942.6554 +0.0002
280 -2942.6552 +0.0002
281 -2942.6550 +0.0002
282 -2942.6548 +0.0002
283 -2942.6546 +0.0002
284 -2942.6544 +0.0002
285 -2942.6542 +0.0002
286 -2942.6540 +0.0002
287 -2942.6538 +0.0002
288 -2942.6536 +0.0002
289 -2942.6534 +0.0002
290 -2942.6533 +0.0002
291 -2942.6531 +0.0002
292 -2942.6529 +0.0002
293 -2942.6527 +0.0002
294 -2942.6525 +0.0002
295 -2942.6523 +0.0002
296 -2942.6522 +0.0002
297 -2942.6520 +0.0002
298 -2942.6518 +0.0002
299 -2942.6516 +0.0002
300 -2942.6514 +0.0002
301 -2942.6513 +0.0002
302 -2942.6511 +0.0002
303 -2942.6509 +0.0002
304 -2942.6507 +0.0002
305 -2942.6506 +0.0002
306 -2942.6504 +0.0002
307 -2942.6502 +0.0002
308 -2942.6501 +0.0002
309 -2942.6499 +0.0002
310 -2942.6497 +0.0002
311 -2942.6496 +0.0002
312 -2942.6494 +0.0002
313 -2942.6492 +0.0002
314 -2942.6491 +0.0002
315 -2942.6489 +0.0002
316 -2942.6487 +0.0002
317 -2942.6486 +0.0002
318 -2942.6484 +0.0002
319 -2942.6483 +0.0002
320 -2942.6481 +0.0002
321 -2942.6479 +0.0002
322 -2942.6478 +0.0002
323 -2942.6476 +0.0002
324 -2942.6475 +0.0002
325 -2942.6473 +0.0002
326 -2942.6472 +0.0002
327 -2942.6470 +0.0002
328 -2942.6469 +0.0002
329 -2942.6467 +0.0002
330 -2942.6466 +0.0002
331 -2942.6464 +0.0002
332 -2942.6463 +0.0002
333 -2942.6461 +0.0001
334 -2942.6460 +0.0001
335 -2942.6458 +0.0001
336 -2942.6457 +0.0001
337 -2942.6455 +0.0001
338 -2942.6454 +0.0001
339 -2942.6452 +0.0001
340 -2942.6451 +0.0001
341 -2942.6449 +0.0001
342 -2942.6448 +0.0001
343 -2942.6446 +0.0001
344 -2942.6445 +0.0001
345 -2942.6444 +0.0001
346 -2942.6442 +0.0001
347 -2942.6441 +0.0001
348 -2942.6439 +0.0001
349 -2942.6438 +0.0001
350 -2942.6437 +0.0001
351 -2942.6435 +0.0001
352 -2942.6434 +0.0001
353 -2942.6432 +0.0001
354 -2942.6431 +0.0001
355 -2942.6430 +0.0001
356 -2942.6428 +0.0001
357 -2942.6427 +0.0001
358 -2942.6426 +0.0001
359 -2942.6424 +0.0001
360 -2942.6423 +0.0001
361 -2942.6422 +0.0001
362 -2942.6420 +0.0001
363 -2942.6419 +0.0001
364 -2942.6418 +0.0001
365 -2942.6416 +0.0001
366 -2942.6415 +0.0001
367 -2942.6414 +0.0001
368 -2942.6412 +0.0001
369 -2942.6411 +0.0001
370 -2942.6410 +0.0001
371 -2942.6409 +0.0001
372 -2942.6407 +0.0001
373 -2942.6406 +0.0001
374 -2942.6405 +0.0001
375 -2942.6403 +0.0001
376 -2942.6402 +0.0001
377 -2942.6401 +0.0001
378 -2942.6400 +0.0001
379 -2942.6399 +0.0001
380 -2942.6397 +0.0001
381 -2942.6396 +0.0001
382 -2942.6395 +0.0001
383 -2942.6394 +0.0001
384 -2942.6392 +0.0001
385 -2942.6391 +0.0001
386 -2942.6390 +0.0001
387 -2942.6389 +0.0001
388 -2942.6388 +0.0001
389 -2942.6386 +0.0001
390 -2942.6385 +0.0001
391 -2942.6384 +0.0001
392 -2942.6383 +0.0001
393 -2942.6382 +0.0001
394 -2942.6381 +0.0001
395 -2942.6379 +0.0001
396 -2942.6378 +0.0001
397 -2942.6377 +0.0001
398 -2942.6376 +0.0001
399 -2942.6375 +0.0001
400 -2942.6374 +0.0001
401 -2942.6372 +0.0001
402 -2942.6371 +0.0001
403 -2942.6370 +0.0001
404 -2942.6369 +0.0001
405 -2942.6368 +0.0001
406 -2942.6367 +0.0001
407 -2942.6366 +0.0001
408 -2942.6365 +0.0001
409 -2942.6364 +0.0001
410 -2942.6362 +0.0001
411 -2942.6361 +0.0001
412 -2942.6360 +0.0001
413 -2942.6359 +0.0001
414 -2942.6358 +0.0001
415 -2942.6357 +0.0001
416 -2942.6356 +0.0001
417 -2942.6355 +0.0001
418 -2942.6354 +0.0001
419 -2942.6353 +0.0001
420 -2942.6352 +0.0001
421 -2942.6351 +0.0001
422 -2942.6350 +0.0001
423 -2942.6349 +0.0001
424 -2942.6348 +0.0001
425 -2942.6347 +0.0001
426 -2942.6345 +0.0001
427 -2942.6344 +0.0001
428 -2942.6343 +0.0001
429 -2942.6342 +0.0001
430 -2942.6341 +0.0001
431 -2942.6340 +0.0001
432 -2942.6339 +0.0001
433 -2942.6338 +0.0001
434 -2942.6337 +0.0001
435 -2942.6336 +0.0001
436 -2942.6335 +0.0001
437 -2942.6334 +0.0001
438 -2942.6333 +0.0001
439 -2942.6332 +0.0001
440 -2942.6331 +0.0001
441 -2942.6330 +0.0001
442 -2942.6330 +0.0001
443 -2942.6329 +0.0001
444 -2942.6328 +0.0001
445 -2942.6327 +0.0001
446 -2942.6326 +0.0001
447 -2942.6325 +0.0001
448 -2942.6324 +0.0001
449 -2942.6323 +0.0001
450 -2942.6322 +0.0001
451 -2942.6321 +0.0001
452 -2942.6320 +0.0001
453 -2942.6319 +0.0001
454 -2942.6318 +0.0001
455 -2942.6317 +0.0001
456 -2942.6316 +0.0001
457 -2942.6315 +0.0001
458 -2942.6315 +0.0001
459 -2942.6314 +0.0001
460 -2942.6313 +0.0001
461 -2942.6312 +0.0001
462 -2942.6311 +0.0001
463 -2942.6310 +0.0001
464 -2942.6309 +0.0001
465 -2942.6308 +0.0001
466 -2942.6307 +0.0001
467 -2942.6307 +0.0001
468 -2942.6306 +0.0001
469 -2942.6305 +0.0001
470 -2942.6304 +0.0001
471 -2942.6303 +0.0001
472 -2942.6302 +0.0001
473 -2942.6301 +0.0001
474 -2942.6301 +0.0001
475 -2942.6300 +0.0001
476 -2942.6299 +0.0001
477 -2942.6298 +0.0001
478 -2942.6297 +0.0001
479 -2942.6296 +0.0001
480 -2942.6295 +0.0001
481 -2942.6295 +0.0001
482 -2942.6294 +0.0001
483 -2942.6293 +0.0001
484 -2942.6292 +0.0001
485 -2942.6291 +0.0001
486 -2942.6291 +0.0001
487 -2942.6290 +0.0001
488 -2942.6289 +0.0001
489 -2942.6288 +0.0001
490 -2942.6287 +0.0001
491 -2942.6287 +0.0001
492 -2942.6286 +0.0001
493 -2942.6285 +0.0001
494 -2942.6284 +0.0001
495 -2942.6283 +0.0001
496 -2942.6283 +0.0001
497 -2942.6282 +0.0001
498 -2942.6281 +0.0001
499 -2942.6280 +0.0001
500 -2942.6280 +0.0001
501 -2942.6279 +0.0001
502 -2942.6278 +0.0001
503 -2942.6277 +0.0001
504 -2942.6277 +0.0001
505 -2942.6276 +0.0001
506 -2942.6275 +0.0001
507 -2942.6274 +0.0001
508 -2942.6274 +0.0001
509 -2942.6273 +0.0001
510 -2942.6272 +0.0001
511 -2942.6271 +0.0001
512 -2942.6271 +0.0001
513 -2942.6270 +0.0001
514 -2942.6269 +0.0001
515 -2942.6269 +0.0001
516 -2942.6268 +0.0001
517 -2942.6267 +0.0001
518 -2942.6266 +0.0001
519 -2942.6266 +0.0001
520 -2942.6265 +0.0001
521 -2942.6264 +0.0001
522 -2942.6264 +0.0001
523 -2942.6263 +0.0001
524 -2942.6262 +0.0001
525 -2942.6262 +0.0001
526 -2942.6261 +0.0001
527 -2942.6260 +0.0001
528 -2942.6259 +0.0001
529 -2942.6259 +0.0001
530 -2942.6258 +0.0001
531 -2942.6257 +0.0001
532 -2942.6257 +0.0001
533 -2942.6256 +0.0001
534 -2942.6255 +0.0001
535 -2942.6255 +0.0001
536 -2942.6254 +0.0001
537 -2942.6254 +0.0001
538 -2942.6253 +0.0001
539 -2942.6252 +0.0001
540 -2942.6252 +0.0001
541 -2942.6251 +0.0001
542 -2942.6250 +0.0001
543 -2942.6250 +0.0001
544 -2942.6249 +0.0001
545 -2942.6248 +0.0001
546 -2942.6248 +0.0001
547 -2942.6247 +0.0001
548 -2942.6247 +0.0001
549 -2942.6246 +0.0001
550 -2942.6245 +0.0001
551 -2942.6245 +0.0001
552 -2942.6244 +0.0001
553 -2942.6243 +0.0001
554 -2942.6243 +0.0001
555 -2942.6242 +0.0001
556 -2942.6242 +0.0001
557 -2942.6241 +0.0001
558 -2942.6241 +0.0001
559 -2942.6240 +0.0001
560 -2942.6239 +0.0001
561 -2942.6239 +0.0001
562 -2942.6238 +0.0001
563 -2942.6238 +0.0001
564 -2942.6237 +0.0001
565 -2942.6236 +0.0001
566 -2942.6236 +0.0001
567 -2942.6235 +0.0001
568 -2942.6235 +0.0001
569 -2942.6234 +0.0001
570 -2942.6234 +0.0001
571 -2942.6233 +0.0001
572 -2942.6232 +0.0001
573 -2942.6232 +0.0001
574 -2942.6231 +0.0001
575 -2942.6231 +0.0001
576 -2942.6230 +0.0001
577 -2942.6230 +0.0001
578 -2942.6229 +0.0001
579 -2942.6229 +0.0001
580 -2942.6228 +0.0001
581 -2942.6228 +0.0001
582 -2942.6227 +0.0001
583 -2942.6227 +0.0001
584 -2942.6226 +0.0001
585 -2942.6225 +0.0001
586 -2942.6225 +0.0001
587 -2942.6224 +0.0001
588 -2942.6224 +0.0001
589 -2942.6223 +0.0001
590 -2942.6223 +0.0001
591 -2942.6222 +0.0001
592 -2942.6222 +0.0001
593 -2942.6221 +0.0001
594 -2942.6221 +0.0001
595 -2942.6220 +0.0001
596 -2942.6220 +0.0000
597 -2942.6219 +0.0000
598 -2942.6219 +0.0000
599 -2942.6218 +0.0000
600 -2942.6218 +0.0000
601 -2942.6217 +0.0000
602 -2942.6217 +0.0000
603 -2942.6216 +0.0000
604 -2942.6216 +0.0000
605 -2942.6215 +0.0000
606 -2942.6215 +0.0000
607 -2942.6215 +0.0000
608 -2942.6214 +0.0000
609 -2942.6214 +0.0000
610 -2942.6213 +0.0000
611 -2942.6213 +0.0000
612 -2942.6212 +0.0000
613 -2942.6212 +0.0000
614 -2942.6211 +0.0000
615 -2942.6211 +0.0000
616 -2942.6210 +0.0000
617 -2942.6210 +0.0000
618 -2942.6209 +0.0000
619 -2942.6209 +0.0000
620 -2942.6209 +0.0000
621 -2942.6208 +0.0000
622 -2942.6208 +0.0000
623 -2942.6207 +0.0000
624 -2942.6207 +0.0000
625 -2942.6206 +0.0000
626 -2942.6206 +0.0000
627 -2942.6206 +0.0000
628 -2942.6205 +0.0000
629 -2942.6205 +0.0000
630 -2942.6204 +0.0000
631 -2942.6204 +0.0000
632 -2942.6203 +0.0000
633 -2942.6203 +0.0000
634 -2942.6203 +0.0000
635 -2942.6202 +0.0000
636 -2942.6202 +0.0000
637 -2942.6201 +0.0000
638 -2942.6201 +0.0000
639 -2942.6201 +0.0000
640 -2942.6200 +0.0000
641 -2942.6200 +0.0000
642 -2942.6199 +0.0000
643 -2942.6199 +0.0000
644 -2942.6199 +0.0000
645 -2942.6198 +0.0000
646 -2942.6198 +0.0000
647 -2942.6197 +0.0000
648 -2942.6197 +0.0000
649 -2942.6197 +0.0000
650 -2942.6196 +0.0000
651 -2942.6196 +0.0000
652 -2942.6195 +0.0000
653 -2942.6195 +0.0000
654 -2942.6195 +0.0000
655 -2942.6194 +0.0000
656 -2942.6194 +0.0000
657 -2942.6193 +0.0000
658 -2942.6193 +0.0000
659 -2942.6193 +0.0000
660 -2942.6192 +0.0000
661 -2942.6192 +0.0000
662 -2942.6192 +0.0000
663 -2942.6191 +0.0000
664 -2942.6191 +0.0000
665 -2942.6191 +0.0000
666 -2942.6190 +0.0000
667 -2942.6190 +0.0000
668 -2942.6189 +0.0000
669 -2942.6189 +0.0000
670 -2942.6189 +0.0000
671 -2942.6188 +0.0000
672 -2942.6188 +0.0000
673 -2942.6188 +0.0000
674 -2942.6187 +0.0000
675 -2942.6187 +0.0000
676 -2942.6187 +0.0000
677 -2942.6186 +0.0000
678 -2942.6186 +0.0000
679 -2942.6186 +0.0000
680 -2942.6185 +0.0000
681 -2942.6185 +0.0000
682 -2942.6185 +0.0000
683 -2942.6184 +0.0000
684 -2942.6184 +0.0000
685 -2942.6184 +0.0000
686 -2942.6183 +0.0000
687 -2942.6183 +0.0000
688 -2942.6183 +0.0000
689 -2942.6182 +0.0000
690 -2942.6182 +0.0000
691 -2942.6182 +0.0000
692 -2942.6181 +0.0000
693 -2942.6181 +0.0000
694 -2942.6181 +0.0000
695 -2942.6181 +0.0000
696 -2942.6180 +0.0000
697 -2942.6180 +0.0000
698 -2942.6180 +0.0000
699 -2942.6179 +0.0000
700 -2942.6179 +0.0000
701 -2942.6179 +0.0000
702 -2942.6178 +0.0000
703 -2942.6178 +0.0000
704 -2942.6178 +0.0000
705 -2942.6177 +0.0000
706 -2942.6177 +0.0000
707 -2942.6177 +0.0000
708 -2942.6177 +0.0000
709 -2942.6176 +0.0000
710 -2942.6176 +0.0000
711 -2942.6176 +0.0000
712 -2942.6175 +0.0000
713 -2942.6175 +0.0000
714 -2942.6175 +0.0000
715 -2942.6175 +0.0000
716 -2942.6174 +0.0000
717 -2942.6174 +0.0000
718 -2942.6174 +0.0000
719 -2942.6173 +0.0000
720 -2942.6173 +0.0000
721 -2942.6173 +0.0000
722 -2942.6173 +0.0000
723 -2942.6172 +0.0000
724 -2942.6172 +0.0000
725 -2942.6172 +0.0000
726 -2942.6172 +0.0000
727 -2942.6171 +0.0000
728 -2942.6171 +0.0000
729 -2942.6171 +0.0000
730 -2942.6170 +0.0000
731 -2942.6170 +0.0000
732 -2942.6170 +0.0000
733 -2942.6170 +0.0000
734 -2942.6169 +0.0000
735 -2942.6169 +0.0000
736 -2942.6169 +0.0000
737 -2942.6169 +0.0000
738 -2942.6168 +0.0000
739 -2942.6168 +0.0000
740 -2942.6168 +0.0000
741 -2942.6168 +0.0000
742 -2942.6167 +0.0000
743 -2942.6167 +0.0000
744 -2942.6167 +0.0000
745 -2942.6167 +0.0000
746 -2942.6166 +0.0000
747 -2942.6166 +0.0000
748 -2942.6166 +0.0000
749 -2942.6166 +0.0000
750 -2942.6165 +0.0000
751 -2942.6165 +0.0000
752 -2942.6165 +0.0000
753 -2942.6165 +0.0000
754 -2942.6164 +0.0000
755 -2942.6164 +0.0000
756 -2942.6164 +0.0000
757 -2942.6164 +0.0000
758 -2942.6163 +0.0000
759 -2942.6163 +0.0000
760 -2942.6163 +0.0000
761 -2942.6163 +0.0000
762 -2942.6163 +0.0000
763 -2942.6162 +0.0000
764 -2942.6162 +0.0000
765 -2942.6162 +0.0000
766 -2942.6162 +0.0000
767 -2942.6161 +0.0000
768 -2942.6161 +0.0000
769 -2942.6161 +0.0000
770 -2942.6161 +0.0000
771 -2942.6161 +0.0000
772 -2942.6160 +0.0000
773 -2942.6160 +0.0000
774 -2942.6160 +0.0000
775 -2942.6160 +0.0000
776 -2942.6159 +0.0000
777 -2942.6159 +0.0000
778 -2942.6159 +0.0000
779 -2942.6159 +0.0000
780 -2942.6159 +0.0000
781 -2942.6158 +0.0000
782 -2942.6158 +0.0000
783 -2942.6158 +0.0000
784 -2942.6158 +0.0000
785 -2942.6158 +0.0000
786 -2942.6157 +0.0000
787 -2942.6157 +0.0000
788 -2942.6157 +0.0000
789 -2942.6157 +0.0000
790 -2942.6157 +0.0000
791 -2942.6156 +0.0000
792 -2942.6156 +0.0000
793 -2942.6156 +0.0000
794 -2942.6156 +0.0000
795 -2942.6156 +0.0000
796 -2942.6155 +0.0000
797 -2942.6155 +0.0000
798 -2942.6155 +0.0000
799 -2942.6155 +0.0000
800 -2942.6155 +0.0000
801 -2942.6154 +0.0000
802 -2942.6154 +0.0000
803 -2942.6154 +0.0000
804 -2942.6154 +0.0000
805 -2942.6154 +0.0000
806 -2942.6153 +0.0000
807 -2942.6153 +0.0000
808 -2942.6153 +0.0000
809 -2942.6153 +0.0000
810 -2942.6153 +0.0000
811 -2942.6153 +0.0000
812 -2942.6152 +0.0000
813 -2942.6152 +0.0000
814 -2942.6152 +0.0000
815 -2942.6152 +0.0000
816 -2942.6152 +0.0000
817 -2942.6151 +0.0000
818 -2942.6151 +0.0000
819 -2942.6151 +0.0000
820 -2942.6151 +0.0000
821 -2942.6151 +0.0000
822 -2942.6151 +0.0000
823 -2942.6150 +0.0000
824 -2942.6150 +0.0000
825 -2942.6150 +0.0000
826 -2942.6150 +0.0000
827 -2942.6150 +0.0000
828 -2942.6150 +0.0000
829 -2942.6149 +0.0000
830 -2942.6149 +0.0000
831 -2942.6149 +0.0000
832 -2942.6149 +0.0000
833 -2942.6149 +0.0000
834 -2942.6148 +0.0000
835 -2942.6148 +0.0000
836 -2942.6148 +0.0000
837 -2942.6148 +0.0000
838 -2942.6148 +0.0000
839 -2942.6148 +0.0000
840 -2942.6148 +0.0000
841 -2942.6147 +0.0000
842 -2942.6147 +0.0000
843 -2942.6147 +0.0000
844 -2942.6147 +0.0000
845 -2942.6147 +0.0000
846 -2942.6147 +0.0000
847 -2942.6146 +0.0000
848 -2942.6146 +0.0000
849 -2942.6146 +0.0000
850 -2942.6146 +0.0000
851 -2942.6146 +0.0000
852 -2942.6146 +0.0000
853 -2942.6145 +0.0000
854 -2942.6145 +0.0000
855 -2942.6145 +0.0000
856 -2942.6145 +0.0000
857 -2942.6145 +0.0000
858 -2942.6145 +0.0000
859 -2942.6145 +0.0000
860 -2942.6144 +0.0000
861 -2942.6144 +0.0000
862 -2942.6144 +0.0000
863 -2942.6144 +0.0000
864 -2942.6144 +0.0000
865 -2942.6144 +0.0000
866 -2942.6144 +0.0000
867 -2942.6143 +0.0000
868 -2942.6143 +0.0000
869 -2942.6143 +0.0000
870 -2942.6143 +0.0000
871 -2942.6143 +0.0000
872 -2942.6143 +0.0000
873 -2942.6143 +0.0000
874 -2942.6142 +0.0000
875 -2942.6142 +0.0000
876 -2942.6142 +0.0000
877 -2942.6142 +0.0000
878 -2942.6142 +0.0000
879 -2942.6142 +0.0000
880 -2942.6142 +0.0000
881 -2942.6141 +0.0000
882 -2942.6141 +0.0000
883 -2942.6141 +0.0000
884 -2942.6141 +0.0000
885 -2942.6141 +0.0000
886 -2942.6141 +0.0000
887 -2942.6141 +0.0000
888 -2942.6140 +0.0000
889 -2942.6140 +0.0000
890 -2942.6140 +0.0000
891 -2942.6140 +0.0000
892 -2942.6140 +0.0000
893 -2942.6140 +0.0000
894 -2942.6140 +0.0000
895 -2942.6140 +0.0000
896 -2942.6139 +0.0000
897 -2942.6139 +0.0000
898 -2942.6139 +0.0000
899 -2942.6139 +0.0000
900 -2942.6139 +0.0000
901 -2942.6139 +0.0000
902 -2942.6139 +0.0000
903 -2942.6139 +0.0000
904 -2942.6138 +0.0000
905 -2942.6138 +0.0000
906 -2942.6138 +0.0000
907 -2942.6138 +0.0000
908 -2942.6138 +0.0000
909 -2942.6138 +0.0000
910 -2942.6138 +0.0000
911 -2942.6138 +0.0000
912 -2942.6137 +0.0000
913 -2942.6137 +0.0000
914 -2942.6137 +0.0000
915 -2942.6137 +0.0000
916 -2942.6137 +0.0000
917 -2942.6137 +0.0000
918 -2942.6137 +0.0000
919 -2942.6137 +0.0000
920 -2942.6136 +0.0000
921 -2942.6136 +0.0000
922 -2942.6136 +0.0000
923 -2942.6136 +0.0000
924 -2942.6136 +0.0000
925 -2942.6136 +0.0000
926 -2942.6136 +0.0000
927 -2942.6136 +0.0000
928 -2942.6136 +0.0000
929 -2942.6135 +0.0000
930 -2942.6135 +0.0000
931 -2942.6135 +0.0000
932 -2942.6135 +0.0000
933 -2942.6135 +0.0000
934 -2942.6135 +0.0000
935 -2942.6135 +0.0000
936 -2942.6135 +0.0000
937 -2942.6135 +0.0000
938 -2942.6134 +0.0000
939 -2942.6134 +0.0000
940 -2942.6134 +0.0000
941 -2942.6134 +0.0000
942 -2942.6134 +0.0000
943 -2942.6134 +0.0000
944 -2942.6134 +0.0000
945 -2942.6134 +0.0000
946 -2942.6134 +0.0000
947 -2942.6133 +0.0000
948 -2942.6133 +0.0000
949 -2942.6133 +0.0000
950 -2942.6133 +0.0000
951 -2942.6133 +0.0000
952 -2942.6133 +0.0000
953 -2942.6133 +0.0000
954 -2942.6133 +0.0000
955 -2942.6133 +0.0000
956 -2942.6133 +0.0000
957 -2942.6132 +0.0000
958 -2942.6132 +0.0000
959 -2942.6132 +0.0000
960 -2942.6132 +0.0000
961 -2942.6132 +0.0000
962 -2942.6132 +0.0000
963 -2942.6132 +0.0000
964 -2942.6132 +0.0000
965 -2942.6132 +0.0000
966 -2942.6132 +0.0000
967 -2942.6131 +0.0000
968 -2942.6131 +0.0000
969 -2942.6131 +0.0000
970 -2942.6131 +0.0000
971 -2942.6131 +0.0000
972 -2942.6131 +0.0000
973 -2942.6131 +0.0000
974 -2942.6131 +0.0000
975 -2942.6131 +0.0000
976 -2942.6131 +0.0000
977 -2942.6130 +0.0000
978 -2942.6130 +0.0000
979 -2942.6130 +0.0000
980 -2942.6130 +0.0000
981 -2942.6130 +0.0000
982 -2942.6130 +0.0000
983 -2942.6130 +0.0000
984 -2942.6130 +0.0000
985 -2942.6130 +0.0000
986 -2942.6130 +0.0000
987 -2942.6129 +0.0000
988 -2942.6129 +0.0000
989 -2942.6129 +0.0000
990 -2942.6129 +0.0000
991 -2942.6129 +0.0000
992 -2942.6129 +0.0000
993 -2942.6129 +0.0000
994 -2942.6129 +0.0000
995 -2942.6129 +0.0000
996 -2942.6129 +0.0000
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
GT model parameters:
startprob : [0.9 0.1]
transmat_: [[0.95 0.05]
[0.15 0.85]]
means: [[[ 5.]
[ 10.]]
[[-10.]
[ -5.]]]
covars: [[[9.]
[4.]]
[[4.]
[9.]]]
weights: [[0.6 0.4]
[0.4 0.6]]
final model parameters:
startprob : [0.745 0.255]
transmat_: [[0.94 0.06 ]
[0.167 0.833]]
means: [[[ 9.785]
[ 4.805]]
[[-10.201]
[ -5.148]]]
covars: [[[4.25 ]
[7.356]]
[[3.888]
[9.904]]]
weights: [[0.4 0.6 ]
[0.35 0.65]]
1
2
3
4
5
997 -2942.6129 +0.0000
998 -2942.6129 +0.0000
999 -2942.6128 +0.0000
1000 -2942.6128 +0.0000
In [8]:
1
2
3
4
5
X, Z = model.sample(1000)
Z_hat = trained_model.predict(X)
accuracy = (Z == Z_hat).sum() / len(Z)
accuracy = 1 - accuracy if accuracy < 0.5 else accuracy
print(f'accuracy : {accuracy*100:<.3f} %')
1
2
accuracy : 99.500 %
In [9]:
1
2
3
4
5
6
7
X_cumsum = X.cumsum()
X_cumsum_hat = X_cumsum.copy()
mask = Z == 0
X_cumsum_hat[mask] = np.nan
plt.plot(X_cumsum, lw=5)
plt.plot(X_cumsum_hat, 'r-', lw=5)
plt.title("X cumulated")
1
Text(0.5, 1.0, 'X cumulated')
Leave a comment