Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:03,360 --> 00:00:10,530
‫I know you are excited because you've been looking forward to this bug hunt for the entire section on
2
00:00:10,530 --> 00:00:14,790
‫linear algebra, so here we go, if you haven't already.
3
00:00:15,090 --> 00:00:22,500
‫Now is the time to pause the video, go through all of this code and find and fix all of the bugs.
4
00:00:22,830 --> 00:00:23,370
‫All right.
5
00:00:23,370 --> 00:00:31,050
‫So I can already see that we are going to need to start by importing some modules and special functions.
6
00:00:31,360 --> 00:00:32,910
‫So let's see.
7
00:00:33,450 --> 00:00:44,160
‫We will need import numpty as and P, we will need import simpy as SIM and we will need to import from
8
00:00:44,550 --> 00:00:51,390
‫AI Python that display the display and math functions.
9
00:00:51,810 --> 00:00:52,920
‫Possibly we will need.
10
00:00:52,920 --> 00:00:55,610
‫Oh we will definitely need matplotlib now I see it here.
11
00:00:55,950 --> 00:01:04,260
‫So also import matplotlib dot pi plot as p l t..
12
00:01:04,770 --> 00:01:05,300
‫All right.
13
00:01:05,310 --> 00:01:08,670
‫I think that's probably all of the modules that we will need.
14
00:01:09,030 --> 00:01:09,520
‫Let's see.
15
00:01:09,540 --> 00:01:11,700
‫Create a column vector and then.
16
00:01:11,700 --> 00:01:15,720
‫Oh this is a lot of complicated embedded functions here.
17
00:01:16,200 --> 00:01:17,430
‫Let's just see what happens.
18
00:01:17,510 --> 00:01:17,850
‫Hmm.
19
00:01:18,390 --> 00:01:18,770
‫All right.
20
00:01:18,780 --> 00:01:24,090
‫So first of all, this looks a little awkward to have these double square brackets here, but this is
21
00:01:24,090 --> 00:01:26,120
‫also clearly not a column vector.
22
00:01:26,130 --> 00:01:27,780
‫It's supposed to be a column vector.
23
00:01:28,650 --> 00:01:35,610
‫Well, what's going on here is that each row in The Matrix, when you specify a matrix using numpad
24
00:01:35,790 --> 00:01:39,540
‫array, each row needs to be in its own square brackets.
25
00:01:39,570 --> 00:01:46,250
‫So this needs to be in a square bracket and the three needs to be in a square brackets.
26
00:01:46,260 --> 00:01:50,130
‫So and those other parentheses, I think we're just there to confuse us.
27
00:01:50,640 --> 00:01:56,580
‫So there we go, each row in its own square bracket and then the entire matrix is in a set of square
28
00:01:56,580 --> 00:01:59,010
‫brackets that gives us a column vector.
29
00:01:59,880 --> 00:02:00,440
‫All right.
30
00:02:00,870 --> 00:02:04,550
‫Visualize scalar vector multiplication.
31
00:02:04,590 --> 00:02:04,980
‫Let's see.
32
00:02:04,990 --> 00:02:07,920
‫I'm just going to run this and we get an error.
33
00:02:08,490 --> 00:02:11,220
‫Now, this one is a bit tricky, actually.
34
00:02:11,230 --> 00:02:14,790
‫So we say the error message claims to be on this line.
35
00:02:15,810 --> 00:02:21,590
‫And if you look at the error message itself, it says string object is not callable.
36
00:02:21,960 --> 00:02:23,000
‫So what is going on here?
37
00:02:23,010 --> 00:02:25,470
‫There are actually no strings in this line.
38
00:02:26,100 --> 00:02:27,620
‫So this is really tricky.
39
00:02:27,630 --> 00:02:34,500
‫The mistake here, the the error actually happens on this line of code and what I'm doing wrong here.
40
00:02:34,530 --> 00:02:40,620
‫Well, you know, I whoever wrote this code, the terrible programmer who wrote this code, what they're
41
00:02:40,620 --> 00:02:43,650
‫trying to do is set the access to be square.
42
00:02:44,250 --> 00:02:49,330
‫But in fact, what they've done is set the axis as a variable to be string.
43
00:02:50,040 --> 00:02:59,250
‫So what we need to do is put this in parentheses like this, except now we still actually get this error.
44
00:02:59,460 --> 00:03:06,670
‫And basically what's happened here is we've just done some real fundamental damage to access by setting
45
00:03:06,670 --> 00:03:09,210
‫it equal to the string is square.
46
00:03:09,570 --> 00:03:16,050
‫And, you know, sometimes when you really get your python code all caught up in a bundle, it's good
47
00:03:16,050 --> 00:03:17,450
‫just to restart everything.
48
00:03:17,460 --> 00:03:22,190
‫So I'm going to select Col up here and restart it.
49
00:03:22,200 --> 00:03:23,970
‫It says, Are you sure you want to restart?
50
00:03:23,970 --> 00:03:25,800
‫All the variables will be lost.
51
00:03:26,100 --> 00:03:30,500
‫Now, sometimes that's problematic, but it's no problem here.
52
00:03:30,720 --> 00:03:37,110
‫All we need to do is rerun this cell here to re-import all of these modules.
53
00:03:38,210 --> 00:03:40,920
‫OK, and then I'm going to go back and rerun this.
54
00:03:41,270 --> 00:03:46,370
‫So now the plotting part looks good, but the legend doesn't quite look right.
55
00:03:46,370 --> 00:03:48,390
‫So I don't know what this percent is doing here.
56
00:03:48,410 --> 00:03:52,780
‫This is actually just Vector V here in Red and S.V..
57
00:03:52,790 --> 00:03:55,180
‫So I think we don't even need that percent sign.
58
00:03:55,660 --> 00:03:59,860
‫OK, now let's look at what's happening here just to make sure that we're doing the right thing.
59
00:04:00,080 --> 00:04:06,800
‫So we have this vector here, minus two to that is minus two comma to not minus a two.
60
00:04:07,190 --> 00:04:10,280
‫And the scalar here is zero point seven.
61
00:04:10,700 --> 00:04:17,000
‫Now if the vector is minus two plus two, which is this line here and a scalar is zero point seven,
62
00:04:17,120 --> 00:04:20,480
‫then actually this blue line should probably come up to around here.
63
00:04:20,480 --> 00:04:21,690
‫It shouldn't be the dot.
64
00:04:21,740 --> 00:04:24,500
‫I think something is fundamentally wrong here.
65
00:04:24,770 --> 00:04:28,620
‫Let's also check out what this variable S.V. actually is.
66
00:04:28,640 --> 00:04:33,350
‫So if we print out S.V., then it's just a zero.
67
00:04:34,190 --> 00:04:37,670
‫This is actually not this vector times point seven.
68
00:04:38,000 --> 00:04:39,140
‫And so what's going on here?
69
00:04:39,140 --> 00:04:44,060
‫I have no idea what's going on here, actually, but it looks like we are computing the DOT product
70
00:04:44,060 --> 00:04:45,580
‫between Eskom.
71
00:04:45,620 --> 00:04:51,530
‫S, so a vector that is point seven point seven and minus two plus two.
72
00:04:51,960 --> 00:04:54,500
‫Now it actually makes sense where this result comes from.
73
00:04:54,780 --> 00:05:02,180
‫Essentially what we are doing here is saying point seven times minus two plus point seven times plus
74
00:05:02,180 --> 00:05:03,540
‫two and that equals zero.
75
00:05:03,830 --> 00:05:05,640
‫So this is totally, totally wrong.
76
00:05:05,660 --> 00:05:12,520
‫This actually is just supposed to be S times V like this.
77
00:05:13,220 --> 00:05:16,490
‫And now when we print this out, we see we get what we expect.
78
00:05:16,520 --> 00:05:22,660
‫So point seven times two is one point four and then we just get a scaled version of this vector.
79
00:05:23,000 --> 00:05:26,330
‫Of course, now we've gotten some other errors and the errors on this line.
80
00:05:26,840 --> 00:05:34,280
‫And you can actually see that this is you know, we need the first component here and the second component
81
00:05:34,280 --> 00:05:34,670
‫here.
82
00:05:36,860 --> 00:05:39,350
‫That should be one for the second component.
83
00:05:39,920 --> 00:05:40,750
‫All right.
84
00:05:40,760 --> 00:05:42,500
‫Now, this looks good.
85
00:05:42,800 --> 00:05:48,150
‫I'm going to say that is the successful completion of this particular problem here.
86
00:05:49,040 --> 00:05:49,450
‫All right.
87
00:05:49,460 --> 00:05:56,330
‫So here we go, algorithm to compute the DOT product so we have some random vectors and then we do the
88
00:05:56,780 --> 00:06:05,720
‫DOT product by setting the DOT product to be this variable, to be zero and adding to itself the corresponding
89
00:06:05,720 --> 00:06:11,510
‫element in V times W and then we compare that to the function num num, pi, dot.
90
00:06:12,380 --> 00:06:12,820
‫All right.
91
00:06:12,830 --> 00:06:15,710
‫So we already get an error and this is related to shape.
92
00:06:15,730 --> 00:06:21,830
‫So I hope that you already caught that one so you could change this to seven or you could have changed
93
00:06:21,830 --> 00:06:22,410
‫that to eight.
94
00:06:22,460 --> 00:06:23,620
‫Either way, it would be fine.
95
00:06:24,810 --> 00:06:25,160
‫Hmm.
96
00:06:25,260 --> 00:06:30,990
‫Now, these two answers are actually not equal to each other and what is going on here?
97
00:06:31,350 --> 00:06:35,980
‫Well, if we look at this line of code carefully, it looks like this was a typo.
98
00:06:36,000 --> 00:06:37,920
‫This probably should say I.
99
00:06:38,220 --> 00:06:43,590
‫Otherwise, it was fixed to be the first or the second element in Vector W.
100
00:06:44,440 --> 00:06:44,940
‫Let's see.
101
00:06:44,950 --> 00:06:49,170
‫And now we get the same answer for both of these mechanisms.
102
00:06:49,950 --> 00:06:54,630
‫And now I'd like to show you a little bit of a shortcut in Python for getting this to work.
103
00:06:55,140 --> 00:07:02,130
‫So if you want to set a variable to be equal to itself plus something else, you can write out the line
104
00:07:02,130 --> 00:07:03,980
‫of code like this totally fine.
105
00:07:03,990 --> 00:07:05,730
‫I think this looks very clear.
106
00:07:06,060 --> 00:07:12,750
‫However, it's possible to write it out in even more condensed language, and that's by saying plus
107
00:07:12,750 --> 00:07:15,000
‫equals instead of just equals.
108
00:07:15,570 --> 00:07:23,760
‫So Python will interpret this expression here as saying that the DOT product equals itself, plus whatever
109
00:07:23,760 --> 00:07:25,800
‫is on the right hand side of this equation.
110
00:07:26,430 --> 00:07:27,440
‫And you can see that here.
111
00:07:27,450 --> 00:07:34,300
‫Now I'm running this again and you get the same answer for NPR dot and our algorithm here.
112
00:07:35,160 --> 00:07:40,380
‫Now, obviously, these answers will change every time I run it because these are random numbers.
113
00:07:41,070 --> 00:07:41,770
‫Very nice.
114
00:07:42,030 --> 00:07:42,770
‫Let's see.
115
00:07:43,770 --> 00:07:48,570
‫This doesn't exactly tell us what we're supposed to be doing here, but I can look down.
116
00:07:48,580 --> 00:07:55,800
‫So here we are creating some data as a range of numbers that goes from zero to nine.
117
00:07:56,070 --> 00:07:59,550
‫And then we add some normally distributed random numbers.
118
00:07:59,910 --> 00:08:05,590
‫And here we are computing the correlation and confirm with the number by correlation coefficient.
119
00:08:05,640 --> 00:08:10,140
‫OK, so I expect these two variables to be identical to each other.
120
00:08:10,470 --> 00:08:14,820
‫And they're kind of close, I guess, but certainly not identical.
121
00:08:15,300 --> 00:08:16,480
‫Let's see what's going wrong.
122
00:08:17,010 --> 00:08:23,850
‫So remember from the video that I showed about computing, the correlation coefficient, that was an
123
00:08:23,850 --> 00:08:31,260
‫application of the DOT product in statistics that the numerator of the correlation coefficient is the
124
00:08:31,260 --> 00:08:37,620
‫DOT product between the two vectors and the denominator is the square root of the dot product of the
125
00:08:37,620 --> 00:08:43,770
‫vector with itself times the square root of the dot product of the other vector with itself.
126
00:08:44,100 --> 00:08:46,190
‫And then we do this division.
127
00:08:46,200 --> 00:08:48,570
‫And so actually all of this is correct.
128
00:08:48,570 --> 00:08:51,080
‫However, we are missing one thing.
129
00:08:51,090 --> 00:08:56,910
‫What does that one thing that we're missing, the one thing that we're missing is that these data vectors,
130
00:08:56,910 --> 00:09:02,300
‫these data streams need to be mean centered, so means center.
131
00:09:02,610 --> 00:09:07,110
‫And that just means subtracting the mean from the data set.
132
00:09:07,120 --> 00:09:13,500
‫So data one equals data one minus number, I mean of data one.
133
00:09:14,020 --> 00:09:19,080
‫And now if you are already thinking that this can be simplified, then good for you.
134
00:09:19,260 --> 00:09:21,570
‫We're going to do that like this.
135
00:09:22,830 --> 00:09:31,170
‫And now that's for data one, and then we repeat this for data, too, and now we get exactly the same
136
00:09:31,170 --> 00:09:34,830
‫correlation coefficient for both of these operations.
137
00:09:35,370 --> 00:09:40,740
‫And actually, it's interesting to see that once you get down to about 10 or 12 or whatever, this is
138
00:09:40,980 --> 00:09:46,230
‫degrees of precision, then eventually these algorithms do start to diverge a tiny bit.
139
00:09:46,500 --> 00:09:52,500
‫And that's because kuriko of this function is actually implementing a slightly different and more efficient
140
00:09:52,500 --> 00:09:55,740
‫and faster algorithm than what I'm showing here.
141
00:09:56,100 --> 00:09:57,410
‫All right, here we go.
142
00:09:57,420 --> 00:10:04,410
‫We are trying to compute the outer product, and this looks, again, like one of these approaches where
143
00:10:04,410 --> 00:10:07,560
‫we compare the numpties function outr.
144
00:10:07,650 --> 00:10:15,510
‫So the built in function outr to computing this manually, using the algorithm for computing the outer
145
00:10:15,510 --> 00:10:15,960
‫product.
146
00:10:16,350 --> 00:10:23,460
‫So remember that one way to compute the outer product is to set each row of the outer product matrix
147
00:10:23,850 --> 00:10:26,960
‫to be the row of the right matrix.
148
00:10:26,970 --> 00:10:33,840
‫So are the right vector, which is going to be this one times each element of the left vector, which
149
00:10:33,840 --> 00:10:35,280
‫here looks like one.
150
00:10:36,060 --> 00:10:39,260
‫So that already tells me that there's something going wrong here.
151
00:10:39,810 --> 00:10:41,790
‫So let's let's just try to run this.
152
00:10:41,790 --> 00:10:44,550
‫And this says could not broadcast input.
153
00:10:44,560 --> 00:10:44,760
‫Right.
154
00:10:44,790 --> 00:10:52,050
‫OK, so based on what I just described as the algorithm for computing the outer product matrix, I can
155
00:10:52,050 --> 00:10:54,830
‫already determine that this is incorrect.
156
00:10:54,840 --> 00:11:02,220
‫This should be the entire row vector on the right and each element of the column vector on the left
157
00:11:02,340 --> 00:11:02,960
‫like this.
158
00:11:03,810 --> 00:11:04,260
‫Hmm.
159
00:11:04,290 --> 00:11:08,700
‫So now we don't get any explicit python errors.
160
00:11:09,060 --> 00:11:18,240
‫But when I say the outer so this outer product matrix here, minus num outer, we get zeros for the
161
00:11:18,240 --> 00:11:22,680
‫first four rows and then non zeros for these last four rows.
162
00:11:23,130 --> 00:11:26,040
‫So there's clearly something strange happening here.
163
00:11:26,070 --> 00:11:26,910
‫Let's try it again.
164
00:11:27,820 --> 00:11:28,230
‫Hmm.
165
00:11:28,440 --> 00:11:29,580
‫Again, the same thing.
166
00:11:29,610 --> 00:11:35,070
‫So now we get all zeros for the first four rows and a couple of zeros here as well.
167
00:11:35,340 --> 00:11:39,880
‫But it seems like the first four rows of zeros is pretty consistent.
168
00:11:40,380 --> 00:11:44,050
‫I wonder what would happen if I would change the sizes of these matrices.
169
00:11:44,070 --> 00:11:49,470
‫So let's say what if this is like six elements and this is eight elements?
170
00:11:50,050 --> 00:11:57,240
‫Oh, now we actually do get an error message and it says index six is out of bounds for axis zero with
171
00:11:57,240 --> 00:11:57,960
‫size six.
172
00:11:58,020 --> 00:12:03,160
‫OK, what's actually happening is in this line here for the range.
173
00:12:03,510 --> 00:12:09,060
‫Now, notice that we are what we are actually looping through is elements in one.
174
00:12:09,480 --> 00:12:15,270
‫But what we are looping through here, what we are specifying is the range of the elements is actually
175
00:12:15,450 --> 00:12:17,250
‫coming from the size of O2.
176
00:12:18,240 --> 00:12:21,150
‫So I'm just going to replace the two with one.
177
00:12:21,330 --> 00:12:23,460
‫And now we get a matrix of all zeros.
178
00:12:23,700 --> 00:12:32,100
‫But this is a really tricky point because, you know, when it was this way, so how it was initially,
179
00:12:32,580 --> 00:12:37,680
‫we didn't get any python coding errors because technically we haven't done anything wrong in terms of
180
00:12:37,680 --> 00:12:38,400
‫programming.
181
00:12:38,640 --> 00:12:44,550
‫We've done something wrong in terms of of math and indexing, but we haven't done anything illegal in
182
00:12:44,550 --> 00:12:45,930
‫terms of python coding.
183
00:12:46,380 --> 00:12:47,610
‫But the result is wrong.
184
00:12:47,610 --> 00:12:53,510
‫And if you weren't actually comparing this, then, yeah, you probably wouldn't even notice.
185
00:12:53,520 --> 00:12:56,020
‫You might not even notice that this error was in there.
186
00:12:56,400 --> 00:13:00,480
‫So these are the most devious kinds of coding mistakes.
187
00:13:00,760 --> 00:13:02,040
‫Anyway, let's move on.
188
00:13:02,790 --> 00:13:04,860
‫OK, matrix multiplication.
189
00:13:05,130 --> 00:13:08,370
‫So we have a random five by five matrix.
190
00:13:08,370 --> 00:13:12,000
‫Multiply it by the five by five identity matrix.
191
00:13:12,270 --> 00:13:18,210
‫And what we should see is a full matrix of random numbers, which we don't see.
192
00:13:18,210 --> 00:13:21,380
‫In fact, we see a matrix that's mostly zeros.
193
00:13:21,900 --> 00:13:28,500
‫So what's happening here is that the asterisk is implementing Element Y's multiplication, but we need
194
00:13:28,830 --> 00:13:31,190
‫full on matrix multiplication.
195
00:13:31,650 --> 00:13:32,730
‫So there you go.
196
00:13:33,600 --> 00:13:35,430
‫All right, let's go on to the next cell.
197
00:13:35,440 --> 00:13:38,220
‫It looks like this is a similar kind of problem.
198
00:13:38,220 --> 00:13:44,340
‫So I can already see that this is a little bit weird here, multiplying a by the identity matrix.
199
00:13:45,590 --> 00:13:54,110
‫So here we see the original Matrix A. Here we are doing Element Y's multiplication and this says there's
200
00:13:54,110 --> 00:13:55,540
‫actually a size problem.
201
00:13:56,120 --> 00:14:02,180
‫So for Element Y's multiplication, it's not possible with these two matrices because they are different
202
00:14:02,180 --> 00:14:02,680
‫sizes.
203
00:14:02,690 --> 00:14:04,250
‫They have a different number of elements.
204
00:14:04,580 --> 00:14:09,220
‫So let's see what would happen if we would replace this with matrix multiplication.
205
00:14:09,650 --> 00:14:10,430
‫And there you go.
206
00:14:10,440 --> 00:14:19,460
‫We get that a on the top is the same thing as a matrix multiplying by the identity matrix on the bottom
207
00:14:19,460 --> 00:14:19,730
‫here.
208
00:14:19,760 --> 00:14:23,810
‫So you can see that this matrix is the same as this matrix.
209
00:14:24,750 --> 00:14:25,780
‫All right here.
210
00:14:26,640 --> 00:14:31,090
‫This one says Random matrices are convertible.
211
00:14:31,340 --> 00:14:37,130
‫So what we do is create a matrix of random integers between minus five and plus five.
212
00:14:37,440 --> 00:14:39,950
‫It's five by five and it's random.
213
00:14:39,960 --> 00:14:41,310
‫So it should be convertible.
214
00:14:41,310 --> 00:14:44,180
‫So I don't really see what the issue is here.
215
00:14:44,190 --> 00:14:50,430
‫We should get the identity matrix because the Matrix times its inverse is the identity matrix.
216
00:14:50,460 --> 00:14:51,390
‫Let's see what's going on.
217
00:14:52,740 --> 00:15:01,530
‫Hmm, module number II has no attribute in the problem here is that it is not in the main PI module,
218
00:15:01,800 --> 00:15:06,240
‫it's actually in the Lynn alg module or the sub module.
219
00:15:06,960 --> 00:15:12,960
‫OK, so now we've multiplied a by its inverse and we get the identity matrix.
220
00:15:14,650 --> 00:15:22,330
‫Let's see, so here we are plotting the Igen spectrum, so we create a matrix, multiply that matrix
221
00:15:22,330 --> 00:15:27,550
‫by its own transpose, remember, that gives us a square symmetric matrix.
222
00:15:27,560 --> 00:15:31,510
‫This matrix is already square, but it does give us a symmetric matrix.
223
00:15:32,020 --> 00:15:33,990
‫And let's just see what's going on here.
224
00:15:35,320 --> 00:15:37,500
‫So we don't get any python errors.
225
00:15:37,510 --> 00:15:39,120
‫So that part seems OK.
226
00:15:39,610 --> 00:15:41,800
‫But let's look at these eigenvalues.
227
00:15:41,800 --> 00:15:48,670
‫You know, there's like 25 of these eigenvalues, but this is just a five by five matrix and we can
228
00:15:48,670 --> 00:15:49,570
‫even confirm this.
229
00:15:49,570 --> 00:15:57,250
‫So I'm going to print out num pi, the shape of M, and this is a five by five matrix.
230
00:15:57,250 --> 00:16:01,120
‫So there's really only supposed to be five eigenvalues.
231
00:16:01,150 --> 00:16:02,370
‫Let's see what's going on.
232
00:16:02,650 --> 00:16:10,100
‫I'm going to look at the help file or the dock string for IG and let's see if this gives us some insight.
233
00:16:10,480 --> 00:16:19,510
‫So this returns W is the eigenvalues and then V the second output is the Igen vectors.
234
00:16:19,870 --> 00:16:22,610
‫So in fact the order of the output is wrong here.
235
00:16:22,630 --> 00:16:23,620
‫This is just swopped.
236
00:16:23,890 --> 00:16:29,260
‫This should be the eigenvalues and this should be the eigenvectors.
237
00:16:30,490 --> 00:16:36,850
‫And now we only get five components, five things being plotted here, which is consistent.
238
00:16:36,850 --> 00:16:40,810
‫That is exactly how many we expect for the eigenvalues.
239
00:16:41,340 --> 00:16:44,470
‫By the way, I haven't yet introduced you to this function.
240
00:16:44,470 --> 00:16:47,740
‫Flatten num pi matrix, dot flatten.
241
00:16:48,160 --> 00:16:54,850
‫But essentially what that's doing is taking this matrix or whatever is the input matrix and expanding
242
00:16:54,850 --> 00:16:59,130
‫it out from a matrix into one really long array, a really long vector.
243
00:16:59,800 --> 00:17:06,730
‫And so for a the eigenvectors matrix, which is a five by five matrix, when you flatten it you get
244
00:17:06,730 --> 00:17:12,730
‫25 total elements and that's why you get a line of twenty five here.
245
00:17:12,740 --> 00:17:18,520
‫So these are just all the individual components of all the, each of the five eigenvectors.
246
00:17:18,790 --> 00:17:22,180
‫OK, so set that back so that looks better.
247
00:17:23,080 --> 00:17:29,380
‫By the way, you can also see here that the eigenvalues are not intrinsically sorted by magnitude,
248
00:17:29,680 --> 00:17:37,000
‫so they don't come out as the largest eigenvalues first, that has to do with the estimation algorithm
249
00:17:37,000 --> 00:17:40,300
‫that Python uses to compute the eigenvalues.
250
00:17:40,870 --> 00:17:42,600
‫Anyway, let's move on.
251
00:17:42,640 --> 00:17:47,090
‫This looks like the last exercise to work on for this bug hunt.
252
00:17:47,530 --> 00:17:51,670
‫So it looks like we are creating a matrix of random integers.
253
00:17:51,970 --> 00:17:53,690
‫It's a 10 by 20 matrix.
254
00:17:53,690 --> 00:17:58,450
‫So actually we cannot perform an eigenvalue decomposition on this matrix.
255
00:17:58,450 --> 00:18:00,660
‫But of course, we can do an SVOD.
256
00:18:01,240 --> 00:18:02,580
‫So we do the DVD.
257
00:18:03,400 --> 00:18:11,080
‫We create a full matrix based on a diagonal matrix based on these singular values.
258
00:18:11,350 --> 00:18:15,700
‫And then we try to reconstruct that matrix and make some plots.
259
00:18:16,150 --> 00:18:16,510
‫All right.
260
00:18:16,520 --> 00:18:19,720
‫And we already get an error and it's related to size.
261
00:18:20,000 --> 00:18:27,200
‫And this is, in fact, something that I discussed in the previous video on the singular value decomposition.
262
00:18:27,610 --> 00:18:36,010
‫So what we need to do is first reconstruct as to be a Xeros matrix corresponding to the size or the
263
00:18:36,010 --> 00:18:48,550
‫shape of the Matrix A and then we need to loop over the elements in S so range of length s and then
264
00:18:48,550 --> 00:18:55,510
‫we say s the ith diagonal element equals the corresponding element in the little S.
265
00:18:55,540 --> 00:18:56,620
‫So in vector s.
266
00:18:57,290 --> 00:18:59,380
‫OK, so now let's see how this looks.
267
00:18:59,890 --> 00:19:01,510
‫Oh we still get an error.
268
00:19:01,790 --> 00:19:03,810
‫It's another mismatched dimension.
269
00:19:03,820 --> 00:19:04,090
‫Hey.
270
00:19:04,090 --> 00:19:10,960
‫But you know, looking at the order, this is not the correct order, it should be U times Sigma Times
271
00:19:10,960 --> 00:19:19,990
‫V so I'm going to rewrite this like this you time Sigma Times V actually this is V transpose python
272
00:19:19,990 --> 00:19:22,720
‫will automatically spit out V transpose.
273
00:19:24,130 --> 00:19:25,860
‫OK, so this is looking good.
274
00:19:25,870 --> 00:19:32,230
‫Here we see the Matrix A, the reconstructed matrix A and the difference between the two, which is
275
00:19:32,230 --> 00:19:33,070
‫an empty plot.
276
00:19:33,070 --> 00:19:33,940
‫It's all zeros.
277
00:19:34,090 --> 00:19:38,980
‫And that's comforting because that means that we have reconstructed this matrix accurately.
278
00:19:40,070 --> 00:19:45,770
‫I hope you enjoyed this bug hunt and more generally, I hope you enjoyed learning a little bit about
279
00:19:45,770 --> 00:19:48,980
‫linear algebra from this section of the course.
280
00:19:49,460 --> 00:19:55,610
‫As I mentioned in the beginning of this section, linear algebra is a beautiful, rich and really important
281
00:19:55,610 --> 00:19:56,880
‫topic in mathematics.
282
00:19:57,140 --> 00:20:02,450
‫I hope you feel like you got a little bit of a taste, a little bit of enthusiasm about learning linear
283
00:20:02,450 --> 00:20:03,830
‫algebra from this section.
284
00:20:04,400 --> 00:20:09,440
‫And maybe you are inspired to continue learning about linear algebra in more depth.
28437
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.