Is it possible to get expression/formula of Neural Network Toolbox?
18 views (last 30 days)
Show older comments
Rokas Bondzinskas
on 23 Oct 2014
Commented: omar alrumayh
on 22 May 2019
Hi all,
I have a dependency P(x,y,z), thus, this is 4D function. My goal is to find an analytic expression of P as a function of x,y,z. I used Neural Network Toolbox to analyse my data (train, validated and so on). It seems that it gives very good fit with MSE of 1e-7 and R-square of 0.997. I am wondering if it is possible to get an expression where I could manually plug in x,y,z and get P values.
Best Regards Rokas,
1 Comment
omar alrumayh
on 22 May 2019
I am trying to do the same. However, I could not get the same answer from the function that represent the NN.
x=randi([0 1],10000,1).'; %INPUT
y= (x./2); %OUTPUT
input= {x};
target= {y};
%--------------------------------------
net= fitnet(1);
net= train(net,input,target);
test= net(x);
view(net);
%---------------------------------------Here I want to get the weight and bias from the trained neural network
obtainedIW= cell2mat(net.IW); %input weight
obtainedLW= cell2mat(net.LW); %Layer weight
obtainedb= cell2mat(net.b); %Biases
n=(obtainedIW.*0.5) + obtainedb(1); %My input here is 0.5
yCal= ((tansig(n)*obtainedLW +obtainedb(2))) ;
Accepted Answer
Greg Heath
on 24 Oct 2014
The equation for fitnet is
y = b2 + LW*tanh(b1+IW*x);
where
b1 = net.b{1};
b2 = net.b{2};
IW = net.IW{1,1};
LW = net.LW{2,1};
Hope this helps.
Thank you for formally accepting my answer
Greg
More Answers (1)
Greg Heath
on 26 Oct 2014
Eliminating statements that assign default values yields
x = input;
t = target; % Reserve the variable name y for the output
MSE00 = mean(var(t',1)) % Reference MSE
net = fitnet; % Uses defaults
% Train the Network
[ net, tr, y0, e ] = train(net, x, t); % e = t-y0
b1 = net.b{1};
b2 = net.b{2};
IW = net.IW{1,1};
LW = net.LW{2,1};
% Test the Network
y = b2 + LW*tanh(b1+IW*x);
diffy = max(abs(y-y0))
performance = mse(e)
% Recalculate Training, Validation and Test Performance
trainTargets = t .* tr.trainMask{1};
valTargets = t .* tr.valMask{1};
testTargets = t .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,y)
valPerformance = perform(net,valTargets,y)
testPerformance = perform(net,testTargets,y)
See Also
Categories
Find more on Define Shallow Neural Network Architectures in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!