[Neural network] How does neural network calculate output from net.IW, net.LW, net.b ?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Son Nguyen
am 3 Dez. 2014
Beantwortet: Greg Heath
am 2 Mai 2018
Example I have a trained neural network as following
clear all
clc
[ x, t ] = simplefit_dataset;
net = feedforwardnet;
rng('default')
net = configure(net,x,t);
[net,tr,y,e] = train(net,x,t);
After training finished, weights will be save to net.IW, net.LW, net.b
How does the network calculate output from these weights ?
If output can be calculated as :
y=[ones(Ns,1) tansig([ones(Ns,1) x]*W1')] * W2'
Where Ns is number of training samples.
How can W1 and W2 be formed from net.IW, net.LW and net.b ?
0 Kommentare
Akzeptierte Antwort
Greg Heath
am 8 Dez. 2014
I will let you figure out how to do it when the default normalization and de-normalization are not removed:
clear all, clc
[ x, t ] = simplefit_dataset;
[ I N ] = size(x) %[ 1 94 ]
[ O N ] = size(t) %[ 1 94 ]
net = fitnet; % H=10 default
rng('default') % For repeatability
% net = configure(net,x,t); % For multiple designs
A = net.input.processFcns % see below
B = net.output.processFcns % see below
% processFcns = {'removeconstantrows' 'mapminmax'}
net.input.processFcns = { }; % Remove normalization
net.output.processFcns= { };
[net,tr,y,e] = train(net,x,t);
R2 = 1-mse(e)/var(t,1) % 0.99998
IW = net.IW{1,1}
b1 = net.b{1}
b2 = net.b{2}
LW = net.LW{2,1}
y1 = b2 + LW * tansig( b1 * ones(1,N) + IW * x );
dy = max(abs(y1-y)) %2.6645e-15
Hope this helps.
Thank you for formally accepting my answer
Greg
3 Kommentare
Greg Heath
am 10 Dez. 2014
It is better to just use the random weights assigned by the program.
Otherwise, reverse the above assignment statements. For example
net.IW{1,1}= 0.01*randn(H,I);
for I input nodes and H hidden nodes.
Asaduz Zaman
am 27 Jul. 2016
Helped me a lot. Couldn't find why
sim(net,input)
and
classify(net,input)
wasn't producing same response as I'm new in NNTool. Now I got it. Thanks again.
Weitere Antworten (1)
Greg Heath
am 2 Mai 2018
You did not consider
net.input.processFcns
and
net.output.processFcns
Search in ANSWERS and
comp.soft-sys.matlab
Hope this helps.
Greg
0 Kommentare
Siehe auch
Kategorien
Mehr zu Deep Learning Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!