neural networks: learning cost function machine learning
TRANSCRIPT
![Page 1: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/1.jpg)
Neural Networks: Learning
Cost function
Machine Learning
![Page 2: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/2.jpg)
Andrew Ng
Neural Network (Classification)
Binary classification
1 output unit
Layer 1 Layer 2 Layer 3 Layer 4
Multi-class classification (K classes)
K output units
total no. of layers in network
no. of units (not counting bias unit) in layer
pedestrian car motorcycle truck
E.g. , , ,
![Page 3: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/3.jpg)
Andrew Ng
Cost function
Logistic regression:
Neural network:
![Page 4: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/4.jpg)
Neural Networks: LearningBackpropagation algorithm
Machine Learning
![Page 5: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/5.jpg)
Gradient computation
Need code to compute:- -
![Page 6: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/6.jpg)
Gradient computation
Given one training example ( , ):Forward propagation:
Layer 1 Layer 2 Layer 3 Layer 4
![Page 7: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/7.jpg)
Gradient computation: Backpropagation algorithm
Intuition: “error” of node in layer .
Layer 1 Layer 2 Layer 3 Layer 4
For each output unit (layer L = 4)
![Page 8: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/8.jpg)
Backpropagation algorithmTraining set
Set (for all ).
ForSetPerform forward propagation to compute for Using , computeCompute
![Page 9: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/9.jpg)
Neural Networks: LearningBackpropagation intuition
Machine Learning
![Page 10: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/10.jpg)
Forward Propagation
![Page 11: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/11.jpg)
Andrew Ng
Forward Propagation
![Page 12: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/12.jpg)
Andrew Ng
What is backpropagation doing?
Focusing on a single example , , the case of 1 output unit, and ignoring regularization ( ),
(Think of ) I.e. how well is the network doing on example i?
![Page 13: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/13.jpg)
Andrew Ng
Forward Propagation
“error” of cost for (unit in layer ).
Formally, (for ), where
![Page 14: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/14.jpg)
Neural Networks: LearningImplementation note: Unrolling parameters
Machine Learning
![Page 15: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/15.jpg)
Andrew Ng
Advanced optimization
function [jVal, gradient] = costFunction(theta)
optTheta = fminunc(@costFunction, initialTheta, options)
Neural Network (L=4):- matrices (Theta1, Theta2, Theta3)- matrices (D1, D2, D3)
“Unroll” into vectors
…
![Page 16: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/16.jpg)
Andrew Ng
Example
thetaVec = [ Theta1(:); Theta2(:); Theta3(:)];DVec = [D1(:); D2(:); D3(:)];
Theta1 = reshape(thetaVec(1:110),10,11);Theta2 = reshape(thetaVec(111:220),10,11);Theta3 = reshape(thetaVec(221:231),1,11);
![Page 17: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/17.jpg)
Andrew Ng
Have initial parameters .Unroll to get initialTheta to pass tofminunc(@costFunction, initialTheta, options)
Learning Algorithm
function [jval, gradientVec] = costFunction(thetaVec)From thetaVec, get .Use forward prop/back prop to compute and .Unroll to get gradientVec.
![Page 18: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/18.jpg)
Neural Networks: Learning
Gradient checking
Machine Learning
![Page 19: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/19.jpg)
Andrew Ng
Numerical estimation of gradients
Implement: gradApprox = (J(theta + EPSILON) – J(theta – EPSILON)) /(2*EPSILON)
![Page 20: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/20.jpg)
Andrew Ng
Parameter vector
(E.g. is “unrolled” version of )
![Page 21: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/21.jpg)
Andrew Ng
for i = 1:n,thetaPlus = theta;thetaPlus(i) = thetaPlus(i) + EPSILON;thetaMinus = theta;thetaMinus(i) = thetaMinus(i) – EPSILON;gradApprox(i) = (J(thetaPlus) – J(thetaMinus))
/(2*EPSILON);end;
Check that gradApprox ≈ DVec
![Page 22: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/22.jpg)
Andrew Ng
Implementation Note:- Implement backprop to compute DVec (unrolled ).- Implement numerical gradient check to compute gradApprox.- Make sure they give similar values.- Turn off gradient checking. Using backprop code for learning.
Important:- Be sure to disable your gradient checking code before training
your classifier. If you run numerical gradient computation on every iteration of gradient descent (or in the inner loop of costFunction(…))your code will be very slow.
![Page 23: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/23.jpg)
Neural Networks: Learning
Random initialization
Machine Learning
![Page 24: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/24.jpg)
Andrew Ng
Initial value of
For gradient descent and advanced optimization method, need initial value for .
Consider gradient descentSet ?
optTheta = fminunc(@costFunction, initialTheta, options)
initialTheta = zeros(n,1)
![Page 25: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/25.jpg)
Andrew Ng
Zero initialization
After each update, parameters corresponding to inputs going into each of two hidden units are identical.
![Page 26: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/26.jpg)
Andrew Ng
Random initialization: Symmetry breaking
Initialize each to a random value in (i.e. )
E.g.
Theta1 = rand(10,11)*(2*INIT_EPSILON) - INIT_EPSILON;
Theta2 = rand(1,11)*(2*INIT_EPSILON) - INIT_EPSILON;
![Page 27: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/27.jpg)
Neural Networks: Learning
Putting it together
Machine Learning
![Page 28: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/28.jpg)
Andrew Ng
Training a neural networkPick a network architecture (connectivity pattern between neurons)
No. of input units: Dimension of featuresNo. output units: Number of classesReasonable default: 1 hidden layer, or if >1 hidden layer, have same no. of hidden units in every layer (usually the more the better)
![Page 29: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/29.jpg)
Andrew Ng
Training a neural network1. Randomly initialize weights2. Implement forward propagation to get for any 3. Implement code to compute cost function4. Implement backprop to compute partial derivativesfor i = 1:m
Perform forward propagation and backpropagation using example(Get activations and delta terms for ).
![Page 30: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/30.jpg)
Andrew Ng
Training a neural network5. Use gradient checking to compare computed using
backpropagation vs. using numerical estimate of gradient of .Then disable gradient checking code.
6. Use gradient descent or advanced optimization method with backpropagation to try to minimize as a function of parameters
![Page 31: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/31.jpg)
Andrew Ng
![Page 32: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/32.jpg)
Neural Networks: LearningBackpropagation example: Autonomous driving (optional)
Machine Learning
![Page 33: Neural Networks: Learning Cost function Machine Learning](https://reader030.vdocuments.net/reader030/viewer/2022012400/551b7297550346a10a8b4a32/html5/thumbnails/33.jpg)
[Courtesy of Dean Pomerleau]