Simple neural network

1 visualización (últimos 30 días)
Marc
Marc el 17 de Abr. de 2012
Hi everyone, I'm having some troubles with a quite simple neural network. Please just run the following code and you'll see what I'm talking about.
fs = 1000; % sampling frequency
t = (0:1999)/fs; % time signal
s1 = 1+3*exp(-t)+0.1*randn(size(t)); % signal #1
s2 = -2+2*exp(-1.2*(t-4/fs))+0.07*randn(size(t)); % signal #2
s3 = 1.3*exp(-(t+9/fs)+1)+0.11*randn(size(t)); % signal #3
s4 = -0.7+2.7*exp(-0.9*t-5/fs)+0.05*randn(size(t)); % signal #4
% I'll try to estimate s4 using s1, s2 and s3
in = [s1; s2; s3];
ref = s4;
figure,plot(s1),hold on,plot(s2,'r'),plot(s3,'g'),plot(s4,'m')
% Neural network
net = feedforwardnet(1); % neural network with 1 hidden layer
net.layers{1}.transferFcn = 'purelin'; % transfer function is "x=y"
net = train(net,in,ref); % train the network
w1 = net.IW{1}; w2=net.LW{2}; b = [net.b{1},net.b{2}]; % get the network's parameters (weights and biaises)
estim_s4 = sim(net,I); % simulate the network to get an estimate of s4
my_estim_s4 = (w1*in+b(1))*w2+b(2); % my estimation of s4
plot(estim_s4,'y')
plot(my_estim_s4,'c')
legend('s1','s2','s3','s4','estim-s4','my-estim-s4')
If you look at the network's structure (the flowchart that appear when you run the network's computation), you see there are 3 inputs, which are then multiplied by a first weight vector w (say w1), then b is added (say b1), then the whole thing goes through a "pure linear transfer function" ('purelin') and is multiplied by a second weight w (say w2), then another biais b (say b2) is added, then the whole thing goes through another "pure linear transfer function" and I have my output. Thus my output is (w1*inputs+b1)*w2+b2.
But my output as estimated like this does not coincide with the output estimated by the network, as you can see. I don't understand why... Isn't the 'purelin' transfer function just copying the input to the output ? Or am I using the wrong weights ? Because for instance net.LW is a 2x2 cell array, but only 1 cell is not empty, so that's the one I use.
This is the first time I use a neural network... Thanks in advance for you help and sorry for my English.

Respuesta aceptada

Greg Heath
Greg Heath el 18 de Abr. de 2012
1. estim_s4 = sim(net,I); % simulate the network to get an estimate of s4
Undefined function or variable 'I'.
Error in replysimplenet (line 24)
2. By default, FEEDFORWARDNET normalizes inputs and outputs to [ -1; 1]
Hope this helps.
Greg
  1 comentario
Marc
Marc el 19 de Abr. de 2012
Thanks you very much, Greg!! It works now :)
(and yes, sorry, it should be estim_s4 = sim(net,in); )

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Deep Learning Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by