Skip to content

Commit

Permalink
refine mlp
Browse files Browse the repository at this point in the history
  • Loading branch information
sth4nth committed May 31, 2017
1 parent 75f3cdf commit 66a59ca
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions chapter05/mlp.m
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
function [model, mse] = mlp(X, Y, h, eta)
function [model, mse] = mlp(X, T, h)
% Train a multilayer perceptron neural network
% Input:
% X: d x n data matrix
% Y: p x n response matrix
% T: p x n response matrix
% h: L x 1 vector specify number of hidden nodes in each layer l
% Ouput:
% model: model structure
% mse: mean square error
% Written by Mo Chen ([email protected]).
if nargin < 4
eta = 1/size(X,2);
end
h = [size(X,1);h(:);size(Y,1)];
eta = 1/size(X,2);
h = [size(X,1);h(:);size(T,1)];
L = numel(h);
W = cell(L-1);
for l = 1:L-1
Expand All @@ -24,10 +22,10 @@
for iter = 1:maxiter
% forward
for l = 2:L
Z{l} = sigmoid(W{l-1}'*Z{l-1});
Z{l} = sigmoid(W{l-1}'*Z{l-1}); % 5.10, 5.49
end
% backward
E = Y-Z{L};
E = T-Z{L};
mse(iter) = mean(dot(E,E),1);
for l = L-1:-1:1
df = Z{l+1}.*(1-Z{l+1});
Expand Down

0 comments on commit 66a59ca

Please sign in to comment.