-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solves neural networks learning quiz
- Loading branch information
1 parent
a4bd175
commit 26c5fd8
Showing
10 changed files
with
49 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,15 @@ | ||
function p = predict(Theta1, Theta2, X) | ||
%PREDICT Predict the label of an input given a trained neural network | ||
% p = PREDICT(Theta1, Theta2, X) outputs the predicted label of X given the | ||
% trained weights of a neural network (Theta1, Theta2) | ||
|
||
% Useful values | ||
m = size(X, 1); | ||
num_labels = size(Theta2, 1); | ||
|
||
% You need to return the following variables correctly | ||
% p = zeros(m, 1); | ||
|
||
% add x0 in x | ||
a1 = [ones(m, 1) X]; | ||
a2 = sigmoid(a1 * Theta1'); | ||
a2 = [ones(m, 1) a2]; | ||
a3 = sigmoid(a2 * Theta2'); | ||
[maxProbability index] = max(a3, [], 2); | ||
p = index; | ||
|
||
% ====================== YOUR CODE HERE ====================== | ||
% Instructions: Complete the following code to make predictions using | ||
% your learned neural network. You should set p to a | ||
% vector containing labels between 1 to num_labels. | ||
% | ||
% Hint: The max function might come in useful. In particular, the max | ||
% function can also return the index of the max element, for more | ||
% information see 'help max'. If your examples are in rows, then, you | ||
% can use max(A, [], 2) to obtain the max for each row. | ||
% | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
% ========================================================================= | ||
|
||
|
||
%PREDICT Predict the label of an input given a trained neural network | ||
% p = PREDICT(Theta1, Theta2, X) outputs the predicted label of X given the | ||
% trained weights of a neural network (Theta1, Theta2) | ||
|
||
% training data size | ||
m = size(X, 1); | ||
|
||
a1 = [ones(m, 1) X]; | ||
a2 = sigmoid(a1 * Theta1'); | ||
a2 = [ones(m, 1) a2]; | ||
a3 = sigmoid(a2 * Theta2'); | ||
[maxProbability index] = max(a3, [], 2); | ||
p = index; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Neural Networks: Learning | ||
|
||
![Question 1](assets/quiz-1.PNG) | ||
![Question 2](assets/quiz-2.PNG) | ||
![Question 3](assets/quiz-3.PNG) | ||
![Question 4](assets/quiz-4.PNG) | ||
![Question 5](assets/quiz-5.PNG) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
clc; | ||
clear; | ||
|
||
% Gradiant Approximater (Gradiant Checker) | ||
function gradent = approximateGradient(theta, cost) | ||
n = length(theta); | ||
gradient = zeros(n, 1); | ||
EPSILON = 1e-4; | ||
for i = 1:n | ||
thetaPlus = theta; | ||
thetaPlus(i) += EPSILON; | ||
thetaMinus = theta; | ||
thetaMinus(i) -= EPSILON; | ||
gradent(i) = (cost(thetaPlus) - cost(thetaMinus)) / (2 * EPSILON); | ||
endfor | ||
endfunction | ||
|
||
function J = costFunction(theta) | ||
J = 100 * rand(1, 1); | ||
endfunction | ||
|
||
hypothesis = [0 ; 1 ; 2]; | ||
disp(approximateGradient(hypothesis, @costFunction)); |