1

I've tried to manually simulate neural network trained by Matlab toolbox with 10 layers. According to this info, I have to scale the input to range [-1,1] (the output is normalize to [0,1] and also has to be scaled back from [-1,1]). I compare to the Matlab's sim function and there's a huge distortion of the output as depicted in this picture where the upper plot is the manual simulation and the lower is the Matlab's sim function. Here is my straightforward code.

clear all;
% x = [0;0;0;0;0;0;0;1;0;0.111;0];
load etp_input;
% t = [0.45];
load etp_target;
load ETp01.mat;
iw = ETp01.IW{1,1};
lw1 = ETp01.LW{2,1};
lw2 = ETp01.LW{3,2};
lw3 = ETp01.LW{4,3};
lw4 = ETp01.LW{5,4};
lw5 = ETp01.LW{6,5};
lw6 = ETp01.LW{7,6};
lw7 = ETp01.LW{8,7};
lw8 = ETp01.LW{9,8};
lw9 = ETp01.LW{10,9};
b1 = ETp01.b{1};
b2 = ETp01.b{2};
b3 = ETp01.b{3};
b4 = ETp01.b{4};
b5 = ETp01.b{5};
b6 = ETp01.b{6};
b7 = ETp01.b{7};
b8 = ETp01.b{8};
b9 = ETp01.b{9};
b10 = ETp01.b{10};
for i=1:365
  x = etp_input(:,i+19*365)*2-1;
  xs = etp_input(:,i+19*365);
  y1 = tansig(iw*x + b1);
  y2 = tansig(lw1*y1 + b2);
  y3 = tansig(lw2*y2 + b3);
  y4 = tansig(lw3*y3 + b4);
  y5 = tansig(lw4*y4 + b5);
  y6 = tansig(lw5*y5 + b6);
  y7 = tansig(lw6*y6 + b7);
  y8 = tansig(lw7*y7 + b8);
  y9 = tansig(lw8*y8 + b9);
  y10 = purelin(lw9*y9 + b10);
  outManual(i) = (y10+1)/2;
  outSim(i) = sim(ETp01,xs);
end
subplot(2,1,1);
plot(outManual);
subplot(2,1,2);
plot(outSim);

I have the annual set of data that's why I do a 365 for-loop. So, what am I missing here?? I have tons of annual data set and they just randomly gave different distortion of the output (the code above using 19th set of data). Any help would be appreciated. This is part of the code so any further info I need to provide, please let me know. Thank you all. :D:D:D

Edited:

  • I use nntool to create the network and save the network object in mat file. The complete code is updated above.
  • Here is the network view from Matlab.
Community
  • 1
  • 1

1 Answers1

0

I found the solution. The scaling i used is the correct idea but my input doesn't have the same range (last two elements are in [0,0.777] while the first 9 elements are [0, 1]). So i have to scale them separately. (see mapminmax function in Matlab). Thanks stackoverflow...:D