how to use weights and thresholds from Neural Network toolbox

3 次查看(过去 30 天)
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
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
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