File Exchange

## MLP Neural Network trained by backpropagation

version 1.0.0.2 (2.15 KB) by Mo Chen

### Mo Chen (view profile)

Multilayer Perceptron (MLP) Neural Network (NN) for regression problem trained by backpropagation (backprop)

Updated 21 Nov 2018

Very compact implementation of backpropagation for MLP regression. Mean to be read and learn.

This package is a part of the PRML toolbox (https://github.com/PRML/PRMLT).

Dan Walker

### Dan Walker (view profile)

I am having the hardest time understanding your code, it seams easy enough but on feed forward why do you require Z{T+1} (outside the loop) without the activation function? When you backpropagate you need the derivative of tanh (1/cosh^2x) but I don't see it in your code. is that because this df is specific to your problem? is that also why you are squaring your values there? I think this code could benefit from more comments

% feedforward
for t = 1:T-1
Z{t+1} = tanh(W{t}'*Z{t}+b{t});
end
Z{T+1} = W{T}'*Z{T}+b{T};

% backward
R{T} = E; % delta
for t = T-1:-1:1
df = 1-Z{t+1}.^2; % h'(a)
R{t} = df.*(W{t+1}*R{t+1}); % delta
end

for t=1:T
dW = Z{t}*R{t}'+lambda*W{t};
db = sum(R{t},2);
W{t} = W{t}-eta*dW;
b{t} = b{t}-eta*db;

yulong zhu

### yulong zhu (view profile)

it train very well。but how to predict？

mr morgan

### mr morgan (view profile)

Hi all,
I used this code to train a sample of 8 inputs and one output and it worked. However, I am wondering about how to use it to predict using testing data.

Niclas Klarström

Zulkifli Hidayat

### Zulkifli Hidayat (view profile)

Nice, but not compatible with R2013b, it's not true compatible with any release

Zulkifli Hidayat

### Zulkifli Hidayat (view profile)

I ran the demo, but I got
>> mlp_demo
Error using +
Matrix dimensions must agree.

Error in mlpReg (line 33)
Z{t+1} = tanh(W{t}'*Z{t}+b{t});

Error in mlp_demo (line 8)
[model, L] = mlpReg(x,y,k);

Omer Yasin Birey

### Omer Yasin Birey (view profile)

Excellent and simple

Mo Chen

### Mo Chen (view profile)

@dsmalenb, [4,5] means, two hidden layer, one with 4 nodes, and one with 5 nodes

dsmalenb

### dsmalenb (view profile)

Dumb question - does "h = [4,5]" mean "4 neurons in 5 layers" or "4 layers with 5 neurons". I can't deduce this by reading the code. It is nice and compact but that point is not clear to me.

zjyedword zjyeword

### zjyedword zjyeword (view profile)

hi, every body, why not do the following? please explain it, thanks
E = W{l}*dG;

Rachit Saluja

LEE ZISHENG

hana razak

nima safari

Ignas A.

Fayzan Zafar

Dan

### Dan (view profile)

Amazing - works really well and is super compact in terms of code. Great work!

Rain

Gyesoon Park