Forward Propagation in a Deep Network (C1W4L02) DeepLearningAI https://www.youtube.com/watch?v=a8i2eJin0lY Transkript (automatisch erstellt) 0:00 in the last video we described what is the deep l-larry neural network and also talked about the notation we use to describe such networks in this video you 0:08 see how you can perform fold propagation in a deep network as usual let's first go over what forward propagation will look like for a single training example 0:18 X and then later on we'll talk about the vectorized version where you want to carry out forward propagation on the entire training set at the same time but 0:26 um given a single training example X here's how you compute the activations of the first layer so for this first layer you compute v1 equals W 1 times X 0:42 plus b1 so W 1 and B 1 that parameters that affect the activations in layer 1 right where this is layer 1 of the neural network and then you compute the 0:57 activations for that layer to be equal to G of Z 1 and the deactivation function G depends on what layer you're at and maybe index AB has the activation 1:09 function from layer 1 so if you do that you've now computed the activations from there 1 how about layer to say that there well 1:18 you would then compute v2 equals W to a 1 plus B 2 and then so the observation of layer 2 is the way matrix times the outputs of layer 1 so that value plus 1:39 the bias vector for layer 2 and then a2 equals the activation function apply to z2 ok so that's it for layer 2 and so on and so forth until you get to the output 1:57 layer that's layer 4 where you would have that V 4 is equal to the parameters for that layer times the activations from the previous layer 2:11 Plus that bias vector and then similarly a four equals G of v4 and so that's how you you know compute your estimated output Y hat so just one thing to notice 2:29 X here is also equal to a zero because the input feature vector X is also the activations of layer 0 so we scratch out X I'm going to cross out X and put a 0 2:43 here then you know all of these equations basically look the same right the general rule is that ZL is equal to WL times a of L minus 1 plus B L 1 there 3:02 and then the activations for that layer is the activation function applied to the values Z so that's the general for propagation equation so we've done all 3:20 this for a single training example how about for doing it in a vectorized way for the whole training set at the same time the equations look quite similar as 3:32 before for the first layer you would have Capital Z 1 equals W 1 times capital X plus B 1 and then a 1 equals G of Z 1 right and bear in mind that X is 3:54 equal to a 0 these are just Neil the training examples stacked in different columns you could take this let me scratch out X we can put a 0 there and 4:05 then for the next layer a little similar Z 2 equals W 2 A 1 plus B 2 and a 2 equals G of Z 2 right we just take these vector Z or a and so on and 4:26 stacking them up so this is V vector for the first training example V vector for the second training example and so on down to the M training example and 4:38 stacking these and columns and calling this capital V alright and similarly for capital A just as capital X all the training examples are column vectors 4:50 snacks left to right and then they then end of this process you end up with y hat which is equal to G of Z 400 this is also equal to a 4 and that's the 5:03 predictions on all the new training examples of stand horizontally so just to summarize our notation I'm going to modify this up here our notation allows 5:12 us to replace lowercase Z and a with the uppercase counterparts it already looks like a capital D and that gives you the vectorized version of forward 5:23 propagation that you carry out on the entire training set at a time where a 0 is X now if you look at this implementation of vectorization it looks 5:35 like that there is going to be a for loop here where it says left for l equals 1 to 4 for l equals 1 through capital l then you have to compute the 5:47 activations for layer 1 and the layer 2 then for layer 3 and they're gentle therefore so since that there is a for loop here and I know that when 5:55 implementing your networks we usually want to get rid of explicit for loops but this is one place where I don't think there's any way to implement this 6:04 other than explicit for loop so we're implementing for propagation it is perfectly okay to have a for loop that compute the activations for layer 1 then 6:11 there are 2 then they are threes and therefore no one knows and I don't think there is this any way to do this without a for loop that goes from 1 to capital L 6:22 from 1 through the total number of layers and in your network so this place is perfectly okay to have an explicit folder so 6:30 that's it for the notation for deep neural networks as well as how to do forward propagation in these networks if the pieces we've seen so far looks a 6:39 little bit familiar to you that's because what we're seeing is taking a piece very similar to what you see in in the neural network with a single hidden 6:47 layer and just repeating that more times now it turns out that we implemented deep neural network one of the ways to increase your odds of having a bug-free 6:57 implementation is to think very systematic and carefully about the matrix dimensions you're working work so when I'm trying to develop my own code 7:05 I'll often pull a piece of paper and just think carefully through so the dimensions of the matrix I'm working with let's see how you could do that in 7:13 the next video