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?
0 个评论
回答(3 个)
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
0 个评论
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.
0 个评论
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
0 个评论
另请参阅
类别
在 Help Center 和 File 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!