-
Notifications
You must be signed in to change notification settings - Fork 51
/
L20Orthogonality.html~
858 lines (704 loc) · 49.4 KB
/
L20Orthogonality.html~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
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
<!DOCTYPE html>
<html lang="en" data-content_root="" >
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<title>Analytic Geometry in \(\mathbb{R}^n\) — Linear Algebra, Geometry, and Computation</title>
<script data-cfasync="false">
document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "light";
</script>
<!-- Loaded before other Sphinx assets -->
<link href="_static/styles/theme.css?digest=5b4479735964841361fd" rel="stylesheet" />
<link href="_static/styles/bootstrap.css?digest=5b4479735964841361fd" rel="stylesheet" />
<link href="_static/styles/pydata-sphinx-theme.css?digest=5b4479735964841361fd" rel="stylesheet" />
<link href="_static/vendor/fontawesome/6.1.2/css/all.min.css?digest=5b4479735964841361fd" rel="stylesheet" />
<link rel="preload" as="font" type="font/woff2" crossorigin href="_static/vendor/fontawesome/6.1.2/webfonts/fa-solid-900.woff2" />
<link rel="preload" as="font" type="font/woff2" crossorigin href="_static/vendor/fontawesome/6.1.2/webfonts/fa-brands-400.woff2" />
<link rel="preload" as="font" type="font/woff2" crossorigin href="_static/vendor/fontawesome/6.1.2/webfonts/fa-regular-400.woff2" />
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" href="_static/styles/sphinx-book-theme.css?digest=14f4ca6b54d191a8c7657f6c759bf11a5fb86285" type="text/css" />
<link rel="stylesheet" type="text/css" href="_static/togglebutton.css" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
<link rel="stylesheet" type="text/css" href="_static/mystnb.4510f1fc1dee50b3e5859aac5469c37c29e427902b24a333a5f9fcb2f0b3ac41.css" />
<link rel="stylesheet" type="text/css" href="_static/sphinx-thebe.css" />
<link rel="stylesheet" type="text/css" href="_static/design-style.4045f2051d55cab465a707391d5b2007.min.css" />
<!-- Pre-loaded scripts that we'll load fully later -->
<link rel="preload" as="script" href="_static/scripts/bootstrap.js?digest=5b4479735964841361fd" />
<link rel="preload" as="script" href="_static/scripts/pydata-sphinx-theme.js?digest=5b4479735964841361fd" />
<script src="_static/vendor/fontawesome/6.1.2/js/all.min.js?digest=5b4479735964841361fd"></script>
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/clipboard.min.js"></script>
<script src="_static/copybutton.js"></script>
<script src="_static/scripts/sphinx-book-theme.js?digest=5a5c038af52cf7bc1a1ec88eea08e6366ee68824"></script>
<script>let toggleHintShow = 'Click to show';</script>
<script>let toggleHintHide = 'Click to hide';</script>
<script>let toggleOpenOnPrint = 'true';</script>
<script src="_static/togglebutton.js"></script>
<script>var togglebuttonSelector = '.toggle, .admonition.dropdown';</script>
<script src="_static/design-tabs.js"></script>
<script>const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js"
const thebe_selector = ".thebe,.cell"
const thebe_selector_input = "pre"
const thebe_selector_output = ".output, .cell_output"
</script>
<script async="async" src="_static/sphinx-thebe.js"></script>
<script>window.MathJax = {"options": {"processHtmlClass": "tex2jax_process|mathjax_process|math|output_area"}}</script>
<script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<script>DOCUMENTATION_OPTIONS.pagename = 'L20Orthogonality';</script>
<link rel="shortcut icon" href="_static/DiagramAR-icon.png"/>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Orthogonal Sets and Projection" href="L21OrthogonalSets.html" />
<link rel="prev" title="PageRank" href="L19PageRank.html" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="docsearch:language" content="en"/>
</head>
<body data-bs-spy="scroll" data-bs-target=".bd-toc-nav" data-offset="180" data-bs-root-margin="0px 0px -60%" data-default-mode="">
<a class="skip-link" href="#main-content">Skip to main content</a>
<div id="pst-scroll-pixel-helper"></div>
<button type="button" class="btn rounded-pill" id="pst-back-to-top">
<i class="fa-solid fa-arrow-up"></i>
Back to top
</button>
<input type="checkbox"
class="sidebar-toggle"
name="__primary"
id="__primary"/>
<label class="overlay overlay-primary" for="__primary"></label>
<input type="checkbox"
class="sidebar-toggle"
name="__secondary"
id="__secondary"/>
<label class="overlay overlay-secondary" for="__secondary"></label>
<div class="search-button__wrapper">
<div class="search-button__overlay"></div>
<div class="search-button__search-container">
<form class="bd-search d-flex align-items-center"
action="search.html"
method="get">
<i class="fa-solid fa-magnifying-glass"></i>
<input type="search"
class="form-control"
name="q"
id="search-input"
placeholder="Search this book..."
aria-label="Search this book..."
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"/>
<span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd></span>
</form></div>
</div>
<nav class="bd-header navbar navbar-expand-lg bd-navbar">
</nav>
<div class="bd-container">
<div class="bd-container__inner bd-page-width">
<div class="bd-sidebar-primary bd-sidebar">
<div class="sidebar-header-items sidebar-primary__section">
</div>
<div class="sidebar-primary-items__start sidebar-primary__section">
<div class="sidebar-primary-item">
<a class="navbar-brand logo" href="landing-page.html">
<img src="_static/DiagramAR-icon.png" class="logo__image only-light" alt="Linear Algebra, Geometry, and Computation - Home"/>
<script>document.write(`<img src="_static/DiagramAR-icon.png" class="logo__image only-dark" alt="Linear Algebra, Geometry, and Computation - Home"/>`);</script>
</a></div>
<div class="sidebar-primary-item"><nav class="bd-links" id="bd-docs-nav" aria-label="Main">
<div class="bd-toc-item navbar-nav active">
<ul class="nav bd-sidenav bd-sidenav__home-link">
<li class="toctree-l1">
<a class="reference internal" href="landing-page.html">
Preface
</a>
</li>
</ul>
<ul class="current nav bd-sidenav">
<li class="toctree-l1"><a class="reference internal" href="L01LinearEquations.html">Linear Equations</a></li>
<li class="toctree-l1"><a class="reference internal" href="L02Numerics.html">(Getting Serious About) Numbers</a></li>
<li class="toctree-l1"><a class="reference internal" href="L03RowReductions.html">Gaussian Elimination</a></li>
<li class="toctree-l1"><a class="reference internal" href="L04VectorEquations.html">Vector Equations</a></li>
<li class="toctree-l1"><a class="reference internal" href="L05Axb.html"><span class="math notranslate nohighlight">\(A{\bf x} = {\bf b}\)</span></a></li>
<li class="toctree-l1"><a class="reference internal" href="L06LinearIndependence.html">Linear Independence</a></li>
<li class="toctree-l1"><a class="reference internal" href="L07LinearTransformations.html">Linear Transformations</a></li>
<li class="toctree-l1"><a class="reference internal" href="L08MatrixofLinearTranformation.html">The Matrix of a Linear Transformation</a></li>
<li class="toctree-l1"><a class="reference internal" href="L09MatrixOperations.html">Matrix Algebra</a></li>
<li class="toctree-l1"><a class="reference internal" href="L10MatrixInverse.html">The Inverse of a Matrix</a></li>
<li class="toctree-l1"><a class="reference internal" href="L11MarkovChains.html">Markov Chains</a></li>
<li class="toctree-l1"><a class="reference internal" href="L12MatrixFactorizations.html">Matrix Factorizations</a></li>
<li class="toctree-l1"><a class="reference internal" href="L13ComputerGraphics.html">Computer Graphics</a></li>
<li class="toctree-l1"><a class="reference internal" href="L14Subspaces.html">Subspaces</a></li>
<li class="toctree-l1"><a class="reference internal" href="L15DimensionRank.html">Dimension and Rank</a></li>
<li class="toctree-l1"><a class="reference internal" href="L16Eigenvectors.html">Eigenvectors and Eigenvalues</a></li>
<li class="toctree-l1"><a class="reference internal" href="L17CharacteristicEqn.html">The Characteristic Equation</a></li>
<li class="toctree-l1"><a class="reference internal" href="L18Diagonalization.html">Diagonalization</a></li>
<li class="toctree-l1"><a class="reference internal" href="L19PageRank.html">PageRank</a></li>
<li class="toctree-l1 current active"><a class="current reference internal" href="#">Analytic Geometry in <span class="math notranslate nohighlight">\(\mathbb{R}^n\)</span></a></li>
<li class="toctree-l1"><a class="reference internal" href="L21OrthogonalSets.html">Orthogonal Sets and Projection</a></li>
<li class="toctree-l1"><a class="reference internal" href="L22LeastSquares.html">Least Squares</a></li>
<li class="toctree-l1"><a class="reference internal" href="L23LinearModels.html">Linear Models</a></li>
<li class="toctree-l1"><a class="reference internal" href="L24SymmetricMatrices.html">Symmetric Matrices</a></li>
<li class="toctree-l1"><a class="reference internal" href="L25SVD.html">The Singular Value Decomposition</a></li>
<li class="toctree-l1"><a class="reference internal" href="L26ApplicationsOfSVD.html">Applications of the SVD</a></li>
</ul>
</div>
</nav></div>
</div>
<div class="sidebar-primary-items__end sidebar-primary__section">
</div>
<div id="rtd-footer-container"></div>
</div>
<main id="main-content" class="bd-main">
<div class="sbt-scroll-pixel-helper"></div>
<div class="bd-content">
<div class="bd-article-container">
<div class="bd-header-article">
<div class="header-article-items header-article__inner">
<div class="header-article-items__start">
<div class="header-article-item"><label class="sidebar-toggle primary-toggle btn btn-sm" for="__primary" title="Toggle primary sidebar" data-bs-placement="bottom" data-bs-toggle="tooltip">
<span class="fa-solid fa-bars"></span>
</label></div>
</div>
<div class="header-article-items__end">
<div class="header-article-item">
<div class="article-header-buttons">
<a href="https://github.com/mcrovella/CS132-Geometric-Algorithms" target="_blank"
class="btn btn-sm btn-source-repository-button"
title="Source repository"
data-bs-placement="bottom" data-bs-toggle="tooltip"
>
<span class="btn__icon-container">
<i class="fab fa-github"></i>
</span>
</a>
<div class="dropdown dropdown-download-buttons">
<button class="btn dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false" aria-label="Download this page">
<i class="fas fa-download"></i>
</button>
<ul class="dropdown-menu">
<li><a href="_sources/L20Orthogonality.ipynb" target="_blank"
class="btn btn-sm btn-download-source-button dropdown-item"
title="Download source file"
data-bs-placement="left" data-bs-toggle="tooltip"
>
<span class="btn__icon-container">
<i class="fas fa-file"></i>
</span>
<span class="btn__text-container">.ipynb</span>
</a>
</li>
<li>
<button onclick="window.print()"
class="btn btn-sm btn-download-pdf-button dropdown-item"
title="Print to PDF"
data-bs-placement="left" data-bs-toggle="tooltip"
>
<span class="btn__icon-container">
<i class="fas fa-file-pdf"></i>
</span>
<span class="btn__text-container">.pdf</span>
</button>
</li>
</ul>
</div>
<button onclick="toggleFullScreen()"
class="btn btn-sm btn-fullscreen-button"
title="Fullscreen mode"
data-bs-placement="bottom" data-bs-toggle="tooltip"
>
<span class="btn__icon-container">
<i class="fas fa-expand"></i>
</span>
</button>
<script>
document.write(`
<button class="btn btn-sm navbar-btn theme-switch-button" title="light/dark" aria-label="light/dark" data-bs-placement="bottom" data-bs-toggle="tooltip">
<span class="theme-switch nav-link" data-mode="light"><i class="fa-solid fa-sun fa-lg"></i></span>
<span class="theme-switch nav-link" data-mode="dark"><i class="fa-solid fa-moon fa-lg"></i></span>
<span class="theme-switch nav-link" data-mode="auto"><i class="fa-solid fa-circle-half-stroke fa-lg"></i></span>
</button>
`);
</script>
<script>
document.write(`
<button class="btn btn-sm navbar-btn search-button search-button__button" title="Search" aria-label="Search" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="fa-solid fa-magnifying-glass fa-lg"></i>
</button>
`);
</script>
<label class="sidebar-toggle secondary-toggle btn btn-sm" for="__secondary"title="Toggle secondary sidebar" data-bs-placement="bottom" data-bs-toggle="tooltip">
<span class="fa-solid fa-list"></span>
</label>
</div></div>
</div>
</div>
</div>
<div id="jb-print-docs-body" class="onlyprint">
<h1>Analytic Geometry in \mathbb{R}^n</h1>
<!-- Table of contents -->
<div id="print-main-content">
<div id="jb-print-toc">
<div>
<h2> Contents </h2>
</div>
<nav aria-label="Page">
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#the-challenge-extending-geometric-intuition-to-high-dimension">The Challenge: Extending Geometric Intuition to High Dimension</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#inner-product-review">Inner Product (Review)</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#vector-norm">Vector Norm</a><ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#normalization-to-unit-length">Normalization to Unit Length</a></li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#distance">Distance</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#orthogonality">Orthogonality</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#the-angle-between-two-vectors">The Angle Between Two Vectors</a><ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#example-application-cosine-similarity">Example Application: Cosine Similarity.</a></li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div id="searchbox"></div>
<article class="bd-article" role="main">
<section class="tex2jax_ignore mathjax_ignore" id="analytic-geometry-in-mathbb-r-n">
<h1>Analytic Geometry in <span class="math notranslate nohighlight">\(\mathbb{R}^n\)</span><a class="headerlink" href="#analytic-geometry-in-mathbb-r-n" title="Permalink to this heading">#</a></h1>
<div class="cell tag_remove-input docutils container">
<div class="cell_output docutils container">
<img alt="_images/fc15baa03beeb7db8f68c47b5fc0b78dfbbae38a44c64bb23c3b6b03b24b87cb.jpg" src="_images/fc15baa03beeb7db8f68c47b5fc0b78dfbbae38a44c64bb23c3b6b03b24b87cb.jpg" />
</div>
</div>
<div class="cell tag_remove-input docutils container">
<div class="cell_output docutils container">
<img alt="_images/fd314ec0f0a34ffbe0952eb5544329822857e29f8721c54f0f2cb292610aa56a.png" src="_images/fd314ec0f0a34ffbe0952eb5544329822857e29f8721c54f0f2cb292610aa56a.png" />
</div>
</div>
<p>Transcript of oral arguments before the US Supreme Court, <em>Briscoe v. Virginia,</em> January 11, 2010:</p>
<p><em>MR. FRIEDMAN: I think that issue is entirely <strong>orthogonal</strong> to the issue here because the Commonwealth is acknowledging –</em></p>
<p><em>CHIEF JUSTICE ROBERTS: I’m sorry. Entirely what?</em></p>
<p><em>MR. FRIEDMAN: <strong>Orthogonal. Right angle. Unrelated. Irrelevant.</strong></em></p>
<p><em>CHIEF JUSTICE ROBERTS: Oh.</em></p>
<p><em>JUSTICE SCALIA: What was that adjective? I liked that.</em></p>
<p><em>MR. FRIEDMAN: <strong>Orthogonal.</strong></em></p>
<p><em>CHIEF JUSTICE ROBERTS: <strong>Orthogonal.</strong></em></p>
<p><em>MR. FRIEDMAN: Right, right.</em></p>
<p><em>JUSTICE SCALIA: <strong>Orthogonal,</strong> ooh.</em></p>
<p><em>(Laughter.)</em></p>
<p><em>JUSTICE KENNEDY: I knew this case presented us a problem.</em></p>
<p><em>(Laughter.)</em></p>
<section id="the-challenge-extending-geometric-intuition-to-high-dimension">
<h2>The Challenge: Extending Geometric Intuition to High Dimension<a class="headerlink" href="#the-challenge-extending-geometric-intuition-to-high-dimension" title="Permalink to this heading">#</a></h2>
<p>Our challenge today is to begin to lay down the elements of <strong>analytic geometry</strong>.</p>
<p>The concepts we deal with today will be familiar to you.</p>
<p>Our goal is not to introduce new ideas, but to cast old ideas into greater <strong>generality.</strong></p>
<p>In particular, we will take familiar notions and reformulate them in terms of vectors …</p>
<p>… vectors in <strong>arbitrary</strong> dimension.</p>
<p>Let’s start with a simple example in <span class="math notranslate nohighlight">\(\mathbb{R}^2\)</span>.</p>
<p>How would you determine the angle <span class="math notranslate nohighlight">\(\theta\)</span> below?</p>
<div class="cell tag_remove-input docutils container">
<div class="cell_output docutils container">
<img alt="_images/afcb34e06dd572e09700aec27881e0a6f85dc64e0fe6c8b6d14485b48e699f34.png" src="_images/afcb34e06dd572e09700aec27881e0a6f85dc64e0fe6c8b6d14485b48e699f34.png" />
</div>
</div>
<p>This is fairly easy. Probably we’d take out a protractor and use it to measure <span class="math notranslate nohighlight">\(\theta\)</span>.</p>
<p>OK, let’s go up one dimension, to <span class="math notranslate nohighlight">\(\mathbb{R}^3\)</span>.</p>
<div class="cell tag_remove-input docutils container">
<div class="cell_output docutils container">
<img alt="_images/d9af8808bc46e040880dc735ff53478e105dd82d53ca0e36bb98455fc2a1f31d.png" src="_images/d9af8808bc46e040880dc735ff53478e105dd82d53ca0e36bb98455fc2a1f31d.png" />
</div>
</div>
<p>This seems a little more challenging, but we could probably do it.</p>
<p>Let’s go up one dimension, to <span class="math notranslate nohighlight">\(\mathbb{R}^4\)</span>:</p>
<p>This seems hard!</p>
<p>What we need are ways to capture simple notions:</p>
<ul class="simple">
<li><p>length,</p></li>
<li><p>distance,</p></li>
<li><p>orthogonality (perpendicularity), and</p></li>
<li><p>angle.</p></li>
</ul>
<p>However we need to take these notions that are familiar from our 3D world and see how to define them for spaces of arbitrary dimension, ie, <span class="math notranslate nohighlight">\(\mathbb{R}^n\)</span>.</p>
<p>Interestingly, it turns out that these notions (length, distance, perpendicularity, angle) <strong>all</strong> depend on one key notion: the <strong>inner product</strong>.</p>
<p>In fact, the notion is so important that we refer to a vector space for which there is an inner product as an <strong>inner product space.</strong></p>
<p>So let’s briefly return to and review the <strong>inner product.</strong></p>
</section>
<section id="inner-product-review">
<h2>Inner Product (Review)<a class="headerlink" href="#inner-product-review" title="Permalink to this heading">#</a></h2>
<p>Recall that we consider vectors such as <span class="math notranslate nohighlight">\(\mathbf{u}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{v}\)</span> in <span class="math notranslate nohighlight">\(\mathbb{R}^n\)</span> to be <span class="math notranslate nohighlight">\(n\times1\)</span> matrices.</p>
<p>Then <span class="math notranslate nohighlight">\(\mathbf{u}^T\mathbf{v}\)</span> is a scalar, called the <strong>inner product</strong> of <span class="math notranslate nohighlight">\(\mathbf{u}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{v}.\)</span></p>
<p>You will also see this called the <strong>dot product</strong>.</p>
<p>It is sometimes written as <span class="math notranslate nohighlight">\(\mathbf{u} \mathbf{\cdot} \mathbf{v}\)</span>, or <span class="math notranslate nohighlight">\(<\mathbf{u}, \mathbf{v}>\)</span></p>
<p>but we will always write <span class="math notranslate nohighlight">\(\mathbf{u}^T\mathbf{v}.\)</span></p>
<p>The inner product is the sum of the componentwise product of <span class="math notranslate nohighlight">\(\mathbf{u}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{v}\)</span>.</p>
<p>If <span class="math notranslate nohighlight">\(\mathbf{u} = \begin{bmatrix}u_1\\u_2\\\vdots\\u_n\end{bmatrix}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{v} = \begin{bmatrix}v_1\\v_2\\\vdots\\v_n\end{bmatrix},\)</span> then the inner product of <span class="math notranslate nohighlight">\(\mathbf{u}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{v}\)</span> is:</p>
<div class="math notranslate nohighlight">
\[\begin{split}\mathbf{u}^T\mathbf{v} = \begin{bmatrix}u_1&u_2&\dots&u_n\end{bmatrix}\begin{bmatrix}v_1\\v_2\\\vdots\\v_n\end{bmatrix} = u_1v_1 + u_2v_2 + \dots + u_nv_n = \sum_{i=1}^n u_iv_i.\end{split}\]</div>
<p>Let’s remind ourselves of the properties of the inner product:</p>
<p><strong>Theorem.</strong> Let <span class="math notranslate nohighlight">\(\mathbf{u}\)</span>,<span class="math notranslate nohighlight">\(\mathbf{v}\)</span>, and <span class="math notranslate nohighlight">\(\mathbf{w}\)</span> be vectors in <span class="math notranslate nohighlight">\(\mathbb{R}^n\)</span>, and let <span class="math notranslate nohighlight">\(c\)</span> be a scalar. Then:</p>
<ol class="arabic simple">
<li><p><span class="math notranslate nohighlight">\(\mathbf{u}^T\mathbf{v} = \mathbf{v}^T\mathbf{u}\)</span></p></li>
</ol>
<p>Inner product is symmetric. Note that these two expressions are the transpose of each other – but of course the transpose of a scalar is itself!</p>
<ol class="arabic simple" start="2">
<li><p><span class="math notranslate nohighlight">\((\mathbf{u}+\mathbf{v})^T\mathbf{w} = \mathbf{u}^T\mathbf{w} + \mathbf{v}^T\mathbf{w}\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\((c\mathbf{u})^T\mathbf{v} = c(\mathbf{u}^T\mathbf{v}) = \mathbf{u}^T(c\mathbf{v})\)</span></p></li>
</ol>
<p>Inner product is <strong>linear</strong> in <strong>each term.</strong></p>
<ol class="arabic simple" start="4">
<li><p><span class="math notranslate nohighlight">\(\mathbf{u}^T\mathbf{u} \geq 0,\;\;\;\mbox{and}\;\mathbf{u}^T\mathbf{u} = 0\;\mbox{if and only if}\;\mathbf{u} = 0\)</span></p></li>
</ol>
<p>Inner product of a vector with itself is <strong>never negative.</strong></p>
<p>The first three are restatements of facts about matrix-vector products.</p>
<p>The last one is straightforward, but important.</p>
<p>Now, given that review, let’s start talking about geometry.</p>
</section>
<section id="vector-norm">
<h2>Vector Norm<a class="headerlink" href="#vector-norm" title="Permalink to this heading">#</a></h2>
<p>OK, armed with the inner product, let’s get started.</p>
<p>Our first question will be: How do we measure the <strong>length</strong> of a vector?</p>
<p>Let’s say we are in <span class="math notranslate nohighlight">\(\mathbb{R}^2\)</span>. Then the length follows directly from the Pythagorean theorem:</p>
<div class="cell tag_remove-input docutils container">
<div class="cell_output docutils container">
<img alt="_images/7dc3b43203e563b32023fd1e775f2255b89e9b2ad495f21f89b6489a35422047.png" src="_images/7dc3b43203e563b32023fd1e775f2255b89e9b2ad495f21f89b6489a35422047.png" />
</div>
</div>
<p>What happens when we move to <span class="math notranslate nohighlight">\(\mathbb{R}^3\)</span>?</p>
<p>It turns out we need to apply the Pythagorean Theorem an additional time:</p>
<div class="cell tag_remove-input docutils container">
<div class="cell_output docutils container">
<img alt="_images/69241dd70b063faec3fb5d1ecedeaead08fabd80cb0edb08c398a4b8eda41868.png" src="_images/69241dd70b063faec3fb5d1ecedeaead08fabd80cb0edb08c398a4b8eda41868.png" />
</div>
</div>
<p>So the length of a vector in <span class="math notranslate nohighlight">\(\mathbb{R}^n\)</span> is</p>
<div class="math notranslate nohighlight">
\[ \sqrt{v_1^2 + v_2^2 + \dots + v_n^2} = \sqrt{\sum_{i=1}^n{v_i}^2}\]</div>
<p>Now let’s express this in a way that <strong>does not require writing the individual components</strong> of <span class="math notranslate nohighlight">\(\mathbf{v}\)</span>.</p>
<p>We notice that the above expression for the length of <span class="math notranslate nohighlight">\(\mathbf{v}\)</span> is the same as:</p>
<div class="math notranslate nohighlight">
\[\sqrt{\mathbf{v}^T\mathbf{v}}.\]</div>
<p>Notice that this is always defined because <span class="math notranslate nohighlight">\(\mathbf{v}^T\mathbf{v}\)</span> is nonnegative.</p>
<p>Length is such a fundamental concept that we introduce a special notation and name for it.</p>
<p><strong>Definition.</strong> The <strong>norm</strong> of <span class="math notranslate nohighlight">\(\mathbf{v}\)</span> is the nonnegative scalar <span class="math notranslate nohighlight">\(\Vert\mathbf{v}\Vert\)</span> defined by</p>
<div class="math notranslate nohighlight">
\[\Vert\mathbf{v}\Vert = \sqrt{\mathbf{v}^T\mathbf{v}} = \sqrt{\sum_{i=1}^n{v_i}^2}.\]</div>
<section id="normalization-to-unit-length">
<h3>Normalization to Unit Length<a class="headerlink" href="#normalization-to-unit-length" title="Permalink to this heading">#</a></h3>
<p>For any scalar <span class="math notranslate nohighlight">\(c\)</span>, the length of <span class="math notranslate nohighlight">\(c\mathbf{v}\)</span> is <span class="math notranslate nohighlight">\(|c|\)</span> times the length of <span class="math notranslate nohighlight">\(\mathbf{v}\)</span>. That is,</p>
<div class="math notranslate nohighlight">
\[\Vert c\mathbf{v}\Vert = \vert c\vert\Vert\mathbf{v}\Vert.\]</div>
<p>So, for example, <span class="math notranslate nohighlight">\(\Vert(-2)\mathbf{v}\Vert = 2\Vert \mathbf{v}\Vert\)</span>.</p>
<p>A vector of length 1 is called a <strong>unit vector</strong>.</p>
<p>If we divide a nonzero vector <span class="math notranslate nohighlight">\(\mathbf{v}\)</span> by its length – that is, multiply by <span class="math notranslate nohighlight">\(1/\Vert\mathbf{v}\Vert\)</span> – we obtain a unit vector <span class="math notranslate nohighlight">\(\mathbf{u}\)</span>.</p>
<p>We say that we have <em>normalized</em> <span class="math notranslate nohighlight">\(\mathbf{v}\)</span>, and that <span class="math notranslate nohighlight">\(\mathbf{u}\)</span> is <em>in the same direction</em> as <span class="math notranslate nohighlight">\(\mathbf{v}.\)</span></p>
<p><strong>Example.</strong> Let <span class="math notranslate nohighlight">\(\mathbf{v} = \begin{bmatrix}1\\-2\\2\\0\end{bmatrix}.\)</span> Find the unit vector <span class="math notranslate nohighlight">\(\mathbf{u}\)</span> in the same direction as <span class="math notranslate nohighlight">\(\mathbf{v}.\)</span></p>
<p><strong>Solution.</strong></p>
<p>First, compute the length of <span class="math notranslate nohighlight">\(\mathbf{v}\)</span>:</p>
<div class="math notranslate nohighlight">
\[\Vert\mathbf{v}\Vert^2 = \mathbf{v}^T\mathbf{v} = (1)^2 + (-2)^2 + (2)^2 + (0)^2 = 9\]</div>
<div class="math notranslate nohighlight">
\[\Vert\mathbf{v}\Vert = \sqrt{9} = 3\]</div>
<p>Then multiply <span class="math notranslate nohighlight">\(\mathbf{v}\)</span> by <span class="math notranslate nohighlight">\(1/\Vert\mathbf{v}\Vert\)</span> to obtain</p>
<div class="math notranslate nohighlight">
\[\begin{split}\mathbf{u} = \frac{1}{\Vert\mathbf{v}\Vert}\mathbf{v} = \frac{1}{3}\mathbf{v} = \frac{1}{3}\begin{bmatrix}1\\-2\\2\\0\end{bmatrix} = \begin{bmatrix}1/3\\-2/3\\2/3\\0\end{bmatrix}\end{split}\]</div>
<p>It’s important to note that we can’t actually visualize <span class="math notranslate nohighlight">\(\mathbf{u}\)</span> but we can still reason geometrically about it as a unit vector.</p>
<p>For example, we can talk about (2D) circles, (3D) spheres, four-dimensional spheres, five-dimensional spheres, etc.</p>
</section>
</section>
<section id="distance">
<h2>Distance<a class="headerlink" href="#distance" title="Permalink to this heading">#</a></h2>
<p>It’s very useful to be able to talk about the <strong>distance</strong> between two points (or vectors) in <span class="math notranslate nohighlight">\(\mathbb{R}^n\)</span>.</p>
<p>We can start from basics:</p>
<div class="cell tag_remove-input docutils container">
<div class="cell_output docutils container">
<img alt="_images/952f81d8a91359d35745f3697e55c37cc7e834c9eccc7439f2bbf266fee29fa1.png" src="_images/952f81d8a91359d35745f3697e55c37cc7e834c9eccc7439f2bbf266fee29fa1.png" />
</div>
</div>
<p>On the number line (ie, <span class="math notranslate nohighlight">\(\mathbb{R}^1\)</span>), the distance between two points <span class="math notranslate nohighlight">\(a\)</span> and <span class="math notranslate nohighlight">\(b\)</span> is <span class="math notranslate nohighlight">\(\vert a-b\vert\)</span>.</p>
<p>The same is true in <span class="math notranslate nohighlight">\(\mathbb{R}^n\)</span>.</p>
<p><strong>Definition.</strong> For <span class="math notranslate nohighlight">\(\mathbf{u}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{v}\)</span> in <span class="math notranslate nohighlight">\(\mathbb{R}^n,\)</span> the <strong>distance between <span class="math notranslate nohighlight">\(\mathbf{u}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{v}\)</span>,</strong> written as <span class="math notranslate nohighlight">\(\mbox{dist}(\mathbf{u},\mathbf{v}),\)</span> is the length of the vector <span class="math notranslate nohighlight">\(\mathbf{u}-\mathbf{v}\)</span>. That is,</p>
<div class="math notranslate nohighlight">
\[\mbox{dist}(\mathbf{u},\mathbf{v}) = \Vert\mathbf{u}-\mathbf{v}\Vert.\]</div>
<p>This definition agrees with the usual formulas for the Euclidean distance between two points. The usual formula is</p>
<div class="math notranslate nohighlight">
\[\mbox{dist}(\mathbf{u},\mathbf{v}) = \sqrt{(u_1-v_1)^2 + (u_2-v_2)^2 + \dots + (u_n-v_n)^2}.\]</div>
<p>Which you can see is equal to</p>
<div class="math notranslate nohighlight">
\[\begin{split}\Vert\mathbf{u}-\mathbf{v}\Vert = \sqrt{(\mathbf{u}-\mathbf{v})^T(\mathbf{u}-\mathbf{v})} = \sqrt{\begin{bmatrix}u_1-v_1&u_2-v_2&\dots&u_n-v_n\end{bmatrix}\begin{bmatrix}u_1-v_1\\u_2-v_2\\\vdots\\u_n-v_n\end{bmatrix}}\end{split}\]</div>
<p>There is a geometric view as well.</p>
<p>For example, consider the vectors <span class="math notranslate nohighlight">\(\mathbf{u} = \begin{bmatrix}7\\1\end{bmatrix}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{v} = \begin{bmatrix}3\\2\end{bmatrix}\)</span> in <span class="math notranslate nohighlight">\(\mathbb{R}^2\)</span>.</p>
<p>Then one can see that the distance from <span class="math notranslate nohighlight">\(\mathbf{u}\)</span> to <span class="math notranslate nohighlight">\(\mathbf{v}\)</span> is the same as the length of the vector <span class="math notranslate nohighlight">\(\mathbf{u}-\mathbf{v}\)</span>.</p>
<div class="cell tag_remove-input docutils container">
<div class="cell_output docutils container">
<img alt="_images/db1b6afce8ad67496b7908328aa4a3184946a918419a2ae8fe61a78a9ab1b9c6.png" src="_images/db1b6afce8ad67496b7908328aa4a3184946a918419a2ae8fe61a78a9ab1b9c6.png" />
</div>
</div>
<p>This shows that the distance between two vectors is the length of their difference.</p>
<div class="toggle docutils container">
<p>Question Time! Q 20.1</p>
</div>
</section>
<section id="orthogonality">
<h2>Orthogonality<a class="headerlink" href="#orthogonality" title="Permalink to this heading">#</a></h2>
<p>Now we turn to another familiar notion from 2D geometry, which we’ll generalize to <span class="math notranslate nohighlight">\(\mathbb{R}^n\)</span>: the notion of being <strong>perpendicular.</strong></p>
<p>Once again, we seek a way to express perpendicularity of two vectors, regardless of the dimension they live in.</p>
<p>We will say that two vectors are perpendicular if they form a right angle at the origin.</p>
<div class="cell tag_remove-input docutils container">
<div class="cell_output docutils container">
<img alt="_images/d9f78400e349da05fd8b23a9ba74bb5c4acd3cc9dc26ff6079c71f90e7f9e4fa.png" src="_images/d9f78400e349da05fd8b23a9ba74bb5c4acd3cc9dc26ff6079c71f90e7f9e4fa.png" />
</div>
</div>
<p>Draw the line connecting <span class="math notranslate nohighlight">\(\mathbf{u}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{v}\)</span>.</p>
<p>Then <span class="math notranslate nohighlight">\(\mathbf{u}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{v}\)</span> are perpendicular if and only if they make a right triangle with the origin.</p>
<p>So <span class="math notranslate nohighlight">\(\mathbf{u}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{v}\)</span> are perpendicular if and only if the Pythagorean Theorem is satisified for this triangle.</p>
<div class="cell tag_remove-input docutils container">
<div class="cell_output docutils container">
<img alt="_images/95fcb0608059d206797d536e4f7ca1b9c68040a77a11dd663b49154caf08d7c1.png" src="_images/95fcb0608059d206797d536e4f7ca1b9c68040a77a11dd663b49154caf08d7c1.png" />
</div>
</div>
<p>What is the length of the red side of the triangle?</p>
<p>According to the definitions we’ve developed today, it is <span class="math notranslate nohighlight">\(\Vert \mathbf{u} - \mathbf{v} \Vert\)</span>.</p>
<div class="cell tag_remove-input docutils container">
<div class="cell_output docutils container">
<img alt="_images/8f2ad2198aff4838243f5bc31dc5caa805395f4f8d7805db23261f7816baf244.png" src="_images/8f2ad2198aff4838243f5bc31dc5caa805395f4f8d7805db23261f7816baf244.png" />
</div>
</div>
<p>So the blue and green lines are perpendicular if and only if:</p>
<div class="math notranslate nohighlight">
\[ \Vert \mathbf{u} - \mathbf{v} \Vert^2 = \Vert \mathbf{u} \Vert^2 + \Vert \mathbf{v} \Vert^2\]</div>
<p>Let’s see what this implies from an algebraic standpoint.</p>
<p>First let’s simplify the expression for squared distance from <span class="math notranslate nohighlight">\(\mathbf{u}\)</span> to <span class="math notranslate nohighlight">\(\mathbf{v}\)</span>:</p>
<div class="math notranslate nohighlight">
\[[\mbox{dist}(\mathbf{u},\mathbf{v})]^2 = \Vert\mathbf{u}-\mathbf{v}\Vert^2\]</div>
<div class="math notranslate nohighlight">
\[ = (\mathbf{u}-\mathbf{v})^T(\mathbf{u}-\mathbf{v})\]</div>
<div class="math notranslate nohighlight">
\[ = (\mathbf{u}^T-\mathbf{v}^T)(\mathbf{u}-\mathbf{v})\]</div>
<div class="math notranslate nohighlight">
\[ = \mathbf{u}^T(\mathbf{u}-\mathbf{v}) - \mathbf{v}^T(\mathbf{u}-\mathbf{v})\]</div>
<div class="math notranslate nohighlight">
\[ = \mathbf{u}^T\mathbf{u} - \mathbf{u}^T\mathbf{v} - \mathbf{v}^T\mathbf{u} + \mathbf{v}^T\mathbf{v}\]</div>
<p>Now, remember that inner product is symmetric, ie, <span class="math notranslate nohighlight">\(\mathbf{u}^T\mathbf{v} = \mathbf{v}^T\mathbf{u}\)</span>, so</p>
<div class="math notranslate nohighlight">
\[ = \mathbf{u}^T\mathbf{u} + \mathbf{v}^T\mathbf{v} - 2\mathbf{u}^T\mathbf{v}\]</div>
<div class="math notranslate nohighlight">
\[ = \Vert\mathbf{u}\Vert^2 + \Vert\mathbf{v}\Vert^2 - 2\mathbf{u}^T\mathbf{v}\]</div>
<p>Now, let’s go back to the Pythagorean Theorem.</p>
<p><span class="math notranslate nohighlight">\( \mathbf{u}\)</span> and <span class="math notranslate nohighlight">\( \mathbf{v} \)</span> are perpendicular if and only if:</p>
<div class="math notranslate nohighlight">
\[ \Vert \mathbf{u} - \mathbf{v} \Vert^2 = \Vert \mathbf{u} \Vert^2 + \Vert \mathbf{v} \Vert^2\]</div>
<p>But we’ve seen that this means:</p>
<div class="math notranslate nohighlight">
\[ \Vert\mathbf{u}\Vert^2 + \Vert\mathbf{v}\Vert^2 - 2\mathbf{u}^T\mathbf{v}= \Vert \mathbf{u} \Vert^2 + \Vert \mathbf{v} \Vert^2\]</div>
<p>So now we can define perpendicularity in <span class="math notranslate nohighlight">\(\mathbb{R}^n\)</span>:</p>
<p><strong>Definition.</strong> Two vectors <span class="math notranslate nohighlight">\(\mathbf{u}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{v}\)</span> in <span class="math notranslate nohighlight">\(\mathbb{R}^n\)</span> are <strong>orthogonal</strong> to each other if <span class="math notranslate nohighlight">\(\mathbf{u}^T\mathbf{v} = 0.\)</span></p>
<p>As you can see, we have introduced a new term for this notion: <strong>orthogonal</strong>.</p>
<p>So when we are referring to vectors, <strong>orthogonal</strong> means the same thing as <strong>perpendicular</strong>.</p>
<div class="toggle docutils container">
<p>Question Time! Q20.2</p>
</div>
</section>
<section id="the-angle-between-two-vectors">
<h2>The Angle Between Two Vectors<a class="headerlink" href="#the-angle-between-two-vectors" title="Permalink to this heading">#</a></h2>
<p>There is an important connection between the inner product of two vectors and the <strong>angle</strong> between them.</p>
<p>This connection is very useful (eg, in thinking about data mining operations).</p>
<p>We start from the <strong>law of cosines:</strong></p>
<div class="math notranslate nohighlight">
\[ c^2 = a^2 + b^2 - 2ab\cos\theta\]</div>
<div class="cell tag_remove-input docutils container">
<div class="cell_output docutils container">
<img alt="_images/705b22831f24f444071064c48f9123fc7bb64675caad8a4c3c44623d9b13e3b2.png" src="_images/705b22831f24f444071064c48f9123fc7bb64675caad8a4c3c44623d9b13e3b2.png" />
</div>
</div>
<p>Now let’s interpret this law in terms of vectors <span class="math notranslate nohighlight">\(\mathbf{u}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{v}\)</span>.</p>
<p>Once again, it is the angle that these vectors make at the origin that we are concerned with:</p>
<div class="cell tag_remove-input docutils container">
<div class="cell_output docutils container">
<img alt="_images/dd33b285b1a14c43ed92c4b78abe6e996cbb6eb7569aab04f94081802e51fc42.png" src="_images/dd33b285b1a14c43ed92c4b78abe6e996cbb6eb7569aab04f94081802e51fc42.png" />
</div>
</div>
<p>Applying the law of cosines we get:</p>
<div class="math notranslate nohighlight">
\[\Vert\mathbf{u}-\mathbf{v}\Vert^2 = \Vert\mathbf{u}\Vert^2 + \Vert\mathbf{v}\Vert^2 - 2\Vert\mathbf{u}\Vert\Vert\mathbf{v}\Vert\cos\theta\]</div>
<p>Now, previously we calculated that:</p>
<div class="math notranslate nohighlight">
\[ \Vert\mathbf{u}-\mathbf{v}\Vert^2 = (\mathbf{u}-\mathbf{v})^T(\mathbf{u}-\mathbf{v})\]</div>
<div class="math notranslate nohighlight">
\[ = \Vert\mathbf{u}\Vert^2 + \Vert\mathbf{v}\Vert^2 - 2\mathbf{u}^T\mathbf{v}\]</div>
<p>Which means that</p>
<div class="math notranslate nohighlight">
\[ 2\mathbf{u}^T\mathbf{v} = 2\Vert\mathbf{u}\Vert\Vert\mathbf{v}\Vert\cos\theta\]</div>
<p>So</p>
<div class="math notranslate nohighlight">
\[ \mathbf{u}^T\mathbf{v} = \Vert\mathbf{u}\Vert\Vert\mathbf{v}\Vert\cos\theta\]</div>
<p>This is a <strong>very</strong> important connection between the notion of inner product and trigonometry.</p>
<p>As a quick check, note that if <span class="math notranslate nohighlight">\(\mathbf{u}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{v}\)</span> are nonzero, and <span class="math notranslate nohighlight">\(\mathbf{u}^T\mathbf{v} = 0\)</span>, then <span class="math notranslate nohighlight">\(\cos\theta = 0.\)</span></p>
<p>In other words, the angle between <span class="math notranslate nohighlight">\(\mathbf{u}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{v}\)</span> is 90 degrees (or 270 degrees). So this agrees with our definition of orthogonality.</p>
<p>One implication in particular concerns <strong>unit vectors.</strong></p>
<div class="math notranslate nohighlight">
\[ \mathbf{u}^T\mathbf{v} = \Vert\mathbf{u}\Vert\Vert\mathbf{v}\Vert\cos\theta\]</div>
<p>So</p>
<div class="math notranslate nohighlight">
\[ \frac{\mathbf{u}^T\mathbf{v}}{\Vert\mathbf{u}\Vert\Vert\mathbf{v}\Vert} = \cos\theta\]</div>
<div class="math notranslate nohighlight">
\[ \frac{\mathbf{u}^T}{\Vert\mathbf{u}\Vert}\frac{\mathbf{v}}{\Vert\mathbf{v}\Vert} = \cos\theta\]</div>
<p>Note that <span class="math notranslate nohighlight">\(\frac{\mathbf{u}}{\Vert\mathbf{u}\Vert}\)</span> and <span class="math notranslate nohighlight">\(\frac{\mathbf{v}}{\Vert\mathbf{v}\Vert}\)</span> are unit vectors.</p>
<p>So we have the very simple rule, that for two <strong>unit</strong> vectors, their inner product is the cosine of the angle between them!</p>
<div class="cell tag_remove-input docutils container">
<div class="cell_output docutils container">
<img alt="_images/514ad5e82bc13755c80fe3b4e7fcc116e2613f4e0993b694aec61347a9ee96d8.png" src="_images/514ad5e82bc13755c80fe3b4e7fcc116e2613f4e0993b694aec61347a9ee96d8.png" />
</div>
</div>
<p>Here <span class="math notranslate nohighlight">\(\mathbf{u} = \begin{bmatrix}0.95\\0.31\end{bmatrix},\)</span> and <span class="math notranslate nohighlight">\(\mathbf{v} = \begin{bmatrix}0.20\\0.98\end{bmatrix}.\)</span></p>
<p>So <span class="math notranslate nohighlight">\(\mathbf{u}^T\mathbf{v} = (0.95\cdot 0.20) + (0.31 \cdot 0.98) = 0.5\)</span></p>
<p>So <span class="math notranslate nohighlight">\(\cos\theta = 0.5.\)</span></p>
<p>So <span class="math notranslate nohighlight">\(\theta = 60\)</span> degrees.</p>
<p><strong>Example.</strong> Find the angle formed by the vectors:</p>
<div class="math notranslate nohighlight">
\[\begin{split}\mathbf{u} = \begin{bmatrix}1\\3\\-7\\-2\end{bmatrix} \;\;\mbox{and}\;\; \mathbf{v} = \begin{bmatrix}8\\-2\\4\\6\end{bmatrix}\end{split}\]</div>
<p><strong>Solution.</strong></p>
<p>First normalize the vectors:</p>
<div class="math notranslate nohighlight">
\[\Vert\mathbf{u}\Vert = \sqrt{1^2 + 3^2 + (-7)^2 + (-2)^2} = 7.93 \]</div>
<div class="math notranslate nohighlight">
\[\Vert\mathbf{v}\Vert = \sqrt{8^2 + (-2)^2 + 4^2 + 6^2} = 10.95 \]</div>
<p>So</p>
<div class="math notranslate nohighlight">
\[\begin{split}\frac{\mathbf{u}}{\Vert\mathbf{u}\Vert} = \begin{bmatrix}0.13\\0.38\\-0.88\\-0.25\end{bmatrix}
\;\;\mbox{and}\;\;\frac{\mathbf{v}}{\Vert\mathbf{v}\Vert} = \begin{bmatrix}0.73\\-0.18\\0.36\\0.54\end{bmatrix}\end{split}\]</div>
<p>Then calculate the cosine of the angle between them:</p>
<div class="math notranslate nohighlight">
\[\cos\theta = \frac{\mathbf{u}^T}{\Vert\mathbf{u}\Vert}\frac{\mathbf{v}}{\Vert\mathbf{v}\Vert}\]</div>
<div class="math notranslate nohighlight">
\[ = (0.13\cdot0.73)+(0.38\cdot -0.18)+(-0.88\cdot 0.36)+(-0.25\cdot0.54)\]</div>
<div class="math notranslate nohighlight">
\[= -0.44\]</div>
<p>Then:</p>
<div class="math notranslate nohighlight">
\[\theta = \cos^{-1}(-0.44)\]</div>
<div class="math notranslate nohighlight">
\[= 116\;\mbox{degrees.}\]</div>
<section id="example-application-cosine-similarity">
<h3>Example Application: Cosine Similarity.<a class="headerlink" href="#example-application-cosine-similarity" title="Permalink to this heading">#</a></h3>
<p>A typical example where these techniques are valuable arises in data science.</p>
<p>Let’s say we are given two documents <span class="math notranslate nohighlight">\(d_1\)</span> and <span class="math notranslate nohighlight">\(d_2\)</span>. Each is a collection of “words.”</p>
<p>For a goal such as information retrieval, we’d like to know whether the two documents are “similar”.</p>
<p>One common way to formalize similarity is to say that documents are similar if the sets of words they contain are similar.</p>
<p>We can measure this as follows: Construct a vector <span class="math notranslate nohighlight">\(\mathbf{x}_1\)</span> that counts the frequency of occurrence of certain words in <span class="math notranslate nohighlight">\(d_1\)</span>:</p>
<div class="math notranslate nohighlight">
\[\begin{split} \begin{bmatrix}
dog\\ car \\ house \\ \dots \\ door
\end{bmatrix} \;\; \rightarrow \;\;
\begin{bmatrix}
3\\ 7 \\ 4 \\ \dots \\ 20
\end{bmatrix} \end{split}\]</div>
<p>Do the same thing for <span class="math notranslate nohighlight">\(d_2\)</span>, yielding <span class="math notranslate nohighlight">\(\mathbf{x_2}\)</span>.</p>
<p>What we have done is taken individual documents and represented them as vectors <span class="math notranslate nohighlight">\(\mathbf{x}_1\)</span> and <span class="math notranslate nohighlight">\(\mathbf{x}_2\)</span> in a very high dimensional space, <span class="math notranslate nohighlight">\(\mathbb{R}^n\)</span>.</p>
<p>Here <span class="math notranslate nohighlight">\(n\)</span> could be 10,000 or more.</p>
<p>Now, to ask whether the two documents are similar, we simply ask “do their vectors point in the same general direction?”</p>
<p>And, despite the fact that we are in a very high dimensional space which we cannot visualize, we can nonetheless answer the question easily.</p>
<p>The angle between the two document-vectors is simply:</p>
<div class="math notranslate nohighlight">
\[\theta_{1,2} = \cos^{-1}\frac{\mathbf{x_1}^T}{\Vert\mathbf{x_1}\Vert}\frac{\mathbf{x_2}}{\Vert\mathbf{x_2}\Vert}\]</div>
</section>
</section>
</section>
<script type="text/x-thebe-config">
{
requestKernel: true,
binderOptions: {
repo: "binder-examples/jupyter-stacks-datascience",
ref: "master",
},
codeMirrorConfig: {
theme: "abcdef",
mode: "python"
},
kernelOptions: {
name: "python3",
path: "./."
},
predefinedOutput: true
}
</script>
<script>kernelName = 'python3'</script>
</article>
<footer class="prev-next-footer">
<div class="prev-next-area">
<a class="left-prev"
href="L19PageRank.html"
title="previous page">
<i class="fa-solid fa-angle-left"></i>
<div class="prev-next-info">
<p class="prev-next-subtitle">previous</p>
<p class="prev-next-title">PageRank</p>
</div>
</a>
<a class="right-next"
href="L21OrthogonalSets.html"
title="next page">
<div class="prev-next-info">
<p class="prev-next-subtitle">next</p>
<p class="prev-next-title">Orthogonal Sets and Projection</p>
</div>
<i class="fa-solid fa-angle-right"></i>
</a>
</div>
</footer>
</div>
<div class="bd-sidebar-secondary bd-toc"><div class="sidebar-secondary-items sidebar-secondary__inner">
<div class="sidebar-secondary-item">
<div class="page-toc tocsection onthispage">
<i class="fa-solid fa-list"></i> Contents
</div>
<nav class="bd-toc-nav page-toc">
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#the-challenge-extending-geometric-intuition-to-high-dimension">The Challenge: Extending Geometric Intuition to High Dimension</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#inner-product-review">Inner Product (Review)</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#vector-norm">Vector Norm</a><ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#normalization-to-unit-length">Normalization to Unit Length</a></li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#distance">Distance</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#orthogonality">Orthogonality</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#the-angle-between-two-vectors">The Angle Between Two Vectors</a><ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#example-application-cosine-similarity">Example Application: Cosine Similarity.</a></li>
</ul>
</li>
</ul>
</nav></div>
</div></div>
</div>
<footer class="bd-footer-content">
<div class="bd-footer-content__inner container">
<div class="footer-item">
<p class="component-author">
By Mark Crovella
</p>
</div>
<div class="footer-item">
<p class="copyright">
© Copyright 2020-2024.
<br/>
</p>
</div>
<div class="footer-item">
</div>
<div class="footer-item">
</div>
</div>
</footer>
</main>
</div>
</div>
<!-- Scripts loaded after <body> so the DOM is not blocked -->
<script src="_static/scripts/bootstrap.js?digest=5b4479735964841361fd"></script>
<script src="_static/scripts/pydata-sphinx-theme.js?digest=5b4479735964841361fd"></script>
<footer class="bd-footer">
</footer>
</body>
</html>