================================================================= TITLE: Deep learning 2 DATE: 2024-11-26 (November 26, 2024 at 04:02 PM) DURATION: 01:59:57 (7197 seconds) WORDS: 13,974 words SPEECH ID: 26XPVAWX55J2LHJW ================================================================= --- AI SUMMARY --- neural network programming, forward propagation, backward propagation, logistic regression, binary classification, feature vector, training set, cost function, gradient descent, sigmoid function, derivative computation, chain rule, vectorization techniques, intermediate variables, final output variable --- FULL TRANSCRIPT --- [00:00] 0: It could have been any number of girls, because he already planned it all out. And I guess you [159:33:20] 1: music, hello and welcome back in this week we're going to go over the basics of neural network programming, it turns out that when you implement a neural network, there are some influential techniques that are going to be really important. For example, if you have a training set of m training examples, you might be used to processing the training set by having a for loop step through your m training examples, but it turns out that when you implement in your network, you usually want to process your entire training set without using an explicit for loop, to loop over your entire training set. So you'll see how to do that in distance materials. Another idea, when you organize the computation in neural network, usually you have what's called a forward pass, or forward propagation step, followed by a backward pass, or what's called a backward propagation step. And so in this week's materials, he also gained intuition about why the computations in learning in a neural network can be organized in this forward propagation and a separate backward propagation for this week's materials. I want to convey these ideas using logistic regression in order to make the ideas easier to understand. But even if you've seen logistic regression before, I think that there'll be some new and interesting ideas for you to pick up in this week's materials. So that let's get started. Logistic Regression is an algorithm for binary classification, so let's start by setting up the problem. Here's an example of a binary classification problem. You might have an input of an image like that, and want to output a label to recognize this image as in either a cat, in which case you output one, or non cat, in which case you output zero. And we're going to use Y to denote the output label. Let's look at how an image is represented in a computer. To store an image, your computer stores three separate matrices corresponding to the red, green and blue COVID channels of this image. So if your input image is 64 pixels by 64 pixels, then you would have 364, by 64 matrices corresponding to the red, green and blue pixel intensity values for your image, although, to make these from the slide, I drew these as much smaller matrices. So these are actually five by four matrices, rather than 64 by 64 so to turn these pixel intensity values into a feature vector, what we're going to do is unroll all of these pixel values into a input feature vector x. So to unroll all of these pixel intensity values into a feature vector, what we're going to do is define a feature vector x corresponding to this image as follows. We're just going to take all the pixel values, 255231, [977:57:20] 1: and so on. 255231, [992:42:40] 1: and so on, until we've listed all the red pixels again, eventually, 255, 13455134, and so on, until we get a very long feature vector listing out all the red, green and blue pixel intensity values of this image. So if this image is a 64 by 64 image, the total dimension of this vector x will be 64 by 64 by three, because that's the total numbers we have in all of these matrices, which, in this case, turns out to be 12283, that's what you get when you multiply out those numbers. And so we're going to use an x equals 12288, to represent the dimension of the input features x, and sometimes for gravity, I might also just use low case n to represent the dimension of this input feature vector. So in binary classification, our goal is to learn the classifier that can input an image represented by its feature vector x, and predict whether the corresponding label y is one or zero. That is whether this is a cat image or a non cat image. Let's now lay out some of the notation that we use throughout the rest of this course. A single training example is represented by a pair x comma y, where x is an n, x dimensional feature vector and y the label is either zero or one. Your training set will comprise lower case n training examples, and so your training sets will be written, x1, comma, y1 which is the input and output for your first training example. X2 comma, y2 for the second training example, up to x, m, y, M, which is your last training example. And then that all together, is your entire training set. So I'm going to use lowercase m to denote the number of train examples, and sometimes to emphasize that this is the number of train examples. I might write this as m subscript train. And when we talk about a test set, we might sometimes use M subscript test to denote the number of test examples. So that's the number of test examples. Find. Finally, to put all of the training examples into a more compact notation, we're going to define a matrix capital X, as defined by taking your training set inputs, x1 x2 and so on, and stacking them in columns, 72 x1 and put that as the first column of this matrix, and x2 put that as the second column, and so on down to x m, then this is the matrix capital X. So this matrix X will have m columns, where m is the number of train examples and the number of rows, or the height of this matrix is NX. Notice that in other causes, you might see the matrix capital x defined by stacking up the training examples in rows like so x1 transpose down to XM transpose. But it turns out that when you're implementing neural networks, using this convention I have on the left will make the implementation much easier. So just to recap, x is a n x by m dimensional matrix, and when you implement this in Python, you see that x dot shape. That's the Python command for finding the shape of a matrix that this is an NX comma m, this just means is an NX by m dimensional matrix. So that's how you group the training examples. Input X into a matrix. How about the output labels y? It turns out that to make your implementation of a neural network easier, it'll be convenient to also stack y in columns. So let me define capital Y to be equal to y1, y2, up to y, M, like so, so y. Here will be a one by m dimensional matrix, and again, to use the Python notation, the shape of y will be one comma m, which just means this is a one by m matrix. And as you implement your neural network later in this course, you find that a useful convention will be to take the data associated with different training examples and by data on either x or y or other quantities you see later, but to take the stuff or the data associated with different training examples and to stack them in different columns, like we've done here for both x and y. So that's the notation we'll use for logistic regression and for neural networks later in this course. If you ever forget what a piece of notation means, like, what is m or what is n or what is something else. We've also posted on the course website, the notation guide we can use to quickly look up what any particular piece of notation means. So that let's go on to the next video. We'll start to flesh out logistic regression using this notation. I [2439:12:00] 1: In this video, we'll go over logistic regression. This is a learning algorithm that you use when the output labels y in the supervised learning problem are either zero or one. So for binary concentration problems, given an input feature vector X may be corresponding to an image that you want to recognize as either a cat picture or not a cat picture. You want an algorithm that can output a prediction, which we call y hat, which is your estimate of y more formally, you want y hat to be the probability of the chance that y is equal to one giving the input features x. So in other words, if x is a picture, as we saw in the last video, you want y hat to tell you what is the chance that this is a cat picture. So X, as we said in the previous video, is a n x dimensional vector, given that the parameters of logistic regression will be w, which is also an n x dimensional vector, together with B, which is just a real number. So given an input x and the parameters w and b, how do we generate the output Y hat? Well, one thing you could try that doesn't work would be to have Y hat be W transpose X plus B, kind of a linear function of the input x. And in fact, this is what you use if you were doing linear regression. But this isn't a very good algorithm for binary classification, because you want y hat to be the chance that y is equal to one, so y hat should really be between zero and one, and it's difficult to enforce that because W transpose X plus B can be much bigger than one, or it can even be negative, which does not make sense for a probability that you want to be between zero and one. So in logistic regression, our output is instead going to be y hat equals the sigmoid function applied to this quantity, this is what the sigmoid function looks like. If on the horizontal axis I plot z, then the function, sigmoid of Z looks like this, so it goes smoothly from zero up to one. Let me label my axis here. This is zero and crosses the vertical axis at 0.5 so this is what sigmoid of Z looks like. And we're going to use z to denote this quantity W transpose X plus B. Here's the formula for the sigmoid function, sigmoid of z, where z is a real number, is one over one plus e to the negative z. So notice a couple things. If z is very large, then e to the negative z will be close to zero. So then sigmoid or z will be approximately one over one, plus something very close to zero, because e to the negative of the very large number will be close to zero. So this is close to one. And indeed We if you look on the plot on the left, if z is very large, then sigmoid of z is very close to one. Conversely, if z is very small or it is a very large negative number, then sigmoid of z becomes one over one plus eta negative z, and this becomes, it's a huge number. So this becomes, you know, think of it as one over one plus a number that is very, very big. [3477:46:40] 1: And so that's close to zero. And indeed you see that as z becomes a very large negative number, sigmoid of z goes very close to zero. So when you implement logistic regression, your job is to try to learn parameters w and b, so that y hat becomes a good estimate of the chance of y being equal to one before moving on, just another note on the notation. When we program neural networks, we'll usually keep the parameter W and parameter b separate where, here B corresponds to an interceptor in some other classes, you might have seen a notation that handles this differently. In some conventions, you define an extra feature called x zero, and if that equals a one, so that now x is in R of x equals one. And then you define y hat to be equal to sigma of theta, transpose x. In this alternative notational convention, you have vector parameters, theta, theta zero, theta one, theta two, down to theta and x. And so theta zero plays a row of B. That's just a row number and theta one down to theta NX, theta row of W. It turns out, when you implement your neural network, will be easier to just keep B and W as separate parameters. And so in this class, we will not use any of this notational convention that I just wrote in red, if you've not seen this notation before in other classes, don't worry about it. It's just that. For those of you that have seen this notation, I wanted to mention explicitly that we're not using that notation in this course. But if you've not seen this before, it's not important and you don't need to worry about it. So you've now seen what the logistic regression model looks like next to train the parameters w and b, you need to Define a cost function. Let's do that In The mixer. [4533:20:00] 1: The video. [4577:03:58] 1: In the previous video, you saw the logistic regression model to train the parameters w and b of your logistic regression model, you need to define a cost function. Let's take a look at the cost function you can use to train logistic regression. To recap, this is what we had defined from the previous slide. So the output Y hat is sigmoid of W transpose X plus b, where sigmoid of z is as defined here. So to learn parameters for your model, you're given a training set of n training examples, and it seems natural that you want to find parameters w and b, so that at least on the training set, the outputs you have the predictions you have on the training set, which you only write as y. Hat I that that will be close to the ground truth labels y, I that you got in training set. So to fill in a little bit more detail for the equation on top, we had said that Y hat is as defined at the top for a training example X and, of course, for each training example, we're using these superscripts with round brackets with parentheses to index into different training examples. Your prediction on training example i, which is Y hat i is going to be obtained by taking the sigmoid function and applying it to w, transpose Xi, the input that we train the example plus b. And you can also define z i as follows, so zi is equal to W, transpose Xi plus b. So throughout this course, we're going to use this notational convention that the superscript parentheses I refers to data via x or y or z or something else associated with the i training example, associated with the I example. Okay, that's what the superscript i in parentheses means. Now let's see what loss function or an error function, we can use to measure how well our algorithm is doing. One thing you could do is define the loss when your algorithm outputs y hat and the true label is y to be maybe the squared error, or one half A square error. It turns out that you could do this, but in logistic regression, people don't usually do this, because when you come to learn the parameters, you find that the optimization problem, which we'll talk about later, becomes non convex. So you end up with optimization problem with multiple local optima, so gradient descent may not find the global optimum if you didn't understand the last couple of comments, don't worry about it. We'll get to it in a later video. But the intuition to take away is that this function, l, called the loss function, is a function we'll need to define to measure how good our output Y hat is when the true label is y and squared error, seems like it might be a reasonable choice, except that it makes gradient descent not work well. So in logistic regression, we will actually define a different loss function that plays a similar role as squared error, that will give us an optimization problem that is convex, and so we'll see in a later video, becomes much easier to optimize. So what we use in logistic regression is actually the following loss function, which I'm just going to write out here, is negative [5487:33:20] 1: y, log y, hat plus [5505:25:20] 1: one minus y, log one minus y hat, here's some intuition for why this loss function makes sense. Keep in mind that if we were using squared error, then we want this squared error to be as small as possible. And with this logistic regression loss function, we'll also want this to be as small as possible. So understand why this makes sense. Let's look at the two cases. In the first case, let's say y is equal to one, then the loss function, y. Hat, comma y is just this first term, right? This negative sign, so it's negative log y. Hat, if y is equal to one, because if y equals one then the second term, when one is y, is equal to zero. So this says, if y equals one, you want a negative log y hat to be as small as possible. So that means you want [5743:33:20] 1: log y hat to be large, [5762:45:20] 1: to be as big as possible. And that means you want y hat to be large, but because Y hat is the SIG one function, it can never be bigger than one. So this is saying that if y is equal to one, you want y hat to be as big as possible, but it can't ever be bigger than one. So saying you want y hat to be close to one as well. The other case is if y equals zero, and if y equals zero, then this first term in the loss function is equal to zero, because y zero and the second term defines the loss function. So the loss becomes negative, log one minus y hat and so if in the learning procedure you try to make the loss function small. What this means is that you want log one minus y hat to be log, and this is negative sign there and then, through a similar piece of reason, you can conclude that this loss function is trying to make y hat as small as possible. And again, because y hat has has to be between zero and one, this is saying that if y is equal to zero, then your loss function will push the parameters to make y hat as close to zero as possible. Now there are a lot of functions with roughly this effect that if y is equal to one, you try to make y hat large and y is equal to zero. We'll try to make y hat small. We just gave here in green, a somewhat informal justification for this particular loss function. We'll provide an optional video later to give a more formal justification for why, in which is regression. We'd like to use the loss function with this particular form. Finally, the loss function was defined with respect to the single training example. It measures how well you're doing on a single training example. I'm now going to define something called the cost function, which measures how well you're doing on the entire training set. So the cost function J, which is applied to your parameters w and b, is going to be the average one over n of the sum of the loss function applied to each of the trillion examples in turn, where here Y hat is, of course, the prediction output by your logistic progression algorithm using, you know, a particular set of parameters, w and b, and so, just to expand this out, this is equal to negative one over m, sum from i equals one through M. Of the definition is the loss function log. So this is y, I log, y, hat i plus one minus y, I long one minus 1x r, I guess you can put square brackets here. So the minus sign is is outside everything else. So the terminology I'm going to use is that the loss function is applied to just a single train example, like so, and the cost function is the cost of your parameters. So in training your logistic regression model, we're going to try to find parameters w and b that minimize the overall cost function J written at the bottom. So you've just seen the setup for the logistic regression algorithm, the loss function for training example, and the overall cost function for the parameters of your algorithm. It turns out that logistic regression can be viewed as a very, very small neural network. In the next video, we'll go over that so you can start gaining intuition about what neural networks do. So that let's go on to the next video about How to View logistic regression as a very small and [6901:14:40] 2: which is, [6916:10:40] 2: what is the difference between the cost function and loss function of logistics progression, the loss function computes the arrow error for a signal I [7022:13:20] 2: it computes the error for a single training example, the cost function is the average of the loss function of The entire training set. The cost function computes the error for a single train. Example, the loss function is the average of The cost function of The entire training Set The [7644:26:40] 1: three you've seen the logistic regression model. You've seen the loss function that measures how well you're doing on a single training example. You've also seen the cost function that measures how well your parameters, w and b are doing on your entire training set. Now let's talk about how you can use the gradient descent algorithm to train or to learn the parameters W on your training set. To recap, here is the familiar logistic regression algorithm, and we have on the second line the cost function J, which is a function of the parameters w and b, and that's defined as the average. So it's one over m times the sum of this loss function. And so the loss function measures how well your algorithms outputs y, hat I on each of the training examples stacks up, compares to the ground truth variable y i on each of the training examples. And the full formula is expanded ultimately, right? So the cost function measures how well your parameters w and b are doing on the training set. So in order to learn the set of parameters w and b, it seems natural that we want to find w and b that make the cost function j of W comma b, as small as possible. So here's an illustration of gradient descent. In this diagram, the horizontal axes represent your space of parameters, w and b. In practice, w can be much higher dimensional, but for the purposes of plotting, let's illustrate w as a single row number and B as a single row number, the cost function J of WB is then some surface above these horizontal axes w and b, so the height of the surface represents the value of j comma B at a certain point. And what we want to do is really to find the value of w and b that corresponds to the minimum of the cost function J. It turns out that this particular cost function J is a convex function, so it's just a single big bold so this is a convex function, and this is as opposed to functions that look like this, which are non convex. So the fact that cost function J of WB, as defined here, is convex, is one of the huge reasons why we use this particular cost function J for logistic regression. So to find a good value for the parameters, what we'll do is initialize w and b to some initial value and denoted by that little bit dot. And for logistic regression, almost any initialization method works. Usually you initialize the values to zero. Random initialization also works, but people don't usually do that for logistic regression, but because this function is convex, no matter where you initialize, you should get to the same point or roughly the same point. And what gradient descent does is it starts at that initial point and then takes a step in the steepest downhill direction. So after one step of gradient descent, you might end up there, because it's trying to take a step downhill in the direction of steepest descent, or as quickly downward as possible. So that's one iteration of gradient descent, and after two iterations of gradient descent, you might step there three iterations and so on. I guess this is not hidden by the back of the plot, until eventually, hopefully, you converge to this global optimal or get to something close to the global optimum. So this picture illustrates the gradient descent algorithm. Let's write out a bit more of the details for the purpose of illustration, let's say that there's some function j of W that you want to maybe that function looks like this. To make this easier to draw, I'm going to ignore B for now, just to make this a one dimensional plot instead of a higher dimension of that. So gradient descent does this, we're going to repeatedly carry out the following update when you take the value of W and update it from these colon equals to represent updating W set W to W minus alpha times. And this is a derivative d of JW, DW. I will repeatedly do that until the algorithm converges. So a couple points in the notation alpha here is the learning rate, and controls how big a step we take on each iteration per gradient descent. We'll talk later about some ways for choosing the learning rate, alpha and second. This quantity here, this is a derivative. This is basically the update of the change you want to make to the parameters W. When we start to write code to implement gradient descent, we're going to use the convention that the variable name in our code D, W will be used to represent this term, so w equals w minus alpha, use d [9038:18:40] 1: w to be available to [9053:30:40] 1: represent now let's Just make sure that makes [9074:34:40] 1: sense. Let's say that W was over here. So you're at this point on the cost function j of W. Remember that the definition of a derivative is the slope of a function at the point. So the slope of the function is mu the height divided by the width. Your triangle here is tangent to j of W, I, and so here the derivative is positive. W gets updated as w minus a learning rate times derivative. The derivative is positive, and so you end up subtracting from w, so you end up taking a step to the left. And so gradient descent would make you, however, slowly decrease the parameter. It starts it off with this large value of w as another example. If W was over here, then at this point, the slope here or DJ, DW will be negative, and so the gradient descent update would subtract alpha times a negative number, and so end up slowly increasing w. So you end up making W bigger and bigger with successive elevations if you have descent. So then hopefully, whether you initialize on the left or the right, creating descent will move you towards this global minimum here, if you're not familiar with derivatives or with calculus, and what this term d, J, W, d W means, don't worry too much about it. We'll talk some more about derivatives in the next video. If you have a deep knowledge of calculus, you might be able to have a deeper intuitions about how neural networks work, even if you're not that familiar with calculus, in the next few videos will give you enough intuitions about derivatives and about calculus that you'll be able to effectively use neural networks. But the overall intuition for now is that this term represents the slope of the function, and we want to know the slope of the function at the current setting of the parameters, so that we can take these steps of steepest descent, so that we know what direction to step in in order to go down though on the cost function J. So we wrote our gradient descent for j of W, if only W was your parameter in logistic regression, your cost function is a function of both w and b. So in that case, the inner loop of gradient descent that exists in here is going to have to repeat becomes as follows. You end up updating w as w minus the learning rate times the derivative of j of W b with respect to w, and you update B minus the learning rate times the derivative of the cost function with respect to B. So these two equations at the bottom are the actual update you implement. As an aside, I just want to mention one notational convention in calculus that is a bit confusing to some people. I don't think it's super important that you understand calculus for the case you see this, I want to make sure that you don't think too much of this, which is that in calculus this term here, we actually write as follows that funny squiggles symbol. So this symbol, this is actually just a lowercase d in a fancy font, in a stylized font, but when you see this expression, all this means is, this is a j of W, comma b, or maybe the slope of the function, j of W, comma B, how much that function slopes in the W direction. And the rule of the notation in calculus, which I think is totally logical, but the rule in the notation for calculus, which I think just makes things much more complicated than you need to be, is that if j is a function of two or more variables, then instead of using lowercase d, you use this funny symbol. This is called a partial derivative symbol, but don't worry about this. And if j is a function of only one variable, then you use lowercase d. So the only difference between when you use this funny partial derivative symbol or lowercase d, as we did on top is whether J is a function of two or more variables, in which case you use this symbol, the partial derivative symbol, or if A j is only a function of one variable, then you use lower case d. This is one of those funny rules of notation and calculus that I think just make things more complicated than they need to be. But if you see this partial derivative symbol, all it means is you're measuring the slope of the function with respect to one of the variables. And similarly, to adhere to the formally correct mathematical notation calculus, because here J has two inputs, not just one, this thing at the bottom should be written with this partial derivative symbol, but it really means the same thing as almost the same thing as lowercase d. Finally, when you implement this in code, we're going to use the convention that this quantity, really the amount by which you update w will denote as the variable DW in your code, and this quantity right, the amount by which you want to update B will denote by the variable DB in your code. All right, so that's how you can implement gradient distance. Now, if you haven't seen calculus for a few years. I know that that might seem like a lot more derivatives in calculus than you might be comfortable with so far, but if you're feeling that way, don't worry about it. In the next video, we'll give you better intuition about derivatives, and even about a deep mathematical understanding of calculus, or just an intuitive understanding of calculus, you will be able to make new networks work effectively, so that let's go into the next video Where we'll talk a little bit more About derivative You. [11377:46:40] 3: True or False. Take home fix function always has not Been [11432:42:40] 2: working. [11762:24:00] 1: This. In this video, I want to help you gain an intuitive understanding of calculus and of derivatives. Now maybe you're thinking that you haven't seen calculus since your college days, and depending on when you graduated, maybe that was quite some time back. Now, if that's what you're thinking, don't worry. You don't need a deep understanding of calculus in order to apply new networks and deep learning very effectively. So if you're watching this video, or some of the later videos, you're wondering, Wow, is this stuff really for me, this calculus looks really complicated. My advice to you is the following, is that watch the videos and then if you could do the homework and complete the programming homework successfully, then you can apply deep learning. In fact, what you see later is that in week four, we'll define a couple of types of functions that will enable you to encapsulate everything that needs to be done with respect to calculus, that these functions called forward functions and backward functions that we learn about that lets you put everything we need to know about calculus into these functions so that you don't need to worry about them anymore. Beyond that, but I thought that in this foray into deep learning, that this week, we should open up the box and peer a little bit further into the details of calculus, but really, all you need is an intuitive understanding of this in order to build and successfully apply these algorithms. Oh, and finally, if you are among that, maybe smaller group of people that are explicit in calculus, if you're very familiar with calculus or derivatives, it's probably okay for you to skip this video, but for everyone else, let's dive in and try to gain an intuitive understanding of derivatives. I plotted here the function f of a equals three eight, so it's just a straight line to gain intuition about derivatives. Let's look at a few points on this function. Let's say that A is equal to two. In that case, f of a, which is equal to three times A, is equal to six. So if A is equal to two, then F of A will be equal to six. Let's say we give the value of a, you know, just a little bit of a nudge. I'm going to just bump up a a little bit so there is now 2.01 so I'm going to give a like a tiny little nudge to the right. So now is, let's say, 2.01 [12385:41:20] 1: this plot isn't too scalable. 2.01 [12399:17:20] 1: the 0.001 difference is too small to show in this plot, just giving a little nudge to the right. Now, f of a is equal to three times that. So 6.003 so plot this over here. This is not to scale. This is 6.003 so if you look at this little triangle here, highlighting reading, what we see is that if I march a 0.001 to the right, then f of a goes up by 0.003 the amount that F of A went up is three times as big as the amount that I nudged A to the right. So we're going to say that the slope, or the derivative of the function f of a at a equals two, or when A is equals two, the slope is three. And you know the term derivative basically means slope is because that derivative sounds like a scarier, more intimidating word, whereas slope is a linear way to describe the concept of derivative. So whenever you hear derivative, just think slope of the function. And more formally, the slope is defined as the height divided by the width of this little triangle that we have in green. So this is, you know, 0.03 over 0.01 and the fact that the slope is equal to three, or the derivative is equal to three, just represents the fact that when you nudge A to the right by 0.01 by tiny amount, the amount that F of A goes up is three times as a as the amount that United States that you nudged a in the horizontal dimension. So that's all the slope of the line is. Now let's look at this function at a different point. Let's say that A is now equal to five. In that case, f of a three times a is equal to 15. So let's say I again give a a nudge to the right, a tiny little nut is now bumped up to 5.0 1f of a is three times that. So f of a is equal to 15.0 me and so once again, when I bump a to the right, naturally to the right by point oh, 1f of A goes up three times as much. So the slope again at a equals five is also three. So the way we write this that the slope of the function f is equal to three, we say d, f of a, d A, and this just means the slope of the function f of a when you nudge the variable A a tiny little amount. This is equal to three. And an alternative way to write this diverse formula is as follows. You can also write this as d, da, of f of a. So whether you put the F of A on top or whether you write it down here, it doesn't matter. What all this equation means is that if I nudge A to the right a little bit I expect F of A to go up by three times as much as I nudge the value of Little a. Now for this video, I explained derivatives, talking about what happens if you nudge the variable A by 0.001 if you want the formal mathematical definition of derivatives. Derivatives are defined with an even smaller value of how much you nudge A to the right. So it's not o point o1, is not o point o1, [13294:34:39] 1: is not o point O, [13307:38:40] 1: and so on. One is sort of even smaller than that. And the formal definition of derivative says, What have you nudged A to the right by an infinitesimal amount, basically an infinite, infinitely tiny, tiny amount. If you do that, does f of a go up three times as much as whatever was a tiny, tiny, tiny amount that you nudged A to the right. So that's actually the formal definition of a derivative. But for the purposes of our intuitive understanding, we just talk about nudging A to the right by this small amount, 0.001 even if 0.001 isn't exactly tiny, tiny, infinitesimal. Now, one property of the derivative is that no matter where you take the slope of this function, it is equal to three. Whether a is equal to two or a is equal to five. The slope of this function is equal to three, meaning that whatever is the value of a, if you increase it by open or one, the value of capital goes up by three times as much. So this function has the same slope everywhere. One way to see that is that wherever you draw this lower triangle right the height divided by the width always has a ratio of three to one. So I hope this gives you a sense of what the slope or the derivative of the function means for a straight line where, in this example, the slope of the function was three everywhere. In the next video, let's take a look at a slightly more complex example, where the slope of the function can be different at different points on the function. [13790:29:20] 2: So on a straight line, the functions derivative doesn't change or changes as value, Access, increase, slash, decrease, So [14608:42:40] 1: in this video, I show you a slightly more complex example where the slope of the function can be different at different points in the function. Let's start with an example. Here I plotted the function f of a equals a squared. Let's take a look at the point A equals two. So a squared or f of a is equal to four. Let's nudge a slightly to the right, so now A is equal to 2.00 1f of a, which is a squared, is going to be approximately 4.004 it turns out that the exact value you call it, calculating the result. It's actually 4.004001 but I'm just to say 4.04 is close enough. So what this means is that when a is equal to two, let's draw this on the plot. So what we're saying is that if a is equal to two, then f of a is equal to four. And here the X and Y axes are not drawn to scale. Technically, this vertical height should be much higher than this horizontal height, so the X and Y axes are not on the same scale. But if I now nudge a to 2.01 then f of a becomes roughly 4.04 so if you draw this little triangle again, what this means is that if I make a to divide by 0.0 1f of A goes up four times as much by O point o4 so the language of calculus, we say that the slope that is the derivative of F of A at a equals two is four. Or to write this out with our calculus notation, we say that DDA of f of a is equal to four when a is equal to two. Now one thing about this function f of a equals a squared is that the slope is different for different values of A. This is different than the example we saw on the previous slide. So let's look at a different point. If A is equal to five, so instead equals two. Now I think was five, then a squared is equal to 25 so that's f of a. If I nudge A to the right, again, it's tiny little nudge the a. So now A is 5.01 then F of A will be approximately 25.010 so what we see is that by nudging a up by point over 1f, of a goes up 10 times as much. So we have that D, da, f of a is equal to 10, where a is equal to five, because f of a goes up 10 times as much as a does when with a tiny lower dimension to a so one way to see why the derivative is different at different points is that at different locations on this you see that the ratio of the height of the triangle over the width of the triangle is very different at different points on the curve. So here, the slope is equal to four when a is equal to two, but is equal to 10 when a is equal to five. Now if you pull up a calculus textbook, a calculus textbook will tell you that DDA of f of a, so f of a is equal to a squared. So that's DDA of a squared. One of the formulas you find in the calculus textbook is that this thing, the slope of the function A squared is equal to two a, not going to prove this, but the way you find this out is that you open up a calculus textbook to the table formulas, and I'll tell you the derivative of two of a squared is equal to two a, and indeed, this is consistent with what we've worked out. Namely, when a is equal to two, the slope the function two A is two times two is therefore equal to four, and when a is equal to five, then the slope of the function two times A is two times five is equal to 10. So if you ever pull up a calculus textbook and you see this formula, that the derivative of a squared is equal to two A. All that means is that for any given value of A, if you nudge it up with by 0.01 already the tiny little value you would expect F of A to go up by two a, that is the slope, or the derivative, times however much you had nudged to the right the value of A now, one tiny little detail, you know, I had used these approximate symbols here. This wasn't exactly 4.04 there's an extra point, oh, one email there. It turns out that this extra point, oh, one, this little thing here, is because we were nudging A to the right by 0.01 if we're instead nudging it to the right by this infinitesimally small value, then this extra error term will go away and you find that the amount that F of it goes up is exactly equal to the derivative times the amount that imaginate to the Right. And the reason why it's not 4.04 exactly is because derivatives are defined using these infinitesimally small nudges to a rather than, you know, 0.01 which is on it while and while 0.01 is small is not infinitesimally small. So that's why the amount that F of A went up isn't exactly given by the formula, but it's only kind of approximately given by the derivative. To wrap up this video, let's just go through a few more quick examples. The example you've already seen is that if f of a equals a squared then the calculus textbooks formula table will tell you that the derivative is equal to two A. And so the example we went through was that if A is equal to 2f, of A equals four, and then the Nike A, so it's a little bit bigger, then f of a is about 4.4 and so f of a went up four times as much. And indeed, when a is equal to two, the derivatives. Let's look at some other examples. Let's say instead, the f of a is equal to A cubed. If you go to a calculus textbook and look up the table of formulas, you see that the slope of dysfunction, the derivative of dysfunction, is equal to three A squared. So you can get this formula out of a calculus textbook. So what this means? So the way to interpret this is as follows. Let's take a equals two as an example. Again, so F of A or A cubed is equal to eight. That's two to power three. So we give a a tiny little nudge, we find that f of a is about 8.012 and feel free to check this. Take 2.001 to r3 you find that it's very close to 8.012 and indeed, when a is equal to two, that's three times two squared, that's equal to three times four, zero to 12. So the derivative formula predicts that if you nudge A to the right by tiny little bit, f of a should go up 12 times as much. And indeed, this is true. When a went up by point O, 1f of A went up 12 times as much by point o1. Two, just one last example, and then we'll wrap up. Let's say the f of a is equal to the log function, right? So I'm going to write log of A. I'm going to use this as the base e logarithm. So some people write that as log log of A. So if you go to a calculus textbook, you find that when you take the derivative of log of A. So this is a function that just looks like that, the slope of this function. So the way to interpret this is that if A is any value, again, let's just keep using a equals two as an example. And you nudge A to the right by point over one, you would expect F of A to go up by one over A that is by the derivative times the amount that you increase a. So in fact, if you pull up a calculator, you find that if A is equal to 2f, of a is about oh point 69315, and if you increase f, and if you increase a to two point over one, then f of a is about [16833:36:00] 1: six, five, says dollar [16856:16:00] 1: five. And indeed, if you look at the formula for the derivative, when a is equal to two DDA, f of a is equal to one half. So this derivative formula predicts that if you bump up a by point, oh one, you would expect F of A to go up by only one half as much and one half, which is exactly what we got, right, that when a goes up by point over one from a equals two to 2.0 1f of A goes up by half as much as I've written. Up by approximately So if you draw the little triangle, if you will. Is that if on the horizontal axis, this goes up by point o1, on the vertical axis, log of A goes up by half of that, and so that one over a or one half, in this case, when a is equal to two, that's just the slope of this line when a is equal to two. So that's it for derivatives. There are just two take home messages from this video. First is that the derivative of a function just means the slope of a function. And the slope of the function can be different at different points on the function. In our first example, where f of a equals three A, there was a straight line. The derivative was the same everywhere. It was three everywhere. But for other functions, like f of a equals a squared or f of a equals log of a, the slope of the line varies, and so the slope of the derivative can be different at different points on the curve. So that's the first takeaway. Derivative just means slope of the line. Second takeaway is that if you want to look up the derivative function, you can flip open your calculus textbook or look up Wikipedia, and often get a formula for the slope of these functions of different modes, so that, I hope you have an intuitive understanding of derivatives of slopes of lines. Let's go on to the next video. We'll start to talk about the computation graph and how to Use that to compute derivatives of more complex functions. [17434:56:00] 1: The it heard me say that the computations of a neural network are all organized in terms of a forward pass or a forward propagation step in which we compute the output of the neural network, followed by a backward pass or a back propagation step, which we use to compute gradients or compute derivatives the computation graph explains why it is organized this way. In this video, we'll go through an example. In order to illustrate the computation graph, let's use a simpler example than logistic regression. Or before going let's say that we're trying to compute a function of J, which is a function of three variables, A, B and C, and let's say that function is three times a plus b times c. Computing this function actually has three distinct steps. The first is you need to compute what is b times c, and let's say we store that in a variable called u, so u is equal to B times C, and then you might compute v is equal to A times u. So let's say this is V, and then finally your output j is v times v. So this is your final function J You're trying to compute. We can take these three steps and draw them in a computation drop as follows. Let's say I draw there are three variables, A, B and C here. So the first thing we did was compute u equals B times C, rectangular box around that, and so the inputs to that are B and C, and then you might have v equals a plus u, [18089:14:40] 1: so the inputs to that V, [18118:18:40] 1: so the inputs to that are u, which we just computed together with a, and then finally we have j equals d times b. So as a counter example, if a equals 5b, equals three and C equals two, then u equals BC with 6d, equals a plus u, i plus six is 11, J is three times x, so j is equal to 33 and indeed, hope you can verify that this is three times five plus three times two. And if you expand that out, you actually get 33 as the value of j. So the computation graph comes in handy when there is some distinguish or some special output variable, such as J, in this case, that you want to optimize. And in the case of a logistic regression, j is, of course, the cost function that we're trying to minimize. And what we've seen in this little example is that through a left to right pass, you can compute the value of j, and what we'll see in the next couple slides is that in order to compute derivatives, it will be a right to left pass, like this kind of going in the opposite direction as the blue arrows that would be Most natural for computing the derivatives. So to recap, the computation graph organizes a computation with this blue arrow, left to right. Computation. Let's refer to the next video how you can do the back with red arrow Right to left, computation, derivative, Just going to the next [18773:09:20] 2: one step of [18783:49:20] 2: blank propagation on computation graph fields derivative of final output variable in the blank it is backward or forward and [19088:21:20] 1: in the last video, we worked through an example of using a computation graph to compute a function J. Now let's take a cleaned up version of that computation graph and show how you can use it to figure out derivative calculations for that function j. So here's our computation graph. Let's say you want to compute the derivative of J respect to B. So what is that? Well, this says if we were to take this value of V and change it a little bit, how would the value of j change? Well, J is defined as v times d, and right now, v is equal to 11. So if we were to bump up V by a little bit to 11.01 then j, which is 3v so currently 33 will get bumped up to 33.03 so here we've increased V by point 01, and the net result of that is that j goes up three times as much. So the derivative of J with respect to b is equal to three because the increase in J is three times the increase in B. And in fact, this is very analogous to the example we had in the previous video, where we had f of a equals three A. And so we then derived that DF da, which was slightly simplified, slightly sloppy notation, you can write as DF da was equal to three, right? So instead, here we have j equals dB, and so DJ, dV is equal to three, with here, j playing the role of F and V playing the role of a in this previous example that we had right from from an earlier video. So in the terminology of back propagation, what we're seeing is that if you want to compute the derivative of this final output variable, which usually is the variable you care most about, with respect to v then we've done, you know, sort of one step of back propagation. So we've got one step backwards in this graph. Now let's look at another example. What is DJ, da? In other words, if we bump up the value of A, how does that affect the value of J? Well, let's go through the example. Right now, a is equal to five, so let's bump it up to 5.01 the net impact of that is at B, which was a plus u. So that was previously 11, this would get increased 11.01 and then we've already seen as above, that J now gets pumped to 33.003, so what we've seen is that if you increase a by point over 1j, increases by point o3, and by increase a, I mean, if you were to take this value five and just plug in a new value right then the change to a will propagate to the right of the computation graph. So the J ends up being 33.03 and so the increase to j is three times the increase the A. So that means this derivative is equal to three. And one way to break this down is to say that if you have, if you change a, then that would change B, and through changing B, that would change J. And so the net change to the value of J. When you bump up the value, when you nudge the value of a up a little bit, is that [20136:37:20] 1: first, [20150:45:20] 1: by changing a, you end up increasing B. Well, how much does B increase? Right? It is increased by an amount that's determined by dvda, and then the change in v would cause the value of j to also increase. So in calculus, this is actually called the chain rule, that if a affects V affects j, then the amount that J changes when you nudge A is the product of how much V changes when you nudge A times how much J changes when you nudge v. So in calculus, again, this is called the chain rule. And what we saw from this calculation is that if you increase a by point O, 1b, changes by the same amount. So dv, dA is equal to one. So in fact, if you plug in what we have worked out previously, dv, Dj is equal to three and dv dA is equal to one. So the product of v is three times one. That actually gives you the correct value that DJ dA is equal to three. So this little illustration shows how by having computed DJ DV as its derivative respect to this variable, it can then help you to compute DJ, da, and so there's another step of this backward calculation, just to introduce one more new notational Convention, which is that in when you're writing codes to implement back propagation, there'll usually be some final output variable that you really care about. So final output variable that you really care about or you want to optimize. And in this case, this final output variable is j is really the last node in your computation graph, and so a lot of the computations will be trying to compute the derivative of that final output variable. So d of this final output variable with respect to some other variable, let me just call that d var. So a lot of the computations you have will be to compute the derivative of the final output variable, really, J, in this case, with various intermediate variables such as A, B, C, u or v. And when you implement this in software, you know, what do you call this variable name, right? One thing you could do is, in Python, you could write, you know, give us a very long variable, mean, like D, final output var, over D var, but that's a very long variable. Mean, you could call this, I guess, DJ, D var, but because you're always taking derivatives respect to DJ respect to this final output variable, I'm going to introduce a new notation where in code, when you're computing this thing in the code you write, we're just going to use the variable name DV AR in order to represent that quantity. Okay, so DV AR in the code you write will represent the derivative of the final output variable you care about, such as J, sometimes the loss l with respect to the various intermediate quantities you're computing in your code. So this thing here in your code, you know, you use dv to denote this value, so DV would be equal to three. And your code, you represent this as a DA, right, which is we also figured out to be equal to three. So we've done back propagation partially through this computation graph. Let's go through the rest of this example. Next slide. So let's go to a cleaned up copy of the computation graph. And just to recap, what we've done so far is go back with here, and figured out that dv is equal to three. And again, the definition of dv, that's just the variable name in the code, is really DJ, dv, and we figured out that dA is equal to three. And again, dA is the variable name in your code, and that's really the value of DJ da. I was sort of hand wave. How? You know we've gone backwards on these two edges like so now let's keep computing derivatives. So let's look at the value. U, so what is DJ D, U, well through a similar calculation as what we did before we start off with u equals six. If you bump up U to 6.01 then V, which is previous 11, goes up to 11.01 and so j goes from 33 to 33.03 and so the increase in J is 3x so this is equal and the analysis for u is very similar to the analysis we did for a this is actually computed as [21580:42:40] 1: DJ, dv times [21600:10:40] 1: dv, du, where this we had already figured out was three, and this turns out to be equal to one. So with kind of one more step at our operation, we end up computing that d u is also equal to 3d. U is, of course, just this, d, J, D now we just step through one last example in detail. So what is DJ dv, right? So you imagine if you are allowed to change the value of b, and you want to tweak b a little bit in order to minimize or maximize the value of j, right? So what is the derivative? What's the slope of this function J, when you change the value of b a little bit. It turns out that, using the chain rule for calculus, this can be written as the product of two lenses, DG and J, du times DU, dB. And the reasoning is, if you change b a little bit. So B goes from three to say D point 01, the way it will affect j is it will first affect U. So how much does it affect U? Well, u is defined as b times c, right? So this will go from six when b is equal to three to now 6.02 because c is equal to two in our example here. And so this tells us that d u, d b is equal to two, because when you bump up b by point over 1u, increases twice as much so du, DB, this is equal to two. And now we know that u has gone up twice as much as B has gone up. Well, what is DJ, D, U, we've already figured out that this is equal to three. And so by multiplying these two out, we find that DJ dp is equal to six. And again, here's the reasoning for the second part of the argument, which is we want to know when u goes up by point o2 how does that affect j, the fact that DJ d u is equal to three. That tells us that when u goes up by point oh 2j, goes up three times as much. So j should go up by point oh six, right? So, so that comes from the fact that DJ D, u is equal to three. And if you check the map in detail, you will find that if B becomes 3.01 [22340:26:39] 1: then u becomes 6.0 2v, [22359:38:40] 1: becomes 11.02 [22376:10:40] 1: right? So that's a plus u, so that's five plus u, and then J, which is equal to three times b, that ends up being equal to 33.006, right? And so that's how you get that DJ db is equal to six. And to fill that in, this is if we go backwards. So this is db is equal to six, and DB really is the Python co variable name for DJ dB. And I won't, I won't go through the last example in great detail. But it turns out that if you also compute out DJ, this turns out to be DJ d [22559:49:20] 1: u times d [22573:57:20] 1: u, and this turns out to be nine. This turns out to be three times three. I won't go through that example in detail, but so through this last step, it is possible to derive that the C is equal to so the key takeaway from this video, from this example, is that when computing derivatives, and computing all of these derivatives. The most efficient way to do so is through a right to left computation, following the direction of the red arrows. And in particular, we'll first compute the derivative with respect to B, and then that becomes useful for computing the derivative with respect to a and the derivative with respect to u, and then the derivative with respect to u, for example, this term over here and this term over here, those in turn, become useful for computing the derivative with respect to B and the derivative respect to C. So that was the computation graph and how there's a forward or left to right calculation to compute the cost function, such as j that you might want to optimize and a backwards or a right to left calculation to compute derivatives. If you're not familiar with calculus of the chain rule, I know some of those details would have gone by really quickly, but you didn't follow all the details. Don't worry about it in the next video, we'll go for this again in the context of logistic regression, and show you exactly what you need to do in order to implement the computations You need to compute the derivatives for The logistics [23034:24:00] 2: group. In this class, what does the coding convention, dv, ar, represent the derivative of a final output variable with respect to various intermediate quantities, the derivative of any of any variable used in the code, the derivative of input variables with respect to various intermediate quantities. [23464:26:40] 4: 15 [23567:12:00] 5: years ago, [23648:10:40] 1: regression model. [23677:30:40] 1: Welcome back in this video, we'll talk about how to compute derivatives for you to implement gradient descent for logistic regression, the key takeaways will be what you need to implement. That is the key equations you need in order to implement gradient descent for logistic regression, but in this video, I want to do this computation using the computation graph. I have to admit, using the computation graph is a little bit of an overkill for deriving gradient descent for logistic regression, but I want to start explaining things this way to get you familiar with these ideas so that hopefully will make a bit more sense when we talk about full fledged neural networks. So that let's dive into gradient descent for logistic regression. To recap, we had set up logistic regression as follows, your predictions Y hat is defined as follows, where z is that. And if we focus on just one example for now, then the loss with respect to that one example is defined as follows, where a is the output of the gist regression, and y is the ground truth label. So let's write this out as a computation graph. And for this example, let's say we have only two features, x1 and x2 so in order to compute z, we need to input w1 w2 and B, in addition to the feature values, x1 and x2 so these things in a computation graph get used to compute z, which is w1, x1 plus w2, x2 plus b, rectangle, the box around that. And then we compute y, hat or a equals sigma of z. That's the next step in a computation graph, and then finally we compute L, A, y, and I won't copy the formula again. So in logistic regression, what we want to do is to modify the parameters w and b. In order to reduce this loss, we've described the forward propagation steps of how you actually compute the loss on a single training example. Now let's talk about how you can go backwards to talk to compute the derivatives. Here's a cleaned up version of the diagram, because what we want to do is compute derivatives with respect to this loss. The first thing we want to do going backwards is to compute the derivative of this loss with respect to scripts over there, with respect to this variable, a and so in the code, you just use da right to denote this variable. And it turns out that if you are familiar with calculus, you could show that this ends up being negative y over a plus one minus y over one minus A. And the way you do that is you take the formula for the loss, and if you're familiar calculus, you can compute the derivative respect to the variable lowercase a, and you get this formula. But if you're not familiar with calculus, don't worry about it. We'll provide the derivative formulas you need throughout this course. So if you're an expert in calculus, you'll encourage you to look up the formula for the loss from the previous slide and try taking the derivative with respect to a using calculus. But if you don't know enough calculus to do that, don't worry about it. Now, having computed this quantity, or da, the derivative of your final output variable with respect to A you can then go backwards, and it turns out that you can show dz, which, this is the Python code variable name. This is going to be the derivative of the loss with respect to z, or for L, you could really write the loss including a and y explicit as parameters or not, right? Either type of notation is equally acceptable. We could show that this is equal to a minus y, just a couple comments only for those of you that are exponent experts in calculus. If you're not expert in calculus, don't worry about it. But it turns out that this right DL dz. This can be expressed as DL da, times dA dz, and it turns out that da dz, this turns out to be a times one minus a and DL da, we have previously worked out over here. And so if you take these two quantities, you know, DL da, which is this term, together with Da, dz, which is this term, and just take these two things and multiply them, you can show that you the equation simplifies to a minus y, so that's how you derive it. And this is really the chain rule that I briefly alluded to before. Okay, so feel free to go through that calculation yourself if you are knowledgeable calculus. But if you aren't, all you need to know is that you can compute dz as a minus one. You've already done that calculus for you. And then the final step in back propagation is to go back to compute how much you need to change w and b. So in particular, you can show that the derivative respect to w1 and in code, we'll call this DW one, that this is equal to x1 times dz, and then similarly, DW two, which is how much you want to change w2. Is x2 times dz and B, excuse me, db is equal to dz. So if you want to do gradient descent with respect to just this one example, what you would do is the following. You would use this formula to compute dz and then use these formulas to compute DW one, DW two and DB, and then you perform these updates. W1, gets updated as w1 minus learning rate, alpha times DW one, w2 gets updated similarly, and B gets set as B minus the learning rate times dB, and so this would be one step of grade with respect to a single example. So you've seen how to compute derivatives and implement gradient descent for logistic regression with respect to a single training example. But to train your logistic regression model, you have not just one training example. You have entire training sets of m training examples. So in the next video, let's see how you can take these ideas and apply them to learning, not just from one example, but from an entire training set. You [25590:34:40] 2: What is the simplified formula for derivative [25619:28:00] 2: of the loss with respect to z [25637:04:00] 2: from this [25716:37:20] 2: A divided by parentheses, one minus a in parentheses, [25772:53:20] 2: a minus y. A, [25806:50:40] 2: parenthesis y, minus y, parenthesis, I, [25866:40:00] 5: did You just [25968:16:00] 1: say in a previous video, you saw how to compute derivatives and implement gradient descent with respect to just one training example for religious regression. Now we want to do it for m training examples to get started, let's remind ourselves of the definition of the cost function J, cost function WB, which you care about. Is this average right, one over m, sum from y equals one through M, the loss with the algorithm output AI on the example y, where you know AI is the prediction on the I've trained example, which is sigma of zi, which is equal to sigma of w, transpose Xi plus b. So what we showed in the previous slide is, for any single train example, [26392:26:40] 1: how to compute the derivatives [26410:08:00] 1: when you have just one training example, so d w 1d, w2 and D B with now the super strip I to denote the corresponding values you get if you were doing what we did on the previous slide, but just Using the one training example, x, i, y, I here as well. So now you notice the overall cost function is a sum. Was really the average, because of one over m term of the individual losses. So it turns out that the derivative respect to say w1, of the overall cost function is also going to be the average of, what do you mean derivatives respect to w1, of the individual loss terms. But Previously, we had already shown how to compute this term as say, D, w1, I on the previous slide show how to compute this single train example. So what you need to do is really compute these derivatives, as we showed on the previous training example, and average them. And this will give you the overall gradient that you can use to implement gradient descent. So I know there was a lot of details, but let's take all of this up and wrap this up into a concrete algorithm. So what you should implement to get logistic regression gradient descent work? So here's what you can do. Let's initialize J equals zero, [26836:53:20] 1: DW one equals zero, DW [26853:41:20] 1: two equals zero, DB equals zero. And what we're going to do is use a for loop over the training set and compute the derivatives with respect to each training example, and then add them up, right? So here's we do it for I equals one through M. So m is the number of training examples we compute Zi equals W, transpose Xi plus b, the prediction AI is equal to sigma of zi. And then, you know, let's, let's add up j, j plus equals y, I log ai plus one minus y, I log one minus AI, nuclear sign up to the whole thing, and then, as we saw earlier, we have d z. I is equal to a, i minus y, i and d w gives plus equals x1, i, d z, i, d w2, plus equals x, 2d, z. I'm doing this calculation assuming that you have just the two features at the end of the two. Otherwise you two, this would be the 1d w, 2d wreath and so on in dB plus equals d ti, and I guess that's the end of the form. And then finally, having done this for all m training examples, you would still need to divide by m, because we're computing averages. M, DB, compute [27253:04:00] 1: averages. [27260:47:59] 1: And so with all of these calculations, you've just computed the derivatives of the cost function J, with respect to equal parameters, w1 w2 and B. Just a couple of details of what we're doing. We're using d w1 and d w2 and D B to as accumulators, so that after this computation, you know d w1 is equal to the derivative of your overall cost function with respect to w1 and similarly for DW two and dB. So notice that dw one and DW two do not have a super strict i, because we're using them in this code as accumulators to sum over the entire training set. Whereas, in contrast, dzi here, this was dz with respect to just one single training example. So that's why that had a super strict i to refer to the one training example. I the gas computer. And so, having finished all these calculations to implement one step of gradient descent, you implement w1 gets updated as w1 minus a learning rate times d w1 w2 gets up to w2 minus learning rate times d w 2b, gets updated as B. D W, 1d, w2, and D B were as computed, and finally, J, here would also be a correct value for your cost function. So everything on this slide implements just one single step of grading descent, and so we have to repeat everything on this slide multiple times in order to take multiple steps of creating to send. In case these details seem too complicated, again, don't worry too much about it for now, hopefully all this will be clearer when you go and implement this in the programming assignment. But it turns out there are two weaknesses with the calculation as with as we've implemented it here, which is that to implement logistic regression, this way, you need to write two for loops. The first for loop is this for loop over the entering examples, and the second for loop is a for loop over all the features over here. So in this example, we just had two features, so n is equal to two and x equals two. But if you have more features, you end up writing DW one, DW two, and with similar computations for DWP and so on, Delta, DW n. So it seems like you need to have a for loop over the features of N features when you're implementing deep learning algorithms, you find that having explicit for loops in your field makes your algorithm run less efficiency, and so in the deep learning era, would move to bigger and bigger data sets. And so being able to implement your algorithms without using explicit for loops is really important and will help you to scale to much bigger data sets. So it turns out that there are certain techniques called vectorization techniques, that allow you to get rid of these explicit four loops in your code. I think, in the pre deep learning era, that is before the rise of deep learning, vectorization was a nice to have. You could sometimes do it to speed up your phone and sometimes not. But in the deep learning era, vectorization, that is getting rid of four loops like this and like this, has become really important because we have more and more training on very large data sets, and so you really need your code to be very efficient. So in the next few videos, we'll talk about vectorization and how to implement all this without using even a single for loop. So of this, I hope you have a sense of how to implement logistic regression, a gradient descent for logistic regression, things will be clearer when you implement the program exercise. But before actually doing the program exercise, let's first talk about vectorization so that you can implement this whole thing, implement a single iteration of breathing descent without using Any Food. [28368:00:00] 2: Use. I enjoy telling my Family [28901:20:00] 2: peace. Greetings, everyone. [29044:10:40] 2: I can meet Friday, available 1031 enjoy. Time So [29511:06:40] 1: can Go Down you can get it to go from here. Everything is [30232:48:00] 6: between P is where it's building homes for them, the first responders, buying hotels up in a lot of major cities. And we're going to be [30270:29:20] 7: down in Houston, coming [30303:01:20] 7: up here tonight, [30312:05:20] 5: opening up a lot of great things going on. [30325:30:40] 7: So that's that's what all this [30334:02:40] 5: money I [30339:38:40] 7: believe is being [30372:42:40] 7: raised today is just that ultimate goal, public service. People have always had a soft spot in my heart. My dad was a police officer in Baton Rouge, and then when I was with the meetings, and I was playing And [30428:32:00] 5: so we're just always [30476:32:00] 7: going to make some sense. [30575:33:20] 8: Around you. Do [30678:50:40] 4: this? I See this? You this. No sign here before we look into the mirror and [30895:22:40] 4: see this, when they could do this article, [30911:54:40] 4: article 61 basically when first of its kind, anti Agency design, specifically, www [30946:34:40] 4: dot, [31084:30:40] 5: users yeah, really. [31248:48:00] 3: Great season. COVID, most mature this whole thing, Thanksgiving, piece with 5000 survivors [31282:08:00] 3: of 13, despite his distance [31286:56:00] 3: being released on Thanksgiving. [31313:09:20] 6: You gotta thank this man whenever you think God is not in the [31334:29:20] 7: blessing business and Americans are not about [31363:33:20] 0: giving one of the busiest travel days of the year. And just a little warming to those people out there, year, [31416:26:40] 4: and this guy just jumped up, started kicking together Reed [31447:22:40] 0: under his wings. There's [31478:34:40] 8: nothing herself [31514:18:40] 9: as a thief [31544:00:00] 0: by posting a video of herself [31582:45:20] 9: why in the story on her [31609:41:20] 9: Tiktok page has forever had to Follow those identified [31641:57:20] 3: Massachusetts can publish [31655:17:20] 8: on a year ago, the [31822:13:20] 4: department and the department of [31837:25:20] 3: government efficiency is first breaking tonight, the [31863:49:20] 0: hand picked by President elect Trump to fix the border crisis gets a first hand look at the situation. Incoming voters are tough. COVID visiting the southern border. Equal tax Texas today with him. Texas government again coverage with jackets, independent [31944:42:40] 0: administration.