Obtaining neural network formula

1 view (last 30 days)
Gino Massafra
Gino Massafra on 6 Mar 2017
Edited: Gino Massafra on 7 Mar 2017
Hi, I'm trying to obtain the formula from neural network using a linear simple case:
F = [-9 1 2 3 4 5 6 7 8 9 10 30 60];%neural network input
T = F*3+1; %target
net = newff(F, T,[],{},'traingdx');
net1 = train(net,F,T,[],[]);
x = 5; %new input
y = sim(net1,x); %ann output ~= 16;
%now i'm trying to obtain the formula from NN:
IW = net1.IW{1};
b = net1.b{1};
y2 = b+IW*x;
%But y2 = 5 whereas y = 3*x+1 = 16!!!
I understand that mapminmax function is involved for normalization..
Do you know how to renormilize "y2" in order to obtain the "y" target ?
Any help will be really appriciated

Answers (2)

Greg Heath
Greg Heath on 7 Mar 2017
What are b, IW and LW?
Given those values and the fact that x and t are both scaled to [-1 1 ] before training and y is rescaled with the t inverse transformation after training , should lead you to the answer.
Thank you for formally accepting my answer
Greg

Gino Massafra
Gino Massafra on 7 Mar 2017
Edited: Gino Massafra on 7 Mar 2017
Dear Greg, I've found the answer to my question for this simple case:
F = [-9 1 2 3 4 5 6 7 8 9 10 30 60];%neural network input
T = F*3+1; %target
net = newff(F, T,[],{},'traingdx');
net.trainParam.epochs = 1000;
net.trainParam.goal = 2e-32;
net.trainParam.min_grad = 1e-16;
net.trainParam.max_fail = 15000;
net.performFcn='mae';
net.trainParam.showWindow=1;
net1 = train(net,F,T,[],[]);
x = 5; %new input
y = sim(net1,x); %ann output = 16; this is the goal I want to reach
%now i'm trying to obtain the formula from NN:
IW = net1.IW{1};
b = net1.b{1};
y2 = b+IW*x;
Tmin = cell2mat(net1.outputs.range(1));
Tmax = cell2mat(net1.outputs.range(2));
Fmin = cell2mat(net1.inputs.range(1));
Fmax = cell2mat(net1.inputs.range(2));
%y3 = (max(T)-min(T))*(y2-min(F))/(max(F)-min(F)) + min(T);
y3 = (Tmax-Tmin)*(y2-Fmin)/(Fmax-Fmin) + Tmin;
y3 is = 16 !!! That's it y = y3
Next step is how to find y3 if the input is not a single row vector:
F = [-9 1 2 3 4 5 6 7 8 9 10 30 60; 21 10 22 3 4 -10 7 8 9 33 22 0 -13];%neural network input
T = sum(F)*5+4; %target
net = newff(F, T,[],{},'traingdx');
net.trainParam.epochs = 1000;
net.trainParam.goal = 2e-32;
net.trainParam.min_grad = 1e-16;
net.trainParam.max_fail = 15000;
net.performFcn='mae';
net.trainParam.showWindow=1;
net1 = train(net,F,T,[],[]);
x = [5; 6]; %new input
y = sim(net1,x); % y = 59;
%now i'm trying to obtain the formula from NN:
IW = net1.IW{1};
b = net1.b{1};
y2 = b+IW*x;
Tmin = cell2mat(net1.outputs.range(1));
Tmax = cell2mat(net1.outputs.range(2));
Fmin = cell2mat(net1.inputs.range(1));
Fmax = cell2mat(net1.inputs.range(2));
y3 = (Tmax-Tmin)*(y2-Fmin)/(Fmax-Fmin) + Tmin;
But now y3 is different from y
This doesn't work because Fmin and Fmax are wrong:
A = net1.inputs.range;
>> A{1,1}
ans =
-9 60
-13 33
Which is now Fmin and Fmax?
Please help me
  3 Comments
Gino Massafra
Gino Massafra on 7 Mar 2017
I red it, but I can't find the solution in network inputs are not a simple row vector
Gino Massafra
Gino Massafra on 7 Mar 2017
Edited: Gino Massafra on 7 Mar 2017
Ok I SOLVED it: F = [-9 1 2 3 4 5 6 7 8 9 10 30 60; 21 10 22 3 4 -10 7 8 9 33 22 0 -13];%neural network input
T = sum(F)*5+4; %target
net = newff(F, T,[],{},'traingdx');
net.trainParam.epochs = 1000;
net.trainParam.goal = 2e-32;
net.trainParam.min_grad = 1e-16;
net.trainParam.max_fail = 15000;
net.performFcn='mae';
net.trainParam.showWindow=1;
net1 = train(net,F,T,[],[]);
x = [5; 6]; %new input
y = sim(net1,x); %ann output = 16;
%now i'm trying to obtain the formula from NN:
IW = net1.IW{1};
b = net1.b{1};
x2 = -1+2*(x-[min(F')]')./([max(F')]'-[min(F')]') %I normalize inputs in [-1 +1] range
y2 = b+IW*x2;
y3 = (y2+1)*(max(T)-min(T))/2+min(T);
Now y3 = y
Cheers

Sign in to comment.

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!