-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmath.leo
10318 lines (8443 loc) · 314 KB
/
math.leo
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
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by Leo: https://leo-editor.github.io/leo-editor/leo_toc.html -->
<leo_file xmlns:leo="https://leo-editor.github.io/leo-editor/namespaces/leo-python-editor/1.1" >
<leo_header file_format="2"/>
<globals/>
<preferences/>
<find_panel_settings/>
<vnodes>
<v t="ekr.20241212164559.1" descendentVnodeUnknownAttributes="7d7100285803000000302e3071017d7102580b0000005f5f626f6f6b6d61726b7371037d7104580700000069735f6475706571054930300a73735803000000302e3271067d71075808000000616e6e6f7461746571087d71092858080000007072696f72697479710a4d0f27580a00000070726973657464617465710b580a000000323032312d30332d3330710c7573752e"><vh>Startup</vh>
<v t="ekr.20241212164559.3" descendentVnodeUnknownAttributes="7d71002858010000003071017d7102580b0000005f5f626f6f6b6d61726b7371037d7104580700000069735f6475706571054930300a73735806000000302e31382e3071067d71075808000000616e6e6f7461746571087d71092858080000007072696f72697479710a4d0f27580a00000070726973657464617465710b580a000000323032312d30332d3330710c7573752e"><vh>@settings</vh>
<v t="ekr.20241212164559.4"><vh>@bool allow-text-zoom = True</vh></v>
<v t="ekr.20241212164559.5"><vh>@bool check-python-code-on-write = True</vh></v>
<v t="ekr.20241212164559.7"><vh>@bool use-mouse-expand-gestures = False</vh></v>
<v t="ekr.20241212164559.8"><vh>@data exec-script-commands</vh></v>
<v t="ekr.20241212164559.9"><vh>@data exec-script-patterns</vh></v>
<v t="ekr.20241212164559.305"><vh>@data history-list</vh></v>
<v t="ekr.20241212164559.306"><vh>@string qt-layout-name = legacy</vh></v>
<v t="ekr.20241212164559.13"><vh>Abbreviation settings</vh>
<v t="ekr.20241212164559.14"><vh>@bool enable-abbreviations = True</vh></v>
<v t="ekr.20241212164559.15"><vh>@outline-data tree-abbreviations</vh>
<v t="ekr.20241212164559.16"><vh>@organizer 1</vh>
<v t="ekr.20241212164559.17"><vh>@organizer 2</vh>
<v t="ekr.20241212164559.18"><vh>demo;;</vh>
<v t="ekr.20241212164559.19"><vh>@@button MyDemo @key=Ctrl-9</vh>
<v t="ekr.20241212164559.20"><vh><< imports >></vh></v>
<v t="ekr.20241212164559.21"><vh>script_string</vh></v>
<v t="ekr.20241212164559.22"><vh>class myDemo</vh></v>
<v t="ekr.20241212164559.23"><vh>wrappers</vh></v>
</v>
</v>
</v>
<v t="ekr.20241212164559.24"><vh>per-commander-plugin;;</vh>
<v t="ekr.20241212164559.25"><vh>@@file pluginname.py</vh>
<v t="ekr.20241212164559.26"><vh><< docstring >></vh></v>
<v t="ekr.20241212164559.27"><vh><< version history >></vh></v>
<v t="ekr.20241212164559.28"><vh><< imports >></vh></v>
<v t="ekr.20241212164559.29"><vh>init</vh></v>
<v t="ekr.20241212164559.30"><vh>onCreate</vh></v>
<v t="ekr.20241212164559.31"><vh>class pluginController</vh>
<v t="ekr.20241212164559.32"><vh>__init__</vh></v>
</v>
</v>
</v>
</v>
<v t="ekr.20241212164559.33"><vh>importer;;</vh>
<v t="ekr.20241212164559.34"><vh>@@file importers/{|{x=name}|}.py</vh>
<v t="ekr.20241212164559.35"><vh>class {|{x=cap_name}|}_Importer</vh>
<v t="ekr.20241212164559.36"><vh>{|{x=name}|}.Overrides</vh>
<v t="ekr.20241212164559.37"><vh>{|{x=name}|}.clean_headline</vh></v>
<v t="ekr.20241212164559.38"><vh>{|{x=name}|}.clean_nodes</vh></v>
</v>
</v>
<v t="ekr.20241212164559.39"><vh>class class {|{x=cap_name}|}_ScanState</vh>
<v t="ekr.20241212164559.40"><vh>{|{x=name}|}_state.level</vh></v>
<v t="ekr.20241212164559.41"><vh>{|{x=name}|}_state.update</vh></v>
</v>
</v>
</v>
</v>
</v>
<v t="ekr.20241212164559.42"><vh>Appearance settings</vh>
<v t="ekr.20241212164559.43"><vh>@bool log-pane-wraps = False</vh></v>
<v t="ekr.20241212164559.44"><vh>@bool recent-files-group-always = True</vh></v>
<v t="ekr.20241212164559.45"><vh>@bool show-iconbar = True</vh></v>
<v t="ekr.20241212164559.46"><vh>@bool show-tips = False</vh></v>
<v t="ekr.20241212164559.47"><vh>@bool stayInTreeAfterSelect = True</vh></v>
<v t="ekr.20241212164559.48"><vh>@bool use-chapter-tabs = True</vh></v>
<v t="ekr.20241212164559.49"><vh>@bool use-chapters = True</vh></v>
<v t="ekr.20241212164559.50"><vh>@bool use-gutter = False</vh></v>
<v t="ekr.20241212164559.51"><vh>@int qweb-view-font-size = 30</vh></v>
<v t="ekr.20241212164559.52"><vh>@string initial-split-orientation = v</vh></v>
</v>
<v t="ekr.20241212164559.106"><vh>Chapters</vh>
<v t="ekr.20241212164559.107"><vh>@chapter 1</vh>
<v t="ekr.20241212164559.108"><vh>abc node 1</vh>
<v t="ekr.20241212164559.109"><vh>child</vh></v>
</v>
<v t="ekr.20241212164559.114"><vh>cloned node in chapter</vh></v>
</v>
<v t="ekr.20241212164559.111"><vh>@chapter 2</vh>
<v t="ekr.20241212164559.112"><vh>Chapter two</vh>
<v t="ekr.20241212164559.113"><vh>Second node</vh></v>
</v>
<v t="ekr.20241212164559.114"></v>
</v>
<v t="ekr.20241212164559.115"><vh>@chapter 3</vh></v>
<v t="ekr.20241212164559.116"><vh>@chapter 丗 @key=Ctrl-1</vh></v>
</v>
<v t="ekr.20241212164559.117"><vh>Coloring settings</vh>
<v t="ekr.20241212164559.118"><vh>@bool color-doc-parts-as-rest = True</vh></v>
<v t="ekr.20241212164559.119"><vh>@bool use-pygments = False</vh></v>
<v t="ekr.20241212164559.120"><vh>@bool use-pygments-styles = False</vh></v>
<v t="ekr.20241212164559.121"><vh>@color head-bg = @mistyrose2</vh></v>
<v t="ekr.20241212164559.122"><vh>@string pygments-style-name = leonine</vh></v>
<v t="ekr.20241212164559.302"><vh>@string target-language = python</vh></v>
</v>
<v t="ekr.20241212164559.124"><vh>Command settings</vh>
<v t="ekr.20241212164559.125"><vh>@bool create-at-persistence-nodes-automatically = True</vh></v>
<v t="ekr.20241212164559.126"><vh>@bool enable-persistence = True</vh></v>
<v t="ekr.20241212164559.127"><vh>@bool make-node-conflicts-node = True</vh></v>
<v t="ekr.20241212164559.128"><vh>@bool run-pyflakes-on-write = True</vh></v>
<v t="ekr.20241212164559.129"><vh>@bool use-jedi = True</vh></v>
<v t="ekr.20241212164559.130"><vh>@bool use-qcompleter = False</vh></v>
<v t="ekr.20241212164559.131"><vh>@bool warn-about-redefined-shortcuts = True</vh></v>
<v t="ekr.20241212164559.132"><vh>@int auto-justify = 80</vh></v>
<v t="ekr.20241212164559.133"><vh>rst3 path options</vh>
<v t="ekr.20241212164559.134"><vh>@string rst3-write-intermediate-extension = .txt</vh></v>
<v t="ekr.20241212164559.135"><vh>@string rst3-default-path = None</vh></v>
<v t="ekr.20241212164559.136"><vh>@string rst3-stylesheet-name = default.css</vh></v>
<v t="ekr.20241212164559.137"><vh>@string rst3-stylesheet-path = None</vh></v>
<v t="ekr.20241212164559.138"><vh>@string rst3-publish-argv-for-missing-stylesheets = None</vh></v>
</v>
</v>
<v t="ekr.20241212164559.139"><vh>Declutter</vh>
<v t="ekr.20241212164559.300"><vh>@bool tree-declutter = False</vh></v>
<v t="ekr.20241212164559.141"><vh>@data tree-declutter-patterns</vh></v>
<v t="ekr.20241212164559.142"><vh>--- unused patterns</vh>
<v t="ekr.20241212164559.143"><vh> About Decluttering</vh>
<v t="ekr.20241212164559.144"><vh>Rule & replacement lines</vh></v>
<v t="ekr.20241212164559.145"><vh>Style lines</vh></v>
</v>
<v t="ekr.20241212164559.146"><vh>declutter: add icon to folders and remove...</vh></v>
<v t="ekr.20241212164559.147"><vh>declutter: demo pattern</vh></v>
<v t="ekr.20241212164559.148"><vh>declutter: hide org-mode tags</vh></v>
<v t="ekr.20241212164559.149"><vh>declutter: replace @<file> with an icon</vh></v>
<v t="ekr.20241212164559.150"><vh>declutter: show last part of long filenames</vh></v>
</v>
</v>
<v t="ekr.20241212164559.151"><vh>Environment settings</vh>
<v t="ekr.20241212164559.152"><vh>@ifenv COMPUTERNAME, edreamleo-pc, other-pc</vh>
<v t="ekr.20241212164559.153"><vh>@bool computername = True</vh></v>
</v>
<v t="ekr.20241212164559.154"><vh>@ifenv xyzzy, abc</vh>
<v t="ekr.20241212164559.155"><vh>@bool xyzzy = True</vh></v>
</v>
<v t="ekr.20241212164559.156"><vh>@ifplatform win32,linux2</vh>
<v t="ekr.20241212164559.157"><vh>@string platform = not-mac</vh></v>
</v>
</v>
<v t="ekr.20241212164559.158"><vh>File settings</vh>
<v t="ekr.20241212164559.159"><vh>@bool open-with-clean-filenames = True</vh></v>
<v t="ekr.20241212164559.160"><vh>@bool check-for-changed-external-files = True</vh></v>
<v t="ekr.20241212164559.161"><vh>@bool open-with-save-on-update = False</vh></v>
<v t="ekr.20241212164559.162"><vh>@bool open-with-uses-derived-file-extensions = True</vh></v>
</v>
<v t="ekr.20241212164559.163"><vh>Find settings</vh>
<v t="ekr.20241212164559.164"><vh>@bool auto-scroll-find-tab = False</vh></v>
<v t="ekr.20241212164559.165"><vh>@bool close-find-dialog-after-search = False</vh></v>
<v t="ekr.20241212164559.166"><vh>@bool find-ignore-duplicates = False</vh></v>
<v t="ekr.20241212164559.167"><vh>@bool minibuffer-find-mode = True</vh></v>
<v t="ekr.20241212164559.168"><vh>@bool use-find-dialog = False</vh></v>
</v>
<v t="ekr.20241212164559.169"><vh>Importer settings</vh>
<v t="ekr.20241212164559.170"><vh>@data import-html-tags</vh></v>
<v t="ekr.20241212164559.171"><vh>@data import-xml-tags</vh></v>
</v>
<v t="ekr.20241212164559.172"><vh>make-stub-files settings</vh>
<v t="ekr.20241212164559.173"><vh>@bool stub-overwrite = True</vh></v>
<v t="ekr.20241212164559.174"><vh>@bool stub-trace-matches = False</vh></v>
<v t="ekr.20241212164559.175"><vh>@bool stub-trace-patterns = False</vh></v>
<v t="ekr.20241212164559.176"><vh>@bool stub-trace-reduce = False</vh></v>
<v t="ekr.20241212164559.177"><vh>@bool stub-trace-visitors = False</vh></v>
<v t="ekr.20241212164559.178"><vh>@bool stub-update = False</vh></v>
<v t="ekr.20241212164559.179"><vh>@data stub-def-name-patterns</vh></v>
<v t="ekr.20241212164559.180"><vh>@data stub-general-patterns</vh></v>
<v t="ekr.20241212164559.181"><vh>@data stub-prefix-lines</vh></v>
<v t="ekr.20241212164559.182"><vh>@string stub-output-directory = ~/stubs</vh></v>
</v>
<v t="ekr.20241212164559.183" descendentVnodeUnknownAttributes="7d71005803000000302e3071017d71025808000000616e6e6f7461746571037d71042858080000007072696f7269747971054d0f27580a000000707269736574646174657106580a000000323032312d30332d333071077573732e"><vh>Plugins (one of these is essential)</vh>
<v t="ekr.20241212164559.307" descendentVnodeUnknownAttributes="7d710058010000003071017d71025808000000616e6e6f7461746571037d71042858080000007072696f7269747971054d0f27580a000000707269736574646174657106580a000000323032312d30332d333071077573732e"><vh>@enabled-plugins</vh></v>
<v t="ekr.20241212164559.185"><vh>@@bool scripting-at-plugin-nodes = True</vh></v>
<v t="ekr.20241212164559.186"><vh>mod_http settings</vh>
<v t="ekr.20241212164559.187"><vh>@bool http-active = True</vh></v>
<v t="ekr.20241212164559.188"><vh>@int port = 8080</vh></v>
<v t="ekr.20241212164559.189"><vh>@string rst-http-attributename = 'rst_http_attribute'</vh></v>
</v>
<v t="ekr.20241212164559.190"><vh>viewrendered settings</vh>
<v t="ekr.20241212164559.191"><vh>@bool view-rendered-auto-create = False</vh></v>
<v t="ekr.20241212164559.192"><vh>@bool view-rendered-auto-hide = False</vh></v>
<v t="ekr.20241212164559.193"><vh>@string view-rendered-default-kind = rst</vh></v>
</v>
<v t="ekr.20241212164559.194"><vh>wikiview plugin</vh>
<v t="ekr.20241212164559.195"><vh>@data wikiview-link-patterns</vh></v>
<v t="ekr.20241212164559.196"><vh>@bool wikiview-active = True</vh></v>
</v>
</v>
<v t="ekr.20241212164559.197"><vh>Scintilla settings</vh>
<v t="ekr.20241212164559.299"><vh>@bool qt-use-scintilla = False</vh></v>
</v>
<v t="ekr.20241212164559.199"><vh>Sphinx settings</vh>
<v t="ekr.20241212164559.200"><vh>@string sphinx-command-directory = </vh></v>
<v t="ekr.20241212164559.201"><vh>@string sphinx-default-command = make html</vh></v>
<v t="ekr.20241212164559.202"><vh>@string sphinx-input-directory = None</vh></v>
<v t="ekr.20241212164559.203"><vh>@string sphinx-output-directory = None</vh></v>
</v>
<v t="ekr.20241212164559.204"><vh>Syntax coloring settings</vh>
<v t="ekr.20241212164559.205"><vh>@@color rest.keyword2 = red</vh></v>
<v t="ekr.20241212164559.206"><vh>@@color rest.keyword4 = blue</vh></v>
<v t="ekr.20241212164559.207"><vh>@@color rest.leokeyword = green</vh></v>
<v t="ekr.20241212164559.208"><vh>@color forth.keyword3 = black</vh></v>
<v t="ekr.20241212164559.209"><vh>@color python.name = @solarized-yellow</vh></v>
<v t="ekr.20241212164559.210"><vh>@font rest.comment1</vh></v>
</v>
<v t="ekr.20241212164559.211"><vh>Vim mode</vh>
<v t="ekr.20241212164559.212"><vh>@string vim-mode-normal-border = border: 3px solid #268bd2</vh></v>
<v t="ekr.20241212164559.213"><vh>@string vim-mode-insert-border = border: 3px solid #dc322f</vh></v>
<v t="ekr.20241212164559.214"><vh>@string vim-mode-visual-border = border: 3px solid gray</vh></v>
<v t="ekr.20241212164559.215"><vh>@string vim-mode-unfocused-border = border: 3px dashed #268bd2</vh></v>
<v t="ekr.20241212164559.216"><vh>@bool vim-mode = False</vh></v>
</v>
</v>
<v t="ekr.20241212164559.305"></v>
<v t="ekr.20241212164559.307" descendentVnodeUnknownAttributes="7d710058010000003071017d71025808000000616e6e6f7461746571037d71042858080000007072696f7269747971054d0f27580a000000707269736574646174657106580a000000323032312d30332d333071077573732e"></v>
</v>
<v t="ekr.20241213035513.1"><vh>Read me</vh></v>
<v t="ekr.20241212164526.17"><vh>@button import-ipynb</vh></v>
<v t="ekr.20241212164526.14"><vh>@button exec-py-file</vh></v>
<v t="ekr.20241213022535.1"><vh>--- Converted ipynb files</vh>
<v t="ekr.20241212164526.16"><vh>pyflakes warnings</vh></v>
<v t="ekr.20241213022535.2"><vh>CH01</vh>
<v t="ekr.20241213022535.3"><vh># @file CH01\CH01_SEC02.py</vh>
<v t="ekr.20241213022535.5"><vh>from matplotlib.image import imread</vh></v>
<v t="ekr.20241213022535.6"><vh>plt.rcParams['figure.figsize'] = [16, 8]</vh></v>
<v t="ekr.20241213022535.7"><vh>U, S, VT =</vh></v>
<v t="ekr.20241213022535.8"><vh>plt.figure(1)</vh></v>
</v>
<v t="ekr.20241213022535.9"><vh># @file CH01\CH01_SEC03_Rotation.py</vh>
<v t="ekr.20241213022535.11"><vh>import matplotlib.pyplot as plt</vh></v>
<v t="ekr.20241213022535.12"><vh>Plot sphere</vh></v>
<v t="ekr.20241213022535.13"><vh>Cell 3</vh></v>
</v>
<v t="ekr.20241213022535.14"><vh># @file CH01\CH01_SEC04_1_Linear.py</vh>
<v t="ekr.20241213022535.16"><vh>import matplotlib.pyplot as plt</vh></v>
<v t="ekr.20241213022535.17"><vh>Three methods of computing regression</vh></v>
</v>
<v t="ekr.20241213022535.18"><vh># @file CH01\CH01_SEC04_2_Cement.py</vh>
<v t="ekr.20241213022535.20"><vh>import matplotlib.pyplot as plt</vh></v>
<v t="ekr.20241213022535.21"><vh>Alternative Methods:</vh></v>
<v t="ekr.20241213022535.22"><vh>Cell 3</vh></v>
</v>
<v t="ekr.20241213022535.23"><vh># @file CH01\CH01_SEC04_3_Housing.py</vh>
<v t="ekr.20241213022535.25"><vh>import matplotlib.pyplot as plt</vh></v>
<v t="ekr.20241213022535.26"><vh>A_mean = np.mean(A,axis=0)</vh></v>
</v>
<v t="ekr.20241213022535.27"><vh># @file CH01\CH01_SEC05_1_PCAGaussian.py</vh>
<v t="ekr.20241213022535.29"><vh>import matplotlib.pyplot as plt</vh></v>
<v t="ekr.20241213022535.30"><vh>Cell 2</vh></v>
</v>
<v t="ekr.20241213022535.31"><vh># @file CH01\CH01_SEC05_2_OvarianCancer.py</vh>
<v t="ekr.20241213022535.33"><vh>import matplotlib.pyplot as plt</vh></v>
<v t="ekr.20241213022535.34"><vh>fig2 = plt.figure()</vh></v>
</v>
<v t="ekr.20241213022535.35"><vh># @file CH01\CH01_SEC06_1.py</vh>
<v t="ekr.20241213022535.37"><vh>import matplotlib.pyplot as plt</vh></v>
<v t="ekr.20241213022535.38"><vh>for person in range(len(nfaces)):</vh></v>
</v>
<v t="ekr.20241213022535.39"><vh># @file CH01\CH01_SEC06_2_3_4.py</vh>
<v t="ekr.20241213022535.41"><vh>import matplotlib.pyplot as plt</vh></v>
<v t="ekr.20241213022535.42"><vh># Now show eigenface reconstruction of</vh></v>
<v t="ekr.20241213022535.43"><vh># Project person 2 and 7 onto PC5 and</vh></v>
<v t="ekr.20241213022535.44"><vh>Cell 4</vh></v>
</v>
<v t="ekr.20241213022535.45"><vh># @file CH01\CH01_SEC07_1.py</vh>
<v t="ekr.20241213022535.47"><vh>import matplotlib.pyplot as plt</vh></v>
<v t="ekr.20241213022535.48"><vh>sigma = 1</vh></v>
<v t="ekr.20241213022535.49"><vh>U, S, VT =</vh></v>
<v t="ekr.20241213022535.50"><vh>Cumulative energy</vh></v>
<v t="ekr.20241213022535.51"><vh># Plot Singular Values</vh></v>
<v t="ekr.20241213022535.52"><vh>Cell 6</vh></v>
</v>
<v t="ekr.20241213022535.53"><vh># @file CH01\CH01_SEC07_2.py</vh>
<v t="ekr.20241213022535.55"><vh>import matplotlib.pyplot as plt</vh></v>
<v t="ekr.20241213022535.56"><vh>X_rot = skimage.transform.rotate(X,10)</vh></v>
<v t="ekr.20241213022535.57"><vh>U, S, VT =</vh></v>
<v t="ekr.20241213022535.58"><vh>U_rot, S_rot, VT_rot =</vh></v>
<v t="ekr.20241213022535.59"><vh>Cell 5</vh></v>
</v>
<v t="ekr.20241213022535.60"><vh># @file CH01\CH01_SEC07_3.py</vh>
<v t="ekr.20241213022535.62"><vh>import matplotlib.pyplot as plt</vh></v>
<v t="ekr.20241213022535.63"><vh>Xrot = X</vh></v>
<v t="ekr.20241213022535.64"><vh>Cell 3</vh></v>
</v>
<v t="ekr.20241213022535.65"><vh># @file CH01\CH01_SEC08_RSVD.py</vh>
<v t="ekr.20241213022535.67"><vh>import matplotlib.pyplot as plt</vh></v>
<v t="ekr.20241213022535.68"><vh>A = imread(os.path.join('..','DATA','jup</vh></v>
<v t="ekr.20241213022535.69"><vh># Reconstruction</vh></v>
<v t="ekr.20241213022535.70"><vh># Plot</vh></v>
<v t="ekr.20241213022535.71"><vh># Illustrate power iterations</vh></v>
<v t="ekr.20241213022535.72"><vh>Cell 6</vh></v>
</v>
<v t="ekr.20241213022535.73"><vh># @file CH01\CH01_SEC09_Tensor.py</vh>
<v t="ekr.20241213022535.75"><vh>import matplotlib.pyplot as plt</vh></v>
<v t="ekr.20241213022535.76"><vh>plt.rcParams['figure.figsize'] = [16,10]</vh></v>
<v t="ekr.20241213022535.77"><vh>Tensor factorization method requires the</vh></v>
<v t="ekr.20241213022535.78"><vh>Cell 4</vh></v>
<v t="ekr.20241213022535.79"><vh>Cell 5</vh></v>
</v>
</v>
<v t="ekr.20241213022535.80"><vh>CH02</vh>
<v t="ekr.20241213022535.81"><vh># @file CH02\CH02_SEC01_0_InnerProduct.py</vh>
<v t="ekr.20241213022535.83"><vh>import numpy as np</vh></v>
</v>
<v t="ekr.20241213022535.84"><vh># @file CH02\CH02_SEC01_1_FourierSines.py</vh>
<v t="ekr.20241213022535.86"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022535.87"><vh># Plot amplitudes</vh></v>
<v t="ekr.20241213022535.88"><vh>Cell 3</vh></v>
</v>
<v t="ekr.20241213022535.89"><vh># @file CH02\CH02_SEC01_2_Gibbs.py</vh>
<v t="ekr.20241213022535.91"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022535.92"><vh>Cell 2</vh></v>
<v t="ekr.20241213022535.93"><vh>Cell 3</vh></v>
</v>
<v t="ekr.20241213022535.94"><vh># @file CH02\CH02_SEC01_2_Gibbs_Movie.py</vh>
<v t="ekr.20241213022535.96"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022535.97"><vh>Cell 2</vh></v>
<v t="ekr.20241213022535.98"><vh>Cell 3</vh></v>
</v>
<v t="ekr.20241213022535.99"><vh># @file CH02\CH02_SEC02_1_DFT.py</vh>
<v t="ekr.20241213022535.101"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022535.102"><vh>DFT = np.zeros((n,n))</vh></v>
<v t="ekr.20241213022535.103"><vh>Fast</vh></v>
<v t="ekr.20241213022535.104"><vh>Cell 4</vh></v>
</v>
<v t="ekr.20241213022535.105"><vh># @file CH02\CH02_SEC02_2_Denoise.py</vh>
<v t="ekr.20241213022535.107"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022535.108"><vh># Compute the Fast Fourier Transform</vh></v>
<v t="ekr.20241213022535.109"><vh># Use the PSD to filter out noise</vh></v>
<v t="ekr.20241213022535.110"><vh># Plots</vh></v>
</v>
<v t="ekr.20241213022535.111"><vh># @file CH02\CH02_SEC02_3_SpectralDerivative.py</vh>
<v t="ekr.20241213022535.113"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022535.114"><vh># Approximate derivative using finite</vh></v>
<v t="ekr.20241213022535.115"><vh># Derivative using FFT (spectral</vh></v>
<v t="ekr.20241213022535.116"><vh># Plots</vh></v>
<v t="ekr.20241213022535.117"><vh>Cell 5</vh></v>
</v>
<v t="ekr.20241213022535.118"><vh># @file CH02\CH02_SEC03_1_FFTHeat.py</vh>
<v t="ekr.20241213022535.120"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022535.121"><vh>Cell 2</vh></v>
</v>
<v t="ekr.20241213022535.122"><vh># @file CH02\CH02_SEC03_2_FFTWave.py</vh>
<v t="ekr.20241213022535.124"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022535.125"><vh>Cell 2</vh></v>
</v>
<v t="ekr.20241213022535.126"><vh># @file CH02\CH02_SEC03_3_FFTBurgers.py</vh>
<v t="ekr.20241213022535.128"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022535.129"><vh>Cell 2</vh></v>
</v>
<v t="ekr.20241213022535.130"><vh># @file CH02\CH02_SEC04_1_SpectrogramChirp.py</vh>
<v t="ekr.20241213022535.132"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022535.133"><vh>Cell 2</vh></v>
<v t="ekr.20241213022535.134"><vh>Cell 3</vh></v>
</v>
<v t="ekr.20241213022535.135"><vh># @file CH02\CH02_SEC05_HAAR.py</vh>
<v t="ekr.20241213022535.137"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022535.138"><vh>x = np.arange(-5,5,0.001)</vh></v>
<v t="ekr.20241213022535.139"><vh>Cell 3</vh></v>
</v>
<v t="ekr.20241213022535.140"><vh># @file CH02\CH02_SEC06_1_2DFFT.py</vh>
<v t="ekr.20241213022535.142"><vh>from matplotlib.image import imread</vh></v>
<v t="ekr.20241213022535.143"><vh>Cell 2</vh></v>
</v>
<v t="ekr.20241213022535.144"><vh># @file CH02\CH02_SEC06_2_Compress.py</vh>
<v t="ekr.20241213022535.146"><vh>from matplotlib.image import imread</vh></v>
<v t="ekr.20241213022535.147"><vh>Cell 2</vh></v>
<v t="ekr.20241213022535.148"><vh>Cell 3</vh></v>
</v>
<v t="ekr.20241213022535.149"><vh># @file CH02\CH02_SEC06_3_Denoise.py</vh>
<v t="ekr.20241213022535.151"><vh>from matplotlib.image import imread</vh></v>
<v t="ekr.20241213022535.152"><vh># Denoise</vh></v>
</v>
<v t="ekr.20241213022535.153"><vh># @file CH02\CH02_SEC06_4_Wavelet.py</vh>
<v t="ekr.20241213022535.155"><vh>Using the PyWavelets module, available</vh></v>
<v t="ekr.20241213022535.156"><vh># Wavelet decomposition (2 level)</vh></v>
</v>
<v t="ekr.20241213022535.157"><vh># @file CH02\CH02_SEC06_5_WaveletCompress.py</vh>
<v t="ekr.20241213022535.159"><vh>Using the PyWavelets module, available</vh></v>
<v t="ekr.20241213022535.160"><vh># Wavelet Compression</vh></v>
</v>
</v>
<v t="ekr.20241213022535.161"><vh>CH03</vh>
<v t="ekr.20241213022535.162"><vh># @file CH03\CH03_SEC01_Compress.py</vh>
<v t="ekr.20241213022535.164"><vh>from matplotlib.image import imread</vh></v>
<v t="ekr.20241213022535.165"><vh># Compute FFT of image using fft2</vh></v>
<v t="ekr.20241213022535.166"><vh># Zero out all small coefficients and</vh></v>
<v t="ekr.20241213022535.167"><vh># Plot Reconstruction</vh></v>
<v t="ekr.20241213022535.168"><vh>plt.rcParams['figure.figsize'] = [16, 8]</vh></v>
<v t="ekr.20241213022535.169"><vh>Cell 6</vh></v>
<v t="ekr.20241213022535.170"><vh>Cell 7</vh></v>
</v>
<v t="ekr.20241213022536.1"><vh># @file CH03\CH03_SEC03_1_Underdetermined.py</vh>
<v t="ekr.20241213022536.3"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.4"><vh>L2 Minimum norm solution s_L2</vh></v>
<v t="ekr.20241213022536.5"><vh>fig,axs = plt.subplots(2,2)</vh></v>
<v t="ekr.20241213022536.6"><vh>Cell 4</vh></v>
<v t="ekr.20241213022536.7"><vh>Cell 5</vh></v>
</v>
<v t="ekr.20241213022536.8"><vh># @file CH03\CH03_SEC03_2_AudioCS.py</vh>
<v t="ekr.20241213022536.10"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.11"><vh># Generate signal, DCT of signal</vh></v>
<v t="ekr.20241213022536.12"><vh># Randomly sample signal</vh></v>
<v t="ekr.20241213022536.13"><vh># Solve compressed sensing problem</vh></v>
<v t="ekr.20241213022536.14"><vh># Plot</vh></v>
<v t="ekr.20241213022536.15"><vh># L1-Minimization using SciPy</vh></v>
<v t="ekr.20241213022536.16"><vh>Theta.shape</vh></v>
<v t="ekr.20241213022536.17"><vh>y.shape</vh></v>
<v t="ekr.20241213022536.18"><vh>Cell 9</vh></v>
</v>
<v t="ekr.20241213022536.19"><vh># @file CH03\CH03_SEC04_Matrices.py</vh>
<v t="ekr.20241213022536.21"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.22"><vh># Plot Psi</vh></v>
<v t="ekr.20241213022536.23"><vh># Plot C</vh></v>
<v t="ekr.20241213022536.24"><vh># Plot Theta</vh></v>
<v t="ekr.20241213022536.25"><vh># Plot s, y</vh></v>
<v t="ekr.20241213022536.26"><vh># L1-Minimization using SciPy</vh></v>
<v t="ekr.20241213022536.27"><vh># Plot C and Theta (2) - Gaussian Random</vh></v>
<v t="ekr.20241213022536.28"><vh>Plot C and Theta (3) - Bernoulli Random</vh></v>
<v t="ekr.20241213022536.29"><vh>Plot C and Theta (4) - Sparse Bernoulli</vh></v>
<v t="ekr.20241213022536.30"><vh>Bad C and Theta (5) - DCT Meas</vh></v>
<v t="ekr.20241213022536.31"><vh>Cell 11</vh></v>
<v t="ekr.20241213022536.32"><vh>Cell 12</vh></v>
<v t="ekr.20241213022536.33"><vh>Cell 13</vh></v>
</v>
<v t="ekr.20241213022536.34"><vh># @file CH03\CH03_SEC05_1_RobustRegression.py</vh>
<v t="ekr.20241213022536.36"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.37"><vh>Random data from [-2,2]</vh></v>
<v t="ekr.20241213022536.38"><vh># L1 optimization to reject outlier</vh></v>
<v t="ekr.20241213022536.39"><vh>Data</vh></v>
<v t="ekr.20241213022536.40"><vh>Cell 5</vh></v>
</v>
<v t="ekr.20241213022536.41"><vh># @file CH03\CH03_SEC05_2_LASSO.py</vh>
<v t="ekr.20241213022536.43"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.44"><vh>Matrix of possible predictors</vh></v>
<v t="ekr.20241213022536.45"><vh>reg = linear_model.LassoCV(cv=10).fit(A,</vh></v>
<v t="ekr.20241213022536.46"><vh>XL1 = linear_model.Lasso(alpha=clf.best_</vh></v>
<v t="ekr.20241213022536.47"><vh>Cell 5</vh></v>
</v>
<v t="ekr.20241213022536.48"><vh># @file CH03\CH03_SEC06_SparseRepresentation.py</vh>
<v t="ekr.20241213022536.50"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.51"><vh># Build Training and Test sets</vh></v>
<v t="ekr.20241213022536.52"><vh># Downsample Training Images (Build</vh></v>
<v t="ekr.20241213022536.53"><vh># Renormalize Columns of Theta</vh></v>
<v t="ekr.20241213022536.54"><vh># Occlude Test Image (Test[:,125] = test</vh></v>
<v t="ekr.20241213022536.55"><vh># Downsample Test Images</vh></v>
<v t="ekr.20241213022536.56"><vh># L1 Search, Testclean</vh></v>
<v t="ekr.20241213022536.57"><vh>plt.figure()</vh></v>
<v t="ekr.20241213022536.58"><vh># L1 Search, Mustache</vh></v>
<v t="ekr.20241213022536.59"><vh>plt.figure()</vh></v>
<v t="ekr.20241213022536.60"><vh># L1 Search, Occlusion</vh></v>
<v t="ekr.20241213022536.61"><vh>plt.figure()</vh></v>
<v t="ekr.20241213022536.62"><vh># L1 Search, Noise</vh></v>
<v t="ekr.20241213022536.63"><vh>plt.figure()</vh></v>
<v t="ekr.20241213022536.64"><vh># Least Squares Is No Good</vh></v>
<v t="ekr.20241213022536.65"><vh>Cell 16</vh></v>
<v t="ekr.20241213022536.66"><vh>Cell 17</vh></v>
</v>
<v t="ekr.20241213022536.67"><vh># @file CH03\CH03_SEC07_RPCA.py</vh>
<v t="ekr.20241213022536.69"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.70"><vh># Function Definitions</vh></v>
<v t="ekr.20241213022536.71"><vh>X = faces[:,:nfaces[0]]</vh></v>
<v t="ekr.20241213022536.72"><vh>inds = (3,4,14,15,17,18,19,20,21,32,43)</vh></v>
<v t="ekr.20241213022536.73"><vh>Cell 5</vh></v>
<v t="ekr.20241213022536.74"><vh>Cell 6</vh></v>
</v>
</v>
<v t="ekr.20241213022536.75"><vh>CH04</vh>
<v t="ekr.20241213022536.76"><vh># @file CH04\CH04_SEC01_LinearRegression.py</vh>
<v t="ekr.20241213022536.78"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.79"><vh>The data</vh></v>
<v t="ekr.20241213022536.80"><vh>x = np.arange(1,11)</vh></v>
<v t="ekr.20241213022536.81"><vh>Cell 4</vh></v>
<v t="ekr.20241213022536.82"><vh>Cell 5</vh></v>
</v>
<v t="ekr.20241213022536.83"><vh># @file CH04\CH04_SEC02_1_GradientDescent.py</vh>
<v t="ekr.20241213022536.85"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.86"><vh>h = 0.5</vh></v>
<v t="ekr.20241213022536.87"><vh>rcParams['figure.figsize'] = [16, 8]</vh></v>
<v t="ekr.20241213022536.88"><vh>rcParams['figure.figsize'] = [16, 16]</vh></v>
<v t="ekr.20241213022536.89"><vh># Gradient Descent</vh></v>
<v t="ekr.20241213022536.90"><vh>fig,ax = plt.subplots(1,1,subplot_kw={'p</vh></v>
<v t="ekr.20241213022536.91"><vh># Computing the gradient descent with</vh></v>
<v t="ekr.20241213022536.92"><vh>rcParams['figure.figsize'] = [12, 8]</vh></v>
<v t="ekr.20241213022536.93"><vh>fig,ax = plt.subplots(1,1,subplot_kw={'p</vh></v>
<v t="ekr.20241213022536.94"><vh># Alternating Descent</vh></v>
<v t="ekr.20241213022536.95"><vh>rcParams['figure.figsize'] = [12, 8]</vh></v>
<v t="ekr.20241213022536.96"><vh>fig,ax = plt.subplots(1,1,subplot_kw={'p</vh></v>
<v t="ekr.20241213022536.97"><vh>Cell 13</vh></v>
</v>
<v t="ekr.20241213022536.98"><vh># @file CH04\CH04_SEC03_1_OverUnderDetermined.py</vh>
<v t="ekr.20241213022536.100"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.101"><vh>Underdetermined</vh></v>
<v t="ekr.20241213022536.102"><vh>plt.rcParams['figure.figsize'] = [12, 8]</vh></v>
<v t="ekr.20241213022536.103"><vh>Overdetermined</vh></v>
<v t="ekr.20241213022536.104"><vh># Matrix Overdetermined System</vh></v>
<v t="ekr.20241213022536.105"><vh>Cell 6</vh></v>
</v>
<v t="ekr.20241213022536.106"><vh># @file CH04\CH04_SEC04_1_CompareRegression.py</vh>
<v t="ekr.20241213022536.108"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.109"><vh>n = 100</vh></v>
<v t="ekr.20241213022536.110"><vh># Different regressions</vh></v>
<v t="ekr.20241213022536.111"><vh>plt.rcParams['figure.figsize'] = [12,</vh></v>
<v t="ekr.20241213022536.112"><vh>M = 10</vh></v>
<v t="ekr.20241213022536.113"><vh>Cell 6</vh></v>
</v>
<v t="ekr.20241213022536.114"><vh># @file CH04\CH04_SEC05_0_Fig4p16_Pareto.py</vh>
<v t="ekr.20241213022536.116"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.117"><vh>fig,ax = plt.subplots(1)</vh></v>
<v t="ekr.20241213022536.118"><vh>Cell 3</vh></v>
</v>
<v t="ekr.20241213022536.119"><vh># @file CH04\CH04_SEC05_1_CrossValidate.py</vh>
<v t="ekr.20241213022536.121"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.122"><vh>n = 200</vh></v>
<v t="ekr.20241213022536.123"><vh>fig,axs = plt.subplots(2,2)</vh></v>
<v t="ekr.20241213022536.124"><vh>Cell 4</vh></v>
</v>
<v t="ekr.20241213022536.125"><vh># @file CH04\CH04_SEC06_1_kFoldValidation.py</vh>
<v t="ekr.20241213022536.127"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.128"><vh>n = 100</vh></v>
<v t="ekr.20241213022536.129"><vh>plt.rcParams['figure.figsize'] = [8,8]</vh></v>
<v t="ekr.20241213022536.130"><vh>n = 200</vh></v>
<v t="ekr.20241213022536.131"><vh>Cell 5</vh></v>
</v>
<v t="ekr.20241213022536.132"><vh># @file CH04\CH04_SEC07_1_ModelValidation.py</vh>
<v t="ekr.20241213022536.134"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.135"><vh>n = 10000</vh></v>
<v t="ekr.20241213022536.136"><vh>generate PDFs</vh></v>
<v t="ekr.20241213022536.137"><vh>Compute integrand</vh></v>
<v t="ekr.20241213022536.138"><vh>Cell 5</vh></v>
</v>
<v t="ekr.20241213022536.139"><vh># @file CH04\CH04_SEC07_2_RegressAIC_BIC.py</vh>
<v t="ekr.20241213022536.141"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.142"><vh>for random data reproducibility</vh></v>
<v t="ekr.20241213022536.143"><vh>Cell 3</vh></v>
</v>
</v>
<v t="ekr.20241213022536.144"><vh>CH05</vh>
<v t="ekr.20241213022536.145"><vh># @file CH05\CH05_SEC01_1_FischerExtraction.py</vh>
<v t="ekr.20241213022536.147"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.148"><vh>fisheriris_mat = io.loadmat(os.path.join</vh></v>
<v t="ekr.20241213022536.149"><vh>fig = plt.figure()</vh></v>
<v t="ekr.20241213022536.150"><vh>dogdata_mat = io.loadmat(os.path.join('.</vh></v>
<v t="ekr.20241213022536.151"><vh>fig,axs = plt.subplots(2,2)</vh></v>
<v t="ekr.20241213022536.152"><vh>fig,axs = plt.subplots(4,1)</vh></v>
<v t="ekr.20241213022536.153"><vh>fig,axs = plt.subplots(2,2)</vh></v>
<v t="ekr.20241213022536.154"><vh>fig,axs = plt.subplots(2,2)</vh></v>
<v t="ekr.20241213022536.155"><vh>fig,axs = plt.subplots(4,1)</vh></v>
<v t="ekr.20241213022536.156"><vh>xbin = np.linspace(-0.25,0.25,20)</vh></v>
<v t="ekr.20241213022536.157"><vh>fig = plt.figure()</vh></v>
<v t="ekr.20241213022536.158"><vh>master = np.zeros((32*5,32*4))</vh></v>
<v t="ekr.20241213022536.159"><vh>master = np.zeros((32*5,32*4))</vh></v>
<v t="ekr.20241213022536.160"><vh>Cell 14</vh></v>
</v>
<v t="ekr.20241213022536.161"><vh># @file CH05\CH05_SEC02_1_Fig5p7_Fig5p8.py</vh>
<v t="ekr.20241213022536.163"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.164"><vh>Training and test set sizes</vh></v>
<v t="ekr.20241213022536.165"><vh>fig,axs = plt.subplots(2,2)</vh></v>
<v t="ekr.20241213022536.166"><vh>training set size</vh></v>
<v t="ekr.20241213022536.167"><vh>Cell 5</vh></v>
</v>
<v t="ekr.20241213022536.168"><vh># @file CH05\CH05_SEC03_1_Kmeans.py</vh>
<v t="ekr.20241213022536.170"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.171"><vh>Training and testing set sizes</vh></v>
<v t="ekr.20241213022536.172"><vh>plt.figure()</vh></v>
<v t="ekr.20241213022536.173"><vh>Training set: first 200 of 240 points</vh></v>
<v t="ekr.20241213022536.174"><vh>Initial guess</vh></v>
<v t="ekr.20241213022536.175"><vh>kmeans code</vh></v>
<v t="ekr.20241213022536.176"><vh>midx = (c[0,0]+c[1,0])/2</vh></v>
<v t="ekr.20241213022536.177"><vh># Dendrograms</vh></v>
<v t="ekr.20241213022536.178"><vh>plt.bar(range(100),dn['leaves'])</vh></v>
<v t="ekr.20241213022536.179"><vh>Cell 10</vh></v>
</v>
<v t="ekr.20241213022536.180"><vh># @file CH05\CH05_SEC04_1_Dendrogram.py</vh>
<v t="ekr.20241213022536.182"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.183"><vh>Training and testing set sizes</vh></v>
<v t="ekr.20241213022536.184"><vh>plt.figure()</vh></v>
<v t="ekr.20241213022536.185"><vh>Training set: first 200 of 240 points</vh></v>
<v t="ekr.20241213022536.186"><vh># Dendrograms</vh></v>
<v t="ekr.20241213022536.187"><vh>plt.bar(range(100),dn['leaves'])</vh></v>
<v t="ekr.20241213022536.188"><vh>thresh = 0.25*np.max(Z[:,2])</vh></v>
<v t="ekr.20241213022536.189"><vh>Cell 8</vh></v>
<v t="ekr.20241213022536.190"><vh>Cell 9</vh></v>
</v>
<v t="ekr.20241213022536.191"><vh># @file CH05\CH05_SEC05_1_GaussianMixtureModels.py</vh>
<v t="ekr.20241213022536.193"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.194"><vh>dogdata_w_mat = io.loadmat(os.path.join(</vh></v>
<v t="ekr.20241213022536.195"><vh>dogcat = v[:,(1,3)]</vh></v>
<v t="ekr.20241213022536.196"><vh>ax = plt.axes(projection='3d')</vh></v>
<v t="ekr.20241213022536.197"><vh># AIC Scores</vh></v>
<v t="ekr.20241213022536.198"><vh>Cell 6</vh></v>
</v>
<v t="ekr.20241213022536.199"><vh># @file CH05\CH05_SEC06_1_LDA_Classify.py</vh>
<v t="ekr.20241213022536.201"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.202"><vh>dogdata_w_mat = io.loadmat(os.path.join(</vh></v>
<v t="ekr.20241213022536.203"><vh>xtrain = np.concatenate((v[:60,np.array(</vh></v>
<v t="ekr.20241213022536.204"><vh>plt.rcParams['figure.figsize'] = [8,4]</vh></v>
<v t="ekr.20241213022536.205"><vh>dogdata_mat = io.loadmat(os.path.join('.</vh></v>
<v t="ekr.20241213022536.206"><vh>plt.rcParams['figure.figsize'] = [12,</vh></v>
<v t="ekr.20241213022536.207"><vh># Cross-validate</vh></v>
<v t="ekr.20241213022536.208"><vh>dogdata_w_mat = io.loadmat(os.path.join(</vh></v>
<v t="ekr.20241213022536.209"><vh>plt.rcParams['figure.figsize'] = [12, 6]</vh></v>
<v t="ekr.20241213022536.210"><vh>Cell 10</vh></v>
</v>
<v t="ekr.20241213022536.211"><vh># @file CH05\CH05_SEC07_1_SVM.py</vh>
<v t="ekr.20241213022536.213"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.214"><vh>Random ellipse 1</vh></v>
<v t="ekr.20241213022536.215"><vh>z1 = np.power(x1,2) * y1</vh></v>
<v t="ekr.20241213022536.216"><vh>r = 7 + np.random.randn(n1)</vh></v>
<v t="ekr.20241213022536.217"><vh>Classify dogs vs. cats</vh></v>
<v t="ekr.20241213022536.218"><vh>features = np.arange(1,21)</vh></v>
<v t="ekr.20241213022536.219"><vh>Cell 7</vh></v>
</v>
<v t="ekr.20241213022536.220"><vh># @file CH05\CH05_SEC08_1_Trees.py</vh>
<v t="ekr.20241213022536.222"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.223"><vh>fisheriris_mat = io.loadmat(os.path.join</vh></v>
<v t="ekr.20241213022536.224"><vh>setosa</vh></v>
<v t="ekr.20241213022536.225"><vh>dogs vs. cats</vh></v>
<v t="ekr.20241213022536.226"><vh># Census Data</vh></v>
<v t="ekr.20241213022536.227"><vh># Splitting Procedure</vh></v>
<v t="ekr.20241213022536.228"><vh>plt.plot(x1[:,0],x1[:,1],'o',markerfacec</vh></v>
<v t="ekr.20241213022536.229"><vh>Cell 8</vh></v>
</v>
</v>
<v t="ekr.20241213022536.230"><vh>CH06</vh>
<v t="ekr.20241213022536.231"><vh># @file CH06\CH06_SEC01_1_NN.py</vh>
<v t="ekr.20241213022536.233"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.234"><vh>dogs vs. cats</vh></v>
<v t="ekr.20241213022536.235"><vh>lasso =</vh></v>
<v t="ekr.20241213022536.236"><vh>fig,axs = plt.subplots(4,1)</vh></v>
<v t="ekr.20241213022536.237"><vh>fig,axs = plt.subplots(2,2)</vh></v>
<v t="ekr.20241213022536.238"><vh># To be implemented: Python version of</vh></v>
<v t="ekr.20241213022536.239"><vh>Cell 7</vh></v>
<v t="ekr.20241213022536.240"><vh>Cell 8</vh></v>
</v>
<v t="ekr.20241213022536.241"><vh># @file CH06\CH06_SEC04_1_StochasticGradientDescent.py</vh>
<v t="ekr.20241213022536.243"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022536.244"><vh>iterMax = 100</vh></v>
<v t="ekr.20241213022536.245"><vh>plt.figure()</vh></v>
<v t="ekr.20241213022536.246"><vh>fig,ax = plt.subplots(1,1,subplot_kw={'p</vh></v>
<v t="ekr.20241213022536.247"><vh>Cell 5</vh></v>
<v t="ekr.20241213022536.248"><vh>Cell 6</vh></v>
</v>
<v t="ekr.20241213022537.1"><vh># @file CH06\CH06_SEC05_1_DeepCNN.py</vh>
<v t="ekr.20241213022537.3"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.4"><vh>letters_train_mat = io.loadmat(os.path.j</vh></v>
<v t="ekr.20241213022537.5"><vh>classes = np.unique(TTrain)</vh></v>
<v t="ekr.20241213022537.6"><vh>create model</vh></v>
<v t="ekr.20241213022537.7"><vh>YPredict =</vh></v>
<v t="ekr.20241213022537.8"><vh>Cell 6</vh></v>
<v t="ekr.20241213022537.9"><vh>Cell 7</vh></v>
</v>
<v t="ekr.20241213022537.10"><vh># @file CH06\CH06_SEC06_1_NNLorenz.py</vh>
<v t="ekr.20241213022537.12"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.13"><vh># Simulate the Lorenz System</vh></v>
<v t="ekr.20241213022537.14"><vh># Neural Net</vh></v>
<v t="ekr.20241213022537.15"><vh>nn_input.shape</vh></v>
<v t="ekr.20241213022537.16"><vh>Cell 5</vh></v>
</v>
</v>
<v t="ekr.20241213022537.17"><vh>CH07</vh>
<v t="ekr.20241213022537.18"><vh># @file CH07\CH07_SEC01_SimulateLogistic.py</vh>
<v t="ekr.20241213022537.20"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.21"><vh>startval = 1</vh></v>
<v t="ekr.20241213022537.22"><vh>plt.plot(xvals[1,:],xvals[0,:],'.',ms=0.</vh></v>
<v t="ekr.20241213022537.23"><vh>plt.plot(xvals[1,:],xvals[0,:],'.',ms=0.</vh></v>
<v t="ekr.20241213022537.24"><vh>Cell 5</vh></v>
</v>
<v t="ekr.20241213022537.25"><vh># @file CH07\CH07_SEC01_SimulateLorenz.py</vh>
<v t="ekr.20241213022537.27"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.28"><vh># Simulate the Lorenz System</vh></v>
<v t="ekr.20241213022537.29"><vh>Cell 3</vh></v>
<v t="ekr.20241213022537.30"><vh>Cell 4</vh></v>
</v>
<v t="ekr.20241213022537.31"><vh># @file CH07\CH07_SEC02_DMD_Cylinder.py</vh>
<v t="ekr.20241213022537.33"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.34"><vh>vortall_mat = io.loadmat(os.path.join('.</vh></v>
<v t="ekr.20241213022537.35"><vh>def DMD(X,Xprime,r):</vh></v>
<v t="ekr.20241213022537.36"><vh>Phi, Lambda, b =</vh></v>
<v t="ekr.20241213022537.37"><vh># Plot Mode 2</vh></v>
<v t="ekr.20241213022537.38"><vh>V2 =</vh></v>
<v t="ekr.20241213022537.39"><vh>Cell 7</vh></v>
<v t="ekr.20241213022537.40"><vh>Cell 8</vh></v>
</v>
<v t="ekr.20241213022537.41"><vh># @file CH07\CH07_SEC03_SINDY_Lorenz.py</vh>
<v t="ekr.20241213022537.43"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.44"><vh># Simulate the Lorenz System</vh></v>
<v t="ekr.20241213022537.45"><vh># Compute Derivative</vh></v>
<v t="ekr.20241213022537.46"><vh># SINDy Function Definitions</vh></v>
<v t="ekr.20241213022537.47"><vh>Up to third order polynomials</vh></v>
<v t="ekr.20241213022537.48"><vh>Cell 6</vh></v>
</v>
<v t="ekr.20241213022537.49"><vh># @file CH07\CH07_SEC04_Koopman.py</vh>
<v t="ekr.20241213022537.51"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.52"><vh>mu = -0.05</vh></v>
<v t="ekr.20241213022537.53"><vh># Integrate Koopman trajectories</vh></v>
<v t="ekr.20241213022537.54"><vh># Plot invariant surfaces</vh></v>
<v t="ekr.20241213022537.55"><vh>Cell 5</vh></v>
<v t="ekr.20241213022537.56"><vh>Cell 6</vh></v>
</v>
<v t="ekr.20241213022537.57"><vh># @file CH07\CH07_SEC05_HAVOK_Lorenz.py</vh>
<v t="ekr.20241213022537.59"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.60"><vh># Simulate the Lorenz System</vh></v>
<v t="ekr.20241213022537.61"><vh># Eigen-time delay coordinates</vh></v>
<v t="ekr.20241213022537.62"><vh># Compute Derivatives (4th Order Central</vh></v>
<v t="ekr.20241213022537.63"><vh># Build HAVOK Regression Model on Time</vh></v>
<v t="ekr.20241213022537.64"><vh>print(1/2/3)</vh></v>
<v t="ekr.20241213022537.65"><vh>Cell 7</vh></v>
</v>
</v>
<v t="ekr.20241213022537.66"><vh>CH08</vh>
<v t="ekr.20241213022537.67"><vh># @file CH08\CH08_SEC01_CruiseControl.py</vh>
<v t="ekr.20241213022537.69"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.70"><vh>time</vh></v>
<v t="ekr.20241213022537.71"><vh>plt.plot(t,wr,'k',linewidth=2,label='Ref</vh></v>
<v t="ekr.20241213022537.72"><vh>Cell 4</vh></v>
</v>
<v t="ekr.20241213022537.73"><vh># @file CH08\CH08_SEC07_1_LQR.py</vh>
<v t="ekr.20241213022537.75"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.76"><vh>m = 1</vh></v>
<v t="ekr.20241213022537.77"><vh># Design LQR Controller</vh></v>
<v t="ekr.20241213022537.78"><vh># ODE RHS Function Definition</vh></v>
<v t="ekr.20241213022537.79"><vh># Simulate closed-loop system</vh></v>
<v t="ekr.20241213022537.80"><vh>for k in range(np.floor(len(t)/100)):</vh></v>
<v t="ekr.20241213022537.81"><vh>fig,ax = plt.subplots()</vh></v>
<v t="ekr.20241213022537.82"><vh>plot_labels = ('x','v','theta','omega')</vh></v>
<v t="ekr.20241213022537.83"><vh># Compare with many examples of Pole</vh></v>
<v t="ekr.20241213022537.84"><vh># Plots</vh></v>
<v t="ekr.20241213022537.85"><vh>for count in range(100):</vh></v>
</v>
<v t="ekr.20241213022537.86"><vh># @file CH08\CH08_SEC07_2b_Obsv.py</vh>
<v t="ekr.20241213022537.88"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.89"><vh>m = 1</vh></v>
<v t="ekr.20241213022537.90"><vh># Which measurements are best if we omit</vh></v>
<v t="ekr.20241213022537.91"><vh>Cell 4</vh></v>
</v>
<v t="ekr.20241213022537.92"><vh># @file CH08\CH08_SEC07_2_KalmanFilter.py</vh>
<v t="ekr.20241213022537.94"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.95"><vh>m = 1</vh></v>
<v t="ekr.20241213022537.96"><vh>Kalman estimator design</vh></v>
<v t="ekr.20241213022537.97"><vh># Specify disturbance and noise</vh></v>
<v t="ekr.20241213022537.98"><vh># Augment system with additional inputs</vh></v>
<v t="ekr.20241213022537.99"><vh># Estimate linearized system in "down"</vh></v>
<v t="ekr.20241213022537.100"><vh>plt.plot(t,y,color=(0.5,0.5,0.5),label='</vh></v>
<v t="ekr.20241213022537.101"><vh>x_labels = ('x','v','theta','omega')</vh></v>
<v t="ekr.20241213022537.102"><vh>Cell 9</vh></v>
</v>
<v t="ekr.20241213022537.103"><vh># @file CH08\CH08_SEC08_1_TransferFunction.py</vh>
<v t="ekr.20241213022537.105"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.106"><vh>s = tf(np.array([1,0]),np.array([0,1]))</vh></v>
<v t="ekr.20241213022537.107"><vh>A = np.array([[0,1],[-2,-1]])</vh></v>
<v t="ekr.20241213022537.108"><vh>Cell 4</vh></v>
</v>
<v t="ekr.20241213022537.109"><vh># @file CH08\CH08_SEC08_2_SandT.py</vh>
<v t="ekr.20241213022537.111"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.112"><vh>s = tf(np.array([1,0]),np.array([0,1]))</vh></v>
<v t="ekr.20241213022537.113"><vh>Cell 3</vh></v>
</v>
<v t="ekr.20241213022537.114"><vh># @file CH08\CH08_SEC08_3_PlantInversion.py</vh>
<v t="ekr.20241213022537.116"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.117"><vh>s = tf(np.array([1,0]),np.array([0,1]))</vh></v>
<v t="ekr.20241213022537.118"><vh>Cell 3</vh></v>
<v t="ekr.20241213022537.119"><vh>Cell 4</vh></v>
</v>
</v>
<v t="ekr.20241213022537.120"><vh>CH09</vh>
<v t="ekr.20241213022537.121"><vh># @file CH09\CH09_SEC02_1_GramianPlot.py</vh>
<v t="ekr.20241213022537.123"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.124"><vh>A = np.array([[-0.75,1],[-0.3,-0.75]])</vh></v>
<v t="ekr.20241213022537.125"><vh>Manually compute transform matrix for</vh></v>
<v t="ekr.20241213022537.126"><vh># Plot Gramians</vh></v>
<v t="ekr.20241213022537.127"><vh>plt.plot(xc,yc,'k--',linewidth=2)</vh></v>
<v t="ekr.20241213022537.128"><vh>Cell 6</vh></v>
</v>
<v t="ekr.20241213022537.129"><vh># @file CH09\CH09_SEC02_2_BalancedTruncation.py</vh>
<v t="ekr.20241213022537.131"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.132"><vh>testSys_mat = io.loadmat(os.path.join('.</vh></v>
<v t="ekr.20241213022537.133"><vh># Plot Hankel Singular Values</vh></v>
<v t="ekr.20241213022537.134"><vh>Balanced truncation</vh></v>
<v t="ekr.20241213022537.135"><vh>Compute BPOD</vh></v>
<v t="ekr.20241213022537.136"><vh># Plot impulse responses for all methods</vh></v>
<v t="ekr.20241213022537.137"><vh>Cell 7</vh></v>
</v>
<v t="ekr.20241213022537.138"><vh># @file CH09\CH09_SEC03_ERA_OKID.py</vh>
<v t="ekr.20241213022537.140"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.141"><vh>Number of inputs</vh></v>
<v t="ekr.20241213022537.142"><vh>yFull = np.zeros((r*5+2,p,q))</vh></v>
<v t="ekr.20241213022537.143"><vh># ERA and OKID Function Definitions</vh></v>
<v t="ekr.20241213022537.144"><vh># Compute ERA from impulse response</vh></v>
<v t="ekr.20241213022537.145"><vh># Compute random input simulation for</vh></v>
<v t="ekr.20241213022537.146"><vh># Compute OKID and then ERA</vh></v>
<v t="ekr.20241213022537.147"><vh># Plot impulse responses for all methods</vh></v>
<v t="ekr.20241213022537.148"><vh># Plot input/output pair for OKID</vh></v>
<v t="ekr.20241213022537.149"><vh>uRandom.shape</vh></v>
<v t="ekr.20241213022537.150"><vh>Cell 11</vh></v>
</v>
<v t="ekr.20241213022537.151"><vh># @file CH09\CH09_SEC03_Fig9p5.py</vh>
<v t="ekr.20241213022537.153"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.154"><vh>Number of inputs</vh></v>
<v t="ekr.20241213022537.155"><vh># Figure 1 = simple impulse response</vh></v>
<v t="ekr.20241213022537.156"><vh>plt.step(t,u,'k',linewidth=1.5)</vh></v>
<v t="ekr.20241213022537.157"><vh>plt.step(t,y,'k',linewidth=1.5)</vh></v>
<v t="ekr.20241213022537.158"><vh># FIgure 2 - OKID response</vh></v>
<v t="ekr.20241213022537.159"><vh>plt.step(t,u,'k',linewidth=1.5)</vh></v>
<v t="ekr.20241213022537.160"><vh>plt.step(t,y,'k',linewidth=1.5)</vh></v>
</v>
</v>
<v t="ekr.20241213022537.161"><vh>CH10</vh>
<v t="ekr.20241213022537.162"><vh># @file CH10\CH10_SEC03_ESCfixed.py</vh>
<v t="ekr.20241213022537.164"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.165"><vh>J = lambda u,t: (25-np.power((5-u),2))</vh></v>
<v t="ekr.20241213022537.166"><vh># Extremum Seeking Control Parameters</vh></v>
<v t="ekr.20241213022537.167"><vh># High pass filter (Butterworth filter)</vh></v>
<v t="ekr.20241213022537.168"><vh># Figures</vh></v>
<v t="ekr.20241213022537.169"><vh>Cell 6</vh></v>
<v t="ekr.20241213022537.170"><vh>Cell 7</vh></v>
</v>
<v t="ekr.20241213022537.171"><vh># @file CH10\CH10_SEC03_ESCsinusoidal.py</vh>
<v t="ekr.20241213022537.173"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022537.174"><vh>J = lambda u,t:</vh></v>
<v t="ekr.20241213022537.175"><vh># Extremum Seeking Control Parameters</vh></v>
<v t="ekr.20241213022537.176"><vh># High pass filter (Butterworth filter)</vh></v>
<v t="ekr.20241213022537.177"><vh># Figures</vh></v>
<v t="ekr.20241213022537.178"><vh>Cell 6</vh></v>
</v>
</v>
<v t="ekr.20241213022538.1"><vh>CH11</vh>
<v t="ekr.20241213022538.2"><vh># @file CH11\CH11_SEC01_1_Fig11p1.py</vh>
<v t="ekr.20241213022538.4"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022538.5"><vh>L = 20</vh></v>
<v t="ekr.20241213022538.6"><vh>fig,axs = plt.subplots(1,2)</vh></v>
<v t="ekr.20241213022538.7"><vh>ut21 = np.zeros(n,dtype='complex_')</vh></v>
<v t="ekr.20241213022538.8"><vh>plt.semilogy(erx,er3,'b',linewidth=2)</vh></v>
<v t="ekr.20241213022538.9"><vh>Cell 6</vh></v>
</v>
<v t="ekr.20241213022538.10"><vh># @file CH11\CH11_SEC02_1_HarmonicOscillator.py</vh>
<v t="ekr.20241213022538.12"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022538.13"><vh>L = 30</vh></v>
<v t="ekr.20241213022538.14"><vh>def harm_rhs(ut_split,t,k=k,V=V,n=n):</vh></v>
<v t="ekr.20241213022538.15"><vh>initial conditions</vh></v>
<v t="ekr.20241213022538.16"><vh>initial conditions</vh></v>
<v t="ekr.20241213022538.17"><vh>ax = Axes3D(plt.figure())</vh></v>
<v t="ekr.20241213022538.18"><vh>ax = Axes3D(plt.figure())</vh></v>
<v t="ekr.20241213022538.19"><vh>usol3 = np.zeros_like(usol)</vh></v>
<v t="ekr.20241213022538.20"><vh>plt.plot(100*S/np.sum(S),'ko',linewidth=</vh></v>
<v t="ekr.20241213022538.21"><vh>plt.plot(100*S2/np.sum(S2),'ko',linewidt</vh></v>
<v t="ekr.20241213022538.22"><vh>fig,axs = plt.subplots(3,1)</vh></v>
<v t="ekr.20241213022538.23"><vh>Cell 12</vh></v>
</v>
<v t="ekr.20241213022538.24"><vh># @file CH11\CH11_SEC03_1_NonlinearSchrodinger.py</vh>
<v t="ekr.20241213022538.26"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022538.27"><vh>L = 40</vh></v>
<v t="ekr.20241213022538.28"><vh>def nls_rhs(ut_split,t,k=k):</vh></v>
<v t="ekr.20241213022538.29"><vh>N = 1</vh></v>
<v t="ekr.20241213022538.30"><vh>N = 2</vh></v>
<v t="ekr.20241213022538.31"><vh>fig = plt.figure()</vh></v>
<v t="ekr.20241213022538.32"><vh>U,S,VT = np.linalg.svd(usol.T)</vh></v>
<v t="ekr.20241213022538.33"><vh>plt.rcParams['figure.figsize'] = [12, 6]</vh></v>
<v t="ekr.20241213022538.34"><vh>color_list = ['b','g','r']</vh></v>
<v t="ekr.20241213022538.35"><vh>for jj in range(3):</vh></v>
<v t="ekr.20241213022538.36"><vh>Cell 11</vh></v>
</v>
<v t="ekr.20241213022538.37"><vh># @file CH11\CH11_SEC05_1_Invariance.py</vh>
<v t="ekr.20241213022538.39"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022538.40"><vh>L = 20</vh></v>
<v t="ekr.20241213022538.41"><vh>U,S,VT =</vh></v>
<v t="ekr.20241213022538.42"><vh>fig, axs = plt.subplots(2,1)</vh></v>
<v t="ekr.20241213022538.43"><vh>plt.rcParams['figure.figsize'] = [12,</vh></v>
<v t="ekr.20241213022538.44"><vh>u = np.tanh(np.sqrt(np.power(X,2)+np.pow</vh></v>
<v t="ekr.20241213022538.45"><vh># Translation</vh></v>
<v t="ekr.20241213022538.46"><vh>plt.rcParams['figure.figsize'] = [12,12]</vh></v>
<v t="ekr.20241213022538.47"><vh>U2,S2,V2T = np.linalg.svd(X)</vh></v>
<v t="ekr.20241213022538.48"><vh>Cell 10</vh></v>
</v>
</v>
<v t="ekr.20241213022538.49"><vh>CH12</vh>
<v t="ekr.20241213022538.50"><vh># @file CH12\CH12_SEC01_1_GAPPY.py</vh>
<v t="ekr.20241213022538.52"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022538.53"><vh>define domain</vh></v>
<v t="ekr.20241213022538.54"><vh>plt.rcParams['figure.figsize'] = [12,12]</vh></v>
<v t="ekr.20241213022538.55"><vh>plt.rcParams['figure.figsize'] = [12,12]</vh></v>
<v t="ekr.20241213022538.56"><vh>fig,axs = plt.subplots(2,2)</vh></v>
<v t="ekr.20241213022538.57"><vh>plt.rcParams['figure.figsize'] = [12,6]</vh></v>
<v t="ekr.20241213022538.58"><vh>Cell 7</vh></v>
</v>
<v t="ekr.20241213022538.59"><vh># @file CH12\CH12_SEC02_1_GAPPY.py</vh>
<v t="ekr.20241213022538.61"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022538.62"><vh>define domain</vh></v>
<v t="ekr.20241213022538.63"><vh>n = len(x)</vh></v>
<v t="ekr.20241213022538.64"><vh># Test Random trials with P% of</vh></v>
<v t="ekr.20241213022538.65"><vh>fig,axs = plt.subplots(2,1)</vh></v>
<v t="ekr.20241213022538.66"><vh># For 20% measurements, sort great from</vh></v>
<v t="ekr.20241213022538.67"><vh>fig,axs = plt.subplots(3,1)</vh></v>
<v t="ekr.20241213022538.68"><vh>fig, ax = plt.subplots(1,1)</vh></v>
<v t="ekr.20241213022538.69"><vh>jloc = np.argsort(co)</vh></v>
<v t="ekr.20241213022538.70"><vh>m = 30</vh></v>
<v t="ekr.20241213022538.71"><vh>Cell 11</vh></v>
</v>
<v t="ekr.20241213022538.72"><vh># @file CH12\CH12_SEC03_1_GAPPY_ConditionNumber.py</vh>
<v t="ekr.20241213022538.74"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022538.75"><vh>define domain</vh></v>
<v t="ekr.20241213022538.76"><vh># Method 1 -- Condition Number</vh></v>
<v t="ekr.20241213022538.77"><vh>plt.rcParams['figure.figsize'] = [12,10]</vh></v>
<v t="ekr.20241213022538.78"><vh>titer = np.arange(1,21)</vh></v>
<v t="ekr.20241213022538.79"><vh>plt.rcParams['figure.figsize'] = [12,6]</vh></v>
<v t="ekr.20241213022538.80"><vh># Method 2 -- Max Diagonal vs. Off-</vh></v>
<v t="ekr.20241213022538.81"><vh>plt.rcParams['figure.figsize'] = [12,10]</vh></v>
<v t="ekr.20241213022538.82"><vh># Method 1 -- First 4 Condition Number</vh></v>
<v t="ekr.20241213022538.83"><vh>Cell 10</vh></v>
</v>
<v t="ekr.20241213022538.84"><vh># @file CH12\CH12_SEC04_1_GAPPY_Variance.py</vh>
<v t="ekr.20241213022538.86"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022538.87"><vh>define domain</vh></v>
<v t="ekr.20241213022538.88"><vh># Method 1 -- Start with max of each</vh></v>
<v t="ekr.20241213022538.89"><vh># Method 2 -- Start with max and mins of</vh></v>
<v t="ekr.20241213022538.90"><vh># Method 3 -- Search for extrema, then</vh></v>
<v t="ekr.20241213022538.91"><vh># select random 20 - shuffle</vh></v>
<v t="ekr.20241213022538.92"><vh># Method to compare -- Willcox condition</vh></v>
<v t="ekr.20241213022538.93"><vh>fig,axs = plt.subplots(3,1)</vh></v>
<v t="ekr.20241213022538.94"><vh>titer = np.arange(1,21)</vh></v>
<v t="ekr.20241213022538.95"><vh>plt.rcParams['figure.figsize'] = [12,6]</vh></v>
<v t="ekr.20241213022538.96"><vh>Cell 11</vh></v>
</v>
<v t="ekr.20241213022538.97"><vh># @file CH12\CH12_SEC06_1_DEIM.py</vh>
<v t="ekr.20241213022538.99"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022538.100"><vh>spatial discretization</vh></v>
<v t="ekr.20241213022538.101"><vh>def ch_pod_sol_rhs(ut_split,t,k=k):</vh></v>
<v t="ekr.20241213022538.102"><vh>N = 2</vh></v>
<v t="ekr.20241213022538.103"><vh>fig = plt.figure()</vh></v>
<v t="ekr.20241213022538.104"><vh>data matrix X</vh></v>
<v t="ekr.20241213022538.105"><vh>NL = (1j)*np.power(np.abs(X),2)*X</vh></v>
<v t="ekr.20241213022538.106"><vh>nonlinear projection</vh></v>
<v t="ekr.20241213022538.107"><vh>def rom_deim_rhs(a_split,tspan,P_NL=P_NL</vh></v>
<v t="ekr.20241213022538.108"><vh>Separate real/complex pieces</vh></v>
<v t="ekr.20241213022538.109"><vh>fig = plt.figure()</vh></v>
<v t="ekr.20241213022538.110"><vh># QR DEIM</vh></v>
<v t="ekr.20241213022538.111"><vh>Cell 13</vh></v>
<v t="ekr.20241213022538.112"><vh>Cell 14</vh></v>
</v>
<v t="ekr.20241213022538.113"><vh># @file CH12\CH12_SEC06_2_DEIM.py</vh>
<v t="ekr.20241213022538.115"><vh>import numpy as np</vh></v>
<v t="ekr.20241213022538.116"><vh>spatial discretization</vh></v>
<v t="ekr.20241213022538.117"><vh>def ch_pod_sol_rhs(ut_split,t,k=k):</vh></v>
<v t="ekr.20241213022538.118"><vh>N = 2</vh></v>
<v t="ekr.20241213022538.119"><vh>fig = plt.figure()</vh></v>
<v t="ekr.20241213022538.120"><vh>data matrix X</vh></v>
<v t="ekr.20241213022538.121"><vh>NL = (1j)*np.power(np.abs(X),2)*X</vh></v>
<v t="ekr.20241213022538.122"><vh>nonlinear projection</vh></v>
<v t="ekr.20241213022538.123"><vh>def rom_deim_rhs(a_split,tspan,P_NL=P_NL</vh></v>
<v t="ekr.20241213022538.124"><vh>Separate real/complex pieces</vh></v>
<v t="ekr.20241213022538.125"><vh>fig = plt.figure()</vh></v>
<v t="ekr.20241213022538.126"><vh>plt.plot(x,-np.real(Psi[:,:3]))</vh></v>
<v t="ekr.20241213022538.127"><vh># QR compare</vh></v>
<v t="ekr.20241213022538.128"><vh>Cell 14</vh></v>
</v>
</v>
</v>
</vnodes>
<tnodes>
<t tx="ekr.20241212164526.14">"""Execute one .py file externally."""
g.cls()
import os
# Must execute the script in the proper folder.
dir_ = os.path.dirname(c.fileName())
os.chdir(dir_) # r'C:\Users\Dev\EKR-Study\python\CODE_PYTHON'
# All the sections have a common naming convention.
chapter = 'CH01'
section = r'SEC03_Rotation.py'
path = fr'{chapter}/{chapter}_{section}'
# No need to hang Leo.
g.execute_shell_commands(f"&python {path}")
</t>
<t tx="ekr.20241212164526.16"># pyflakes generated these warnings when saving "live" versions of the converted files.
tbo: beautified: CH01_SEC02.py
tbo: beautified: CH01_SEC03_Rotation.py
CH01_SEC03_Rotation.py:24:1: 'mpl_toolkits.mplot3d.Axes3D' imported but unused
tbo: beautified: CH01_SEC04_1_Linear.py
tbo: beautified: CH01_SEC04_2_Cement.py
tbo: beautified: CH01_SEC04_3_Housing.py
tbo: beautified: CH01_SEC05_1_PCAGaussian.py
tbo: beautified: CH01_SEC05_2_OvarianCancer.py
CH01_SEC05_2_OvarianCancer.py:25:1: 'mpl_toolkits.mplot3d.Axes3D' imported but unused
tbo: beautified: CH01_SEC06_1.py
tbo: beautified: CH01_SEC06_2_3_4.py
tbo: beautified: CH01_SEC07_1.py
tbo: beautified: CH01_SEC07_2.py
CH01_SEC07_2.py:24:1: 'scipy.misc' imported but unused
CH01_SEC07_2.py:42:9: undefined name 'skimage'
CH01_SEC07_2.py:46:12: undefined name 'Y'
tbo: beautified: CH01_SEC07_3.py
CH01_SEC07_3.py:23:1: 'matplotlib.cm' imported but unused
tbo: beautified: CH01_SEC08_RSVD.py
tbo: beautified: CH01_SEC09_Tensor.py
CH01_SEC09_Tensor.py:24:1: 'os' imported but unused
CH01_SEC09_Tensor.py:25:1: 'matplotlib.rc' imported but unused
CH01_SEC03_Rotation.py:24:1: 'mpl_toolkits.mplot3d.Axes3D' imported but unused
CH01_SEC05_2_OvarianCancer.py:25:1: 'mpl_toolkits.mplot3d.Axes3D' imported but unused