-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath.tex
More file actions
1673 lines (1321 loc) · 59.6 KB
/
math.tex
File metadata and controls
1673 lines (1321 loc) · 59.6 KB
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LaTeX Template: Two Column Colour Article
%
% Source: http://www.howtotex.com/
% Feel free to distribute this template, but please keep the
% referal to howtotex.com.
% Date: Feb 2011
%
%%% Preamble
\documentclass[ DIV=calc,%
paper=a4,%
fontsize=11pt,%
twocolumn]{scrartcl} % KOMA-article class
\usepackage{lipsum} % Package to create dummy text
\usepackage[english]{babel} % English language/hyphenation
\usepackage[protrusion=true,expansion=true]{microtype} % Better typography
\usepackage{amsmath,amsfonts,amsthm} % Math packages
\usepackage[pdftex]{graphicx} % Enable pdflatex
\usepackage{wrapfig} % enable figure wrapping
\usepackage[svgnames]{xcolor} % Enabling colors by their 'svgnames'
\usepackage[hang, small,labelfont=bf,up,textfont=it,up]{caption} % Custom captions under/above floats
\usepackage{epstopdf} % Converts .eps to .pdf
\usepackage{subfig} % Subfigures
\usepackage{booktabs} % Nicer tables
\usepackage{fix-cm} % Custom fontsizes
\usepackage{booktabs} % prof. looking tables (www.en.wikibooks.org/wiki/LaTeX/Tables#Professional_tables)
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{quotes,angles}
\usepackage{mathtools}
\usepackage{tkz-euclide}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{svg}
\usepackage{tikz-3dplot}
%%% Custom sectioning (sectsty package)
\usepackage{sectsty} % Custom sectioning (see below)
\allsectionsfont{% % Change font of al section commands
\usefont{OT1}{phv}{b}{n}% % bch-b-n: CharterBT-Bold font
}
\sectionfont{% % Change font of \section command
\usefont{OT1}{phv}{b}{n}% % bch-b-n: CharterBT-Bold font
}
%%% Headers and footers
\usepackage{fancyhdr} % Needed to define custom headers/footers
\pagestyle{fancy} % Enabling the custom headers/footers
\usepackage{lastpage}
% Header (empty)
\lhead{}
\chead{}
\rhead{\today}
% Footer (you may change this to your own needs)
\lfoot{\footnotesize \texttt{Math Notes for ML} \textbullet ~ Bhargav}
\cfoot{}
\rfoot{\footnotesize page \thepage\ of \pageref{LastPage}} % "Page 1 of 2"
\renewcommand{\headrulewidth}{0.0pt}
\renewcommand{\footrulewidth}{0.4pt}
\newcommand{\hformbar}[1]{\vspace{5pt}\hrule\vspace{10pt}} % creates a horizontal bar to separate formulae better; space adaptions can be made centrally here
%%% Creating an initial of the very first character of the content
\usepackage{lettrine}
\newcommand{\initial}[1]{%
\lettrine[lines=3,lhang=0.3,nindent=0em]{
\color{DarkGoldenrod}
{\textsf{#1}}}{}}
%%% Title, author and date metadata
\usepackage{titling} % For custom titles
\newcommand{\HorRule}{\color{DarkGoldenrod}% % Creating a horizontal rule
\rule{\linewidth}{1pt}%
}
\pretitle{\vspace{-30pt} \begin{flushleft} \HorRule
\fontsize{20}{20} \usefont{OT1}{phv}{b}{n} \color{DarkRed} \selectfont
}
\title{Linear Algebra + Stats + Probability Notes} % Title of your article goes here
\posttitle{\par\end{flushleft}\vskip 0.5em}
\preauthor{\begin{flushleft}\large \lineskip 0.5em \usefont{OT1}{phv}{b}{sl} \color{DarkRed}}
\author{Bhargav} % Author name goes here
\postauthor{\footnotesize \usefont{OT1}{phv}{m}{sl} \color{Black} \hspace{5pt} github.com/brpy/ml-notes \par\end{flushleft}\HorRule}
\date{\today} % No date
%%% wws: create a non-indented formula name
\newcommand{\formdesc}[1]{\noindent\textbf{#1}}
% A 2x2 shape matrix
\newcommand{\tctmat}[4]{\begin{bmatrix}
$#1$ & $#2$\\
$#3$ & $#4$
\end{bmatrix}}
% A 2x1 shape matrix
\newcommand{\tcomat}[2]{\begin{bmatrix}
$#1$\\
$#2$
\end{bmatrix}}
% A 3x3 shape matrix
\newcommand{\thcthmat}[9]{\begin{bmatrix}
$#1$ & $#2$ & $#3$\\
$#4$ & $#5$ & $#6$\\
$#7$ & $#8$ & $#9$
\end{bmatrix}}
% A 3x1 shape matrix
\newcommand{\thcomat}[3]{\begin{bmatrix}
$#1$\\
$#2$\\
$#3$
\end{bmatrix}}
\DeclareUnicodeCharacter{03C6}{$\phi$ }
\DeclareUnicodeCharacter{03C3}{$\sigma$ }
\DeclareUnicodeCharacter{03BC}{$\mu$ }
\DeclareUnicodeCharacter{2212}{$-$}
\DeclareUnicodeCharacter{03A6}{$\Phi$ }
\DeclareUnicodeCharacter{2248}{$\approx$ }
%%% Begin document -----------------------------------------------------------------
\begin{document}
\maketitle
\thispagestyle{fancy} % Enabling the custom headers/footers for the first page
% The first character should be within \initial{}
\section{Linear Algebra}
\textbf{The following notes is primarily made for my revision. I might have skipped some topics that seemed obvious to me. I do not guarantee factual correctness of the notes. If you feel there are any errors, open a github issue/pr. Notes material is collected from various sources. Image credits are given in tex document and in src.csv}
\hspace{10pt}
\hformbar
\formdesc{Vectors:}
\begin{tikzpicture}
\draw[thin,gray!40] (-3,-3) grid (3,3);
\draw[<->] (-3,0)--(3,0) node[right]{$\hat{i}$};
\draw[<->] (0,-3)--(0,3) node[above]{$\hat{j}$};
\draw[line width=1pt,blue,-stealth](0,0)--(2,3) node[anchor=south west]{$\boldsymbol{\tcomat{2}{3}}$};
\draw [dashed] (2,3)--(2,0) node[anchor=north east]{${2}$};
\draw [dashed] (2,3)--(0,3) node[anchor=north east]{${3}$};
\end{tikzpicture}
\begin{itemize}
\item This vector is represented as $2\hat{i} + 3\hat{j}$ where $\hat{i}$ and $\hat{j}$ are unit vectors perpendicular to each other also known as basis vectors (in 2d).
\item It is also represented as a column matrix $\tcomat{2}{3}$
\item A vector is represented by its length and direction wrto. basis vectors $\hat{i}$, $\hat{j}$.
\item A vector can be freely moved without changing its length and the direction it is pointing to.
\item So any vector in space can be represented using a linear combination of $\hat{i}$, $\hat{j}$ by moving the starting point to origin.
\end{itemize}
\hformbar
\formdesc{Adding 2 Vectors:}
\begin{tikzpicture}
\draw[thin,gray!40] (-2,-2) grid (6,4);
\draw[.->] (-2,0)--(6,0) node[right]{$\hat{i}$};
\draw[.->] (0,-2)--(0,4) node[above]{$\hat{j}$};
\draw[line width=1pt,blue,-stealth](0,0)--(2,2) node[anchor=south west]{$\vec{v}$ (2,2)};
\draw[line width=1pt,red,-stealth](0,0)--(3,-1) node[anchor=south west]{$\vec{w}$ (3,-1)};
\end{tikzpicture}
\begin{tikzpicture}
\draw[thin,gray!40] (-2,-2) grid (6,4);
\draw[<->] (-2,0)--(6,0) node[right]{$\hat{i}$};
\draw[<->] (0,-2)--(0,4) node[above]{$\hat{j}$};
\draw[line width=1pt,blue,-stealth](0,0)--(2,2) node[anchor=south east, pos=0.8]{$\vec{v}$ [2,2]};
\draw[red, dashed, ->](0,0)--(3,-1) node[anchor=south west]{$\vec{w}$ [3,-1]};
\draw[line width=1pt,red,-stealth](2,2)--(5,1) node[anchor=south, pos=0.8]{$\vec{w}$ [5,1]};
\draw[line width=1pt,violet,-stealth](0,0)--(5,1) node[anchor=north, pos=0.5]{$\vec{v} + \vec{w}$};
\end{tikzpicture}
This is also known as Triangular law of vector addition.
\begin{itemize}
\item Can also be interpreted as,
$\boldsymbol{\tcomat{5}{1}}$ = $\boldsymbol{\tcomat{2}{2}}$ + $\boldsymbol{\tcomat{3}{-1}}$
\item The vector $\vec{w}$ is moved along $\vec{v}$ such that the starting point of $\vec{w}$ meets the end point of $\vec{v}$
\item Both $\vec{v}$ and $\vec{w}$ direction and lengths remain unchanged.
\end{itemize}
\hformbar
\formdesc{Scaling:}
\begin{tikzpicture}
\draw[thin,gray!40] (0,0) grid (3,4);
\draw[.-> ] (0,0)--(3,0) node[right]{$\hat{i}$};
\draw[.->] (0,0)--(0,4) node[above]{$\hat{j}$};
\draw[.->,-stealth] (0,0)--(1.5,2) coordinate (a) node[above]{$\vec{a}$};
\draw[.->,-stealth] (0,0)--(3,4) node[above]{$2\vec{a}$};
\end{tikzpicture}
\begin{itemize}
\item 2 \emph{scales} the vector $\vec{a}$.
So, 2 is a Scalar.
\item Similarly basis vectors $\hat{i}$ and $\hat{j}$ can be scaled to represent any vector in 2d plane.
\end{itemize}
\hformbar
\formdesc{Span:}
\begin{itemize}
\item $a\vec{v}+b\vec{w}$ $\implies$ Linear combination of $\vec{v}$, $\vec{w}$
\item Set of all vectors of linear combination of $\vec{v}$, $\vec{w}$ ; $a\vec{v}+b\vec{w}$ is called \textbf{span}.
\item For most vectors span consists of all points on the plane.
\item If $\vec{v}$, $\vec{w}$ lie on same line, span is a line passin through origin.
\item If both $\vec{v}$, $\vec{w}$ are zero, span is zero.
\end{itemize}
\hformbar
\formdesc{Linear (in)dependent:}
\begin{itemize}
\item If one vector can be represented as a linear combination of other, then the vectors are linearly dependent.
\item A linearly dependent vector doesn't add to span of a vector.
\item If one vector adds a dimension to a span of a vector, they are linearly independent.
\end{itemize}
\hformbar
\formdesc{Transformation:}
\begin{itemize}
\item Takes a vector and gives a output vector.
\end{itemize}
\hformbar
\formdesc{Linear Transformation:}
The conditions for the tranformation to be linear are:
\begin{itemize}
\item All lines must remain lines.
\item Origin must be remain inplace.
\item This makes all equidistant parallel lines remain equidistant and parallel.
\item Matrices = Transformation of space.
\item For example, the linear transform $\tctmat{1}{3}{-2}{0}$ transforms the 2d plane such a way that the new $\hat{i}$ lands at $\tcomat{1$\hat{i}$}{-2$\hat{j}$}$ and $\hat{j}$ lands at $\tcomat{3$\hat{i}$}{0$\hat{j}$}$
\end{itemize}
\begin{tikzpicture}
\draw[thin,gray!40] (-4,-4) grid (4,4);
\draw[<->] (-4,0)--(4,0) node[right]{$\hat{i}$};
\draw[<->] (0,-4)--(0,4) node[above]{$\hat{j}$};
\draw[line width=1pt,blue,-stealth](0,0)--(1,-2) node[anchor=south west]{$\vec{i}$ [1, -2]};
\draw[line width=1pt,red,-stealth](0,0)--(3,0) node[anchor=south east]{$\vec{j}$ [3,0]};
\end{tikzpicture}
The new basis vectors are blue $\vec{i}$ and red $\vec{j}$.
\\
\\
Now in this new transformed space, every vector has to be represented as a linear combination of these two new basis vectors.
\\
\\
The vector $\vec{v} =$ -1$\hat{i} + 2 \hat{j}$ after transformation lands at the point $\tcomat{5}{2}$ in the new vector space.
\\
\\
Even after the transformation, the linear combination doesn't change. So, $\hat{i}$ and $\hat{j}$ are replaced by $\tcomat{1$\hat{i}$}{-2$\hat{j}$}$ and $\tcomat{3$\hat{i}$}{0$\hat{j}$}$ respectively.
\\
\\
So the new transformed $\vec{v}$ becomes,
\begin{equation}
\vec{v}_{new} = -1\hat{i}_{new} + 2 \hat{j}_{new}
\end{equation}
\begin{equation}
\vec{v}_{new} = -1\tcomat{1$\hat{i}$}{-2$\hat{j}$} + 2\tcomat{3$\hat{i}$}{0$\hat{j}$}
\end{equation}
\begin{equation}
\vec{v}_{new} =\tcomat{-1$\hat{i}$}{2$\hat{j}$} + \tcomat{6$\hat{i}$}{0$\hat{j}$}
\end{equation}
\begin{equation}
\vec{v}_{new} = \tcomat{5$\hat{i}$}{2$\hat{j}$}
\end{equation}
For any vector $x\hat{i}+y\hat{j}$, after applying the transformation $\begin{bmatrix}
1 & 3\\
$-2$ & 0
\end{bmatrix}$ becomes,
\begin{equation}
\begin{bmatrix}
x \hat{i}\\
y \hat{j}
\end{bmatrix} \overset{lr. \; transform}{ \implies } x \begin{bmatrix}
1 \hat{i}\\
$-2$ \hat{j}
\end{bmatrix} + y \begin{bmatrix}
3 \hat{i}\\
0 \hat{j}
\end{bmatrix} = \begin{bmatrix}
1x+3y \hat{i}\\
-2x+0y \hat{j}
\end{bmatrix}
\end{equation}
Removing $\hat{i}$, $\hat{j}$ for legibility,
\begin{equation}
\begin{bmatrix}
x \\
y
\end{bmatrix} \overset{lr. \; transform}{ \implies } x \begin{bmatrix}
1 \\
$-2$
\end{bmatrix} + y \begin{bmatrix}
3 \\
0
\end{bmatrix} = \begin{bmatrix}
1x+3y\\
-2x+0y
\end{bmatrix}
\end{equation}
This is the basis for Matrix multiplication.
\begin{itemize}
\item $\begin{bmatrix}
1 \\
$-2$
\end{bmatrix}$ is where $\hat{i}$ lands and $\begin{bmatrix}
3 \\
0
\end{bmatrix}$ is where $\hat{j}$ (basis vectors) lands after the transformation.
\item So the 2X2 matrix $\begin{bmatrix}
1 & 3\\
$-2$ & 0
\end{bmatrix}$ itself can represent the transformation.
\item This explains the \emph{rules} for multiplication and why matrix multiplication is not commutative.
\item This also explains why the matrix $\begin{bmatrix}
1 & 0\\
0 & 1
\end{bmatrix}$ is an identity matrix. Since, this \emph{transform} actually does nothing, $\hat{i}$ and $\hat{j}$ remain unchanged.
\end{itemize}
For any transformation $\begin{bmatrix}
a & b\\
c & d
\end{bmatrix}$,
\begin{equation} \label{eq:transform1}\underbracket{
\begin{bmatrix}
a & b\\
c & d
\end{bmatrix}}_{\mathclap{Transformation}} \overbracket{\begin{bmatrix}
x\\
y
\end{bmatrix}}^{old \; vector}=x \overbracket{\begin{bmatrix}
a\\
c
\end{bmatrix}}^{\mathclap{where \; \hat{i} \; lands}} + y \underbracket{\begin{bmatrix}
b\\
d
\end{bmatrix}}_{\mathclap{where \; \hat{j} \; lands}} = \overbracket{\begin{bmatrix}
ax+by\\
cx+by
\end{bmatrix}}^{\mathclap{Transformed \; matrix}}
\end{equation}
\begin{itemize}
\item $\begin{bmatrix}
a\\
c
\end{bmatrix}$ and $\begin{bmatrix}
b\\
d
\end{bmatrix}$ are the new basis vectors; where old $\hat{i}$ and $\hat{j}$ land. These are the new transformed basis vectors.
\item Now these new basis vectors have to be used to represent all the vectors in it's span. In other words the linear combination of these two basis vectors.
\item From equation \ref{eq:transform1} it can be observed that the scalars $x$ and $y$ scale the corresponding new basis vectors.
\item For no transformation (or) Identity transform / Multiplication,
\begin{equation}
\tctmat{1}{0}{0}{1} \tcomat{x}{y} = \tcomat{x}{y}
\end{equation}
Which makes sense !!
\end{itemize}
\hformbar
\formdesc{Counterclock Transform:}\\
$\tctmat{0}{-1}{1}{0}$ $\tcomat{x}{y}$
\begin{tikzpicture}
\draw[thin,gray!40] (-2,-2) grid (2,2);
\draw[<->] (-2,0)--(2,0) node[right]{$\hat{i}$};
\draw[<->] (0,-2)--(0,2) node[above]{$\hat{j}$};
\draw[line width=1pt,blue,-stealth](0,0)--(0,1.0) node[anchor=north west]{$\hat{i}$};
\draw[line width=1pt,red,-stealth](0,0)--(-1,0) node[anchor=north west]{$\hat{j}$};
\end{tikzpicture}
\hformbar
\formdesc{Shear Transform:}\\
$\tctmat{1}{1}{0}{1}$ $\tcomat{x}{y}$
\begin{tikzpicture}
\draw[thin,gray!40] (-2,-2) grid (2,2);
\draw[<->] (-2,0)--(2,0) node[right]{$\hat{i}$};
\draw[<->] (0,-2)--(0,2) node[above]{$\hat{j}$};
%new grid
%horizontal
\foreach \y in {-2,...,2}
{\draw[orange!80] (-2,\y)--(2,\y);}
%vertical
\draw[orange!80] (-2,1)--(-1,2);
\draw[orange!80] (-2,0)--(0,2);
\draw[orange!80] (-2,-1)--(1,2);
\draw[orange!80] (-2,-2)--(2,2);
\draw[orange!80] (-1,-2)--(2,1);
\draw[orange!80] (0,-2)--(2,0);
\draw[orange!80] (1,-2)--(2,-1);
\draw[line width=1pt,blue,-stealth](0,0)--(1,0) node[anchor=north east]{$\hat{i}$};
\draw[line width=1pt,red,-stealth](0,0)--(1,1) node[anchor=south east]{$\hat{j}$};
\end{tikzpicture}
\hformbar
\formdesc{Few notable points:}\\
\begin{itemize}
\newcommand\ii{$\tcomat{2}{1}$}
\newcommand\jj{$\tcomat{-2}{-1}$}
\item In transformations, order matters. $M_1M_2 \neq M_2M_1$ because $f(g(x)) \neq g(f(x))$
\item The associative property $(AB)C = A(BC)$ holds true because the order is $C$, $B$ then $A$ regardless.
\item For a $\tctmat{2}{-2}{1}{-1}$ transformation all 2d space is squished into a line.
\begin{tikzpicture}
\draw[thin,gray!40] (-3,-3) grid (3,3);
\draw[<->] (-3,0)--(3,0) node[right]{$\hat{i}$};
\draw[<->] (0,-3)--(0,3) node[above]{$\hat{j}$};
\draw[line width=1pt,blue,-stealth](0,0)--(2,1) node[anchor=south east]{$\hat{i}$ \ii};
\draw[line width=1pt,red,-stealth](0,0)--(-2,-1) node[anchor=north west]{$\hat{j}$ \jj};
\draw[orange!80] (-3,-1.5)--(3,1.5);
\end{tikzpicture}
These two vectors \ii and \jj are linearly dependent vectors.
\item Two transforms for ex. shear and rotation can be composed into a single transform. This composition transform is nothing but a multiplication of shear and rotation matrix.
\begin{equation}
\underbracket{\tctmat{1}{1}{0}{1}}_{\mathclap{Shear}}
\overbracket{ \tctmat{0}{-1}{1}{0}}^{\mathclap{Rotation}} \tcomat{x}{y} =
\underbracket{\tctmat{1}{-1}{1}{0}}_{\mathclap{Compostion}} \tcomat{x}{y}
\end{equation}
\item Product or composition of two matrices/ transforms,
\begin{equation}
\tctmat{a}{b}{c}{d} \tctmat{e}{f}{g}{h} = \tctmat{ae$+$bg}{af$+$bh}{ce$+$dg}{cf$+$dh}
\end{equation}
\end{itemize}
\hformbar
\formdesc{Determinant:}
\begin{itemize}
\item Transformation $\tctmat{3}{0}{0}{2}$ scales $\hat{i}$ by factor 3 $\hat{j}$ by a factor 2.
\end{itemize}
\begin{figure}[ht!]
\centering
\begin{tikzpicture}
\draw[thin,gray!40] (-5,-5) grid (5,5);
% new grid
\foreach \x in {-3,0,3}
{\draw[orange!80] (\x,-5)--(\x,5);}
\foreach \y in {-4,-2,...,4}
{\draw[orange!80] (-5,\y)--(5,\y);}
% axis
\draw[<->] (-5,0)--(5,0) node[right]{$\hat{i}$};
\draw[<->] (0,-5)--(0,5) node[above]{$\hat{j}$};
% vector
\draw[line width=1pt,blue,-stealth](0,0)--(3,0) node[anchor=south east]{$\hat{i}$ (3,0)};
\draw[line width=1pt,red,-stealth](0,0)--(0,2) node[anchor=north west]{$\hat{j}$ (0,2)};
\end{tikzpicture}
\end{figure}
\begin{itemize}
\item We observe that the unit square in transformed space is scaled from 1 sq. unit to 6 sq. units. So the determinant of the transform/matrix $\tctmat{3}{0}{0}{2}$ is 6. In case of 3d, volume is scaled.
\item For a matrix/transform $\tctmat{a}{b}{c}{d}$, the determinat is $ad-bc$.
\item The determinant can be $-ve$ if the axis cross each other during the transformation. It has the effect of \emph{flipping} or \emph{inverting} the space.
% Credit https://i.stack.imgur.com/0hxY1.png https://stackoverflow.com/a/34068511/4915164
\begin{figure}[ht!]
\graphicspath{ {images/math/} }
\includesvg[width=\linewidth]{right-hand-rule}
\end{figure}
\item This can be checked using right hand rule to check if the axis still lie in the same orientation after transformation. If not, the determinant is $-ve$.
\item For 3d space, determinant is measured by unit volume instead of area.
\item Determinant can be zero if the space is squished. For ex. if transformed to a line or point in 2d or to a plane, line or a point in 3d. This has the effect of reduction in number of dimensions.
\end{itemize}
\begin{equation}
det(M_1M_2) = det(M_1) det(M_2)
\end{equation}
\hformbar
\formdesc{System of equations:}
\\
$A.\vec{X} = \vec{V}$\\
$3x+1y+4z = 1$
$3x+9y+2z = 6$
$3x+3y+3z = 8$
\begin{itemize}
\item Solving these system of equations imply, finding the vector $\thcomat{x}{y}{z}$ that if applied the transformation $\thcthmat{3}{1}{4}{3}{9}{2}{3}{3}{3}$, would land on the vector $\thcomat{1}{6}{8}$.
\item This can only be solved if $A^{-1}$ exists. Since space cannot be unpacked since there is/are lost dimension(s) if $det(A) = 0$. So $det(A) \neq 0$ has to be true for the system of equations to be solved using,
\begin{equation}
\vec{X} = A^{-1}\vec{V}
\end{equation}
\end{itemize}
\hformbar
\formdesc{Rank:}
\begin{itemize}
\item Rank is the number of dimensions of the transformed space.
\item The Rank of a matrix ; output space.
Rank : 1 $\implies$ output transformation : Line
Rank : 2 $\implies$ output transformation : Plane
Rank : 0 $\implies$ output transformation : Point
\end{itemize}
\hformbar
\formdesc{Column space:}
\begin{itemize}
\item Set of all possible linear combinations or span of column vectors of $A$. Or,
\item Set of all possible $A \vec{V}$
\end{itemize}
\hformbar
\formdesc{Null space:}
\begin{itemize}
\item Set of vectors that get squished into origin after transformation.
\end{itemize}
\hformbar
\formdesc{Dot Product:}
\begin{itemize}
\item $\vec{a}$ and $\vec{b}$ are two vectors and angle between them is $\theta$.
\begin{equation}
\vec{a} = [a_1 ,a_2 ,... a_n]
\end{equation}
\begin{equation}
\vec{b} = [b_1, b_2,... b_n]
\end{equation}
\begin{equation}
\vec{a}.\vec{b} = (a_1)*(b_1) + (a_2)*(b_2) + ... + (a_n)*(b_n)
\end{equation}
\item Geometric representation:
\begin{equation}
\vec{a}.\vec{b} = ||{a}||* ||{b}||* cos \theta
\end{equation}
\begin{tikzpicture}
\coordinate (o) at (0,0);
\draw[.->] (0,0)--(5,0) coordinate (a) node[right]{$\vec{a}$};
\draw[.->] (0,0)--(3,4) coordinate (b) node[above]{$\vec{b}$};
\pic [draw, ->, "$\theta$", angle eccentricity=1.5] {angle =a--o--b};
\end{tikzpicture}
dot product of two vectors = (length of any vector) x
(length of projection made on the vector)
\end{itemize}
\newcommand{\dotbase}{
\coordinate (o) at (0,0);
\draw[thin,gray!40] (-2,-2) grid (6,4);
\draw[<->] (-2,0)--(6,0) node[right]{$\hat{i}$};
\draw[<->] (0,-2)--(0,4) node[above]{$\hat{j}$};
\draw[line width=1pt,blue,-stealth](0,0)--(2,2) coordinate (a) node[anchor=south east, pos=0.8]{$\vec{a}$ [2,2]};
\draw[line width=1pt,red,-stealth](0,0)--(4,-1) coordinate (b) node[anchor=south west]{$\vec{b}$ [4,-1]};
\pic [draw, ->, "$\theta$", angle eccentricity=1.5] {angle =b--o--a};
}
\begin{tikzpicture}
\dotbase
\end{tikzpicture}
\\
\\
Projecting $\vec{a}$ on $\vec{b}$:
\begin{tikzpicture}
\dotbase
\draw[dashed] (2,2)--(1.411764,-0.352941176) coordinate(p);
\draw [decorate,decoration={brace,amplitude=10pt,mirror,raise=2pt},yshift=0pt]
(0,0) -- (1.411764,-0.352941176) node [black,midway,xshift=0pt, yshift=-25pt,rotate=-13] {\footnotesize
length of projection};
\tkzMarkRightAngle[draw=black,size=.2](o,p,a);
\end{tikzpicture}
\begin{itemize}
\item Length of projection = $||a||cos\theta$
\item Dot product = $||b||.||a|| cos\theta $
\item The length of projection does not depend on the length of $\vec{b}$. It only depends on length of $\vec{a}$ and $\theta$.
\item Projecting $\vec{b}$ on $\vec{a}$ will result in the same dot product result. The order does not matter.
\item If projection does not lie betweeon origin and the end point of the other vector, you can extend the other vector since length of projection is not affected by it.
\item Dot product is -ve if projection is on -ve side.
\end{itemize}
\hformbar
\formdesc{Cross Product:}
\begin{itemize}
\item Directed area product.
%https://en.wikipedia.org/wiki/Cross_product#/media/File:Cross_product_parallelogram.svg
\begin{figure}[ht!]
\graphicspath{ {images/math/} }
\includesvg[width=\linewidth]{cross_product_parallelogram}
\end{figure}
% https://en.wikipedia.org/wiki/Cross_product#/media/File:Right_hand_rule_cross_product.svg
\begin{figure}[ht!]
\graphicspath{ {images/math/} }
\includesvg[width=\linewidth]{right_hand_rule_cross_product}
\end{figure}
\item $\vec{a}\times \vec{b} = -\vec{b} \times \vec{a}$
\item Length of $\vec{a}\times \vec{b}$ = $det (\tctmat{$a_1$}{$b_1$}{$a_2$}{$b_2$})$
\item The cross product vector is normal to the area.
\begin{tikzpicture}
\coordinate (o) at (0,0);
\draw[thin,gray!40] (-2,-2) grid (6,2);
\draw[<->] (-2,0)--(6,0) node[right]{$\hat{i}$};
\draw[<->] (0,-2)--(0,2) node[above]{$\hat{j}$};
\draw[line width=1pt,blue,-stealth](0,0)--(3,1) coordinate (a) node[anchor=south west]{$\vec{a}$ (3,1)};
\draw[line width=1pt,red,-stealth](0,0)--(2,-1) coordinate(b) node[anchor=north east]{$\vec{b}$ (2,-1)};
\draw[dashed] (2,-1)--(5,0);
\draw[dashed] (3,1)--(5,0);
\pic [draw, ->, "$\theta$", angle eccentricity=1.5] {angle =b--o--a};
\end{tikzpicture}
\item The area of this parallelogram is $det (\tctmat{3}{2}{1}{-1})$
\item The direction of the cross product is normal to the area, i.e, in the direction of $\hat{k}$
\item The magnitude of this vector is the area of this parallelogram i.e, determinant.
\begin{equation}
\vec{a} \times \vec{b} = ||a|| . ||b|| sin\theta
\end{equation}
\end{itemize}
\hformbar
\formdesc{Eigen:}
\begin{itemize}
\item For a few transformations, vectors only scale. i.e, only stretch or compress.
\item Such vectors are called eigen vectors of the transformation.
\item Such vectors are transformed into it's own span.
\item The scaled value of such vectors (scalar) is the eigen value. It can be +ve or -ve.
\begin{equation}
A\vec{V} = \lambda \vec{V}
\end{equation}
where:
$A$ is the transformation,
$\vec{V}$ is the eigen vector and,
$\lambda$ is the eigen value.
\end{itemize}
\hformbar
\formdesc{Vector from origin:}\\
\begin{itemize}
\item As discussed previously, any vector can be moved to origin for reference, without changing it's direction it is pointing to and it's length.
\item To make a vector starting from $\thcomat{$a_1$}{$a_2$}{$a_3$}$ and ending at $\thcomat{$b_1$}{$b_2$}{$b_3$}$ as a reference vector, we can apply triangular law of addition to get a vector which starts from origin and is equivalent with the vector starting and ending at the above two points.
\item We need to remember that the above vectors themselves start at origin. So, we can get the vector by doing $\thcomat{$a_1$}{$a_2$}{$a_3$}$ $-$ $\thcomat{$b_1$}{$b_2$}{$b_3$}$
\end{itemize}
\hformbar
\formdesc{Matrices:}\\
Diagonal Matrix:
\begin{itemize}
\item A matrix with all 0's except diagonal elements.
\end{itemize}
\hformbar
Identity Matrix:
\begin{itemize}
\item A Matrix with all diagonal elements as 1.
$I = \thcthmat{1}{0}{0}{0}{1}{0}{0}{0}{1}$
\end{itemize}
\hformbar
Scalar Matrix:
\begin{itemize}
\item A Matrix with only equal diagonal elements.
\item A scalar matrix can be represented by a single scalar.
$K.I = \thcthmat{4}{0}{0}{0}{4}{0}{0}{0}{4}$
\end{itemize}
\hformbar
Upper Triangular Matrix:
\begin{itemize}
\item A Matrix with all elements below diagonal are 0
$\thcthmat{3}{5}{2}{0}{2}{7}{0}{0}{1}$
\end{itemize}
\hformbar
Lower Triangular Matrix:
\begin{itemize}
\item A Matrix with all elements above diagonal are 0
$\thcthmat{3}{0}{0}{7}{2}{0}{5}{3}{1}$
\end{itemize}
\hformbar
Symmetric Matrix:
\begin{itemize}
\item A square matrix which is equal to its transpose.
\item $A=A^T$
\item $a_{ij} = a_{ji}$ for every i and j.
%https://en.wikipedia.org/wiki/Symmetric_matrix#/media/File:Matrix_symmetry_qtl1.svg
\begin{center}
\graphicspath{ {images/math} }
\includesvg[width=\linewidth]{matrix_symmetry.svg}
\end{center}
\end{itemize}
\hformbar
Skew Symmetric Matrix:
\begin{itemize}
\item A square matrix which is equal to negative of its transpose.
\item $A=-A^T$
\item $a_{ij} = -a_{ji}$ for every i and j.
\end{itemize}
\hformbar
Orthogonal Matrix:
\begin{itemize}
\item A square matrix whose column vectors and row vectors are orthonormal.
\item $AA^T=A^TA=I$ or,
\item $A^T=A^{-1}$
\item $a_{ij} = -a_{ji}$ for every i and j.
\end{itemize}
\hformbar
\formdesc{Lines, Planes and Hyperplanes:}
\begin{itemize}
\item \textbf{Line} - A line has 2 degrees of freedom. You need a point and a slope or two points to uniquely identify a line.
\item Equation of a line
\begin{enumerate}
\item $y=mx+c$ ; slope = m ; y - intercept = c ; passes through $(0,c)$
\item $ax+by+c=0$ is a simple linear form with 2 unknowns
\item $y-y_1=m(x-x_1)+c$ ; slope = m ; passes through $x_1$ and $y_1$
\end{enumerate}
\item Slope is the $tan$ of angle x axis makes with the line in anti-clock wise direction.
\item Any 2 points on a line can uniquely identify the line.
\item An object on a line can move in 1 dimension.
\end{itemize}
\hformbar
\begin{itemize}
\item \textbf{Plane} - A plane is a flat 2d surface.
\item A $xy$ plane is an example of a plane.
\item To represent a plane you need 3 non collinear points or a point and a normal.
\item A normal is a vector that is perperndicular to all vectors on the surface.
\begin{enumerate}
\item So, by definition a plane is set all $(x,y,z)$ points that satisfy,
\begin{equation}
dot(\thcomat{$x$}{$y$}{$z$} - \thcomat{$x_0$}{$y_0$}{$z_0$}, \vec{n}) = 0
\end{equation}
Where:
$\vec{n}=\thcomat{$n_1$}{$n_2$}{$n_3$}$ is the normal to the plane and starts at point $\thcomat{$x_0$}{$y_0$}{$z_0$}$ which is located on the plane.
\end{enumerate}
\item The equation subsequently solves to,
\begin{equation}
n_1(x-x_0) + n_2(y-y_0) + n_3(z-z_0) = 0
\end{equation}
\begin{figure}[ht!]
\graphicspath{ {images/math/} }
\includesvg[width=\linewidth]{plane}
\end{figure}
\end{itemize}
\hformbar
\begin{itemize}
\item \textbf{Hyperplane} - Is an extension to Line and a plane in higher dimensions.
\end{itemize}
\hformbar
\begin{itemize}
\item A \textbf{Linear regression} model can successfully represent a line, plane or a hyperplane.
\end{itemize}
\hformbar
\formdesc{Miscellaneous:}
\begin{itemize}
\item Distance between two points $(x_1,y_1)$ and $(x_2,y_2)$ is $$\sqrt{(x_2-x_1)^2 + (y_2-y_1)^2}$$
\item Length of a vector $a\hat{i}+b\hat{j}+c\hat{k}$ is $$\sqrt{a^2+b^2+c^2}$$ also known as L2 Norm. {\scriptsize (Check knn notes for info on norms.)}
\item Distance from a plane $ax+by+cz=0$ to a point $(x_1,y_1)$ is $$\frac{|ax_1+by_1+cz_1|}{\sqrt{a^2+b^2+c^2}}$$
\end{itemize}
\hformbar
\formdesc{Credits:}
\begin{itemize}
\item Most of this notes is taken from 3Blue1Brown's Essence of Linear Algebra playlist. Some images are taken from wikipedia.
\end{itemize}
\newpage
\section{Statistics}
\hformbar
\formdesc{Population and Sample}:
\begin{itemize}
\item (Statistical) population is a set of all the items or events which is of interest for a question or experiment.
\item (Statistical) sample is a subset of population. The aim of sampling is that our sample represents the population.\\ The advantage is that it is faster and cheaper to collect data than for the entire population.
%https://en.wikipedia.org/wiki/Sampling_(statistics)#/media/File:Simple_random_sampling.PNG
\begin{figure}[ht!]
\caption{A random sampling process}
\graphicspath{ {images/math/} }
\includegraphics[width=\linewidth]{simple_random_sampling}
\end{figure}
\bigskip
\begin{figure}[ht!]
\centering
\caption{A sample is a subset of population}
\begin{tikzpicture}
\filldraw[color=blue!60, fill=white!2, very thick](0,0) circle (3.0);
\filldraw[color=red!60, fill=red!5, very thick](0,-0.5) circle (1.8);
\node[text width=1.2cm] at (0,-1.8) {sample};
\node[text width=1.2cm] at (0,2.2) {population};
\end{tikzpicture}
\end{figure}
\end{itemize}
\newpage
\hformbar
\formdesc{Random variable}: ($X$)
\begin{itemize}
\item A Random variable is a measurable function defined on probability space that maps from the sample space to real numbers.
\item It is called a \textbf{Discrete Random variable} if the range of the function is countable.
\item It is called a \textbf{Continous Random variable} if the range of the function is uncountably infinite or an interval.
\item Both these types of Random variable has a distribution.
\begin{itemize}
\item If $X$ is a \textbf{Discrete Random variable}, it's distribution is a discrete probability distribution i.e. can be described by a probability mass function (pmf) that assigns a probability to each value in the range of $X$.
\item If $X$ is a \textbf{Continous Random variable}, and \emph{absolutely continuous}, its distribution can be described by a probability density function (pdf).\\ Pdf assigns probailities to an interval and since the range is absolutely continuous, each individual point must have a probability of 0.
\end{itemize}
\item Not all continuous random variables are absolutely continuous.\\ A mixture distribution is one such counterexample; such random variables cannot be described by a probability density or a probability mass function.
\item But all Random variable can be described by a Cumulative distribution function (cdf).
\item Ex. for a discrete rv is dice rolls and for continuous rv is height or incomes of people.
\end{itemize}
\hformbar
\formdesc{Probability Distribution}:
\begin{itemize}
\item A Probability Distribution is the mathematical function that gives probabilities of occurences of different possible outcomes for an experiment.
\item It is a mathematical description of a random phenomenon in terms of its sample space and the probabilities of events (subsets of the sample space).
\end{itemize}
\newpage
\hformbar
\formdesc{Probability Density Function} : (pdf)
\begin{itemize}
\item Pdf is a function used to specify the random variable falling within a particular range of values, as opposed to taking any particular value(which is 0, since there are infinite number of values).
\item Probablity is the integral or area under the curve over an interval.
\item It's value at any given point can be interpreted as providing the relative likelyhood that the value of the random variable would equal that sample.
\item In other words, while the absolute likelihood for a continuous random variable to take on any particular value is 0 (since there is an infinite set of possible values to begin with), the value of the PDF at two different samples can be used to infer, in any particular draw of the random variable, how much more likely it is that the random variable would equal one sample compared to the other sample.
\end{itemize}
Properties of pdf:
\begin{itemize}
\item Area under the curve or AUC(pdf) = 1
\item Value at any point of pdf curve has to be $\geq0$
\item x-axis : Random variable $X$ \\ y-axis : Relative likelyhood/ probability density.
\item For a continuous rv, it's pdf has to also be continuous.
\item A pdf doesn't have to be differentiable. For ex. Laplace distribution is not differentiable. $$\frac{1}{2}e^{-|x|}$$
\item But a CDF has to be differentiable.
\item A point on pdf provides relative likelyhood. Whereas, area under an interval gives probability.
\item Few random variables may not have pdf. They are called Singular distributions.
\end{itemize}
\newpage
\hformbar
\formdesc{Gaussian/ Normal Distribution}: ($N$)
\begin{equation}
P(X=x) = \frac{1}{\sqrt{2\pi}\sigma} \exp{\frac{-(x-\mu)^2}{2\sigma^2}}
\end{equation}
where:
$\mu$ - Mean or expectation
$\sigma$ - Standard deviation
$\sigma^2$ - Variance
\begin{itemize}
\item The significance of Normal distribution comes from various factors like,
\begin{itemize}
\item Central limit theorem
\item Many natural properties follow a roughly Normal distribution
\item For a fixed mean and std. deviation, Normal disitribution has maximum entropy.
\end{itemize}
\item Though Normal distribution is commonly referred to as a bell curve, there are also other distributions in the bell curve family.
\end{itemize}
%https://en.wikipedia.org/wiki/Normal_distribution#/media/File:Normal_Distribution_PDF.svg
\begin{figure}[ht!]
\centering
\caption{pdf of a normal distribution}
\graphicspath{ {images/math/} }
\includegraphics[width=\linewidth]{normal_distribution_pdf}
\end{figure}
%https://en.wikipedia.org/wiki/Normal_distribution#/media/File:Normal_Distribution_CDF.svg
\begin{figure}[ht!]
\centering
\caption{cdf of a normal distribution}
\label{fig:cdf-normal}
\graphicspath{ {images/math/} }
\includegraphics[width=\linewidth]{normal_distribution_cdf}
\end{figure}
\newpage
\formdesc{68-95-99.7 Rule}:
\begin{itemize}
\item It is an empirical rule that a percentage of values lie within a band around the mean for a normal distribution.
%https://en.wikipedia.org/wiki/Statistics#/media/File:Standard_Normal_Distribution.png
\begin{figure}[ht!]
\caption{pdf of a normal distribution with $\mu=0$}
\graphicspath{ {images/math/} }
\includegraphics[width=\linewidth]{standard_normal_distribution}
\end{figure}
\item The percentage of values are,
\begin{itemize}
\item 68\% of values lie within $\mu$-$\sigma$ and $\mu+\sigma$
\item 95\% of values lie within $\mu$-$2\sigma$ and $\mu$+$2\sigma$
\item 99.7\% of values lie within $\mu$-$3\sigma$ and $\mu$+$3\sigma$
\end{itemize}
\item Is valid for any value of $\mu$ and $\sigma$
%https://en.wikipedia.org/wiki/Statistics#/media/File:Standard_Normal_Distribution.png
\begin{figure}[ht!]
\caption{pdf of a normal distribution with mean $\mu$ and std-dev. $\sigma$}
\graphicspath{ {images/math/} }
\includesvg[width=\linewidth]{empirical_rule_histogram}
\end{figure}
\end{itemize}
\newpage
\hformbar