how to use weights and thresholds from Neural Network toolbox

조회 수: 3 (최근 30일)
Cadmean
Cadmean 2011년 1월 25일
Establish a very simple feed forward network to approximate sin wave:
x=[0:0.1:10];
y=sin(x);
net=newff(x,y,30); %30 neurons
net=train(net,x,y); %train
y=sim(net,x);
plot(x,sin(x),x,y);
The result is good. However, if I take the weight and threshold matrix from this network:
w1=net.IW{1,1};
w2=net.LW{2,1};
b1=net.b{1};
b2=net.b{2};
and use a loop to simulate it:
xx=[0:0.5:5];
for i=1:size(x,2)
Y(i)=w2*tansig(w1*xx(i)+b1)+b2;
end
plot(xx,sin(xx),xx,Y);
the result is totally different. Is there any problem?

답변 (3개)

Andres Zarate de Landa
Andres Zarate de Landa 2011년 4월 26일
I figured out the problem! The thing here is that newff by default normalices the inputs and outputs using the mapminmax function. You can see that by typing net.inputs{1}.processFcns 'fixunknowns' 'removeconstantrows' 'mapminmax'
net.outputs{2}.processFcns 'removeconstantrows' 'mapminmax'
So, if you don't want normalized inputs and outputs as in my case just remove the mapminmax function: net.inputs{1}.processFcns = {'fixunknowns', 'removeconstantrows'}; net.outputs{2}.processFcns = {'removeconstantrows'};
And that's all! the weights and biases won't be normalized and you can use these parameters in your own ANN using any software. I hope this helps

Mark Hudson Beale
Mark Hudson Beale 2011년 4월 19일
You need to first preprocess inputs, then post process outputs as follows:
xx = [0:0.5:5]
for i=1:length(net.inputs{1}.processFcns)
xx = feval(net.inputs{1}.processFcns{i},...
'apply',xx,net.inputs{1}.processSettings{i});
end
for i=1:size(x,2)
Y(i)=w2*tansig(w1*xx(i)+b1)+b2;
end
for i=1:length(net.outputs{2}.processFcns)
Y = feval(net.outputs{2}.processFcns{i},...
'reverse',Y,net.outputs{2}.processSettings{i});
end
You can replace the FEVAL calls with direct calls to the functions in "net.inputs{1}.processFcns" and "net.outputs{2}.processFcns" if you like.

Andres Zarate de Landa
Andres Zarate de Landa 2011년 4월 25일
I have the exact same problem, I need the Weights and biases to simulate the ANN using equations on ADS. The function aproximation results using the "sim" function are ok, however when I try to simulate it it doesn't work at all. I don't know what's wrong can anybody help please?
Thanx

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by