Matlab神经网络工具箱,关于提取重量和重量来自前馈网的偏见 [英] Matlab neural network tool box,on extract weight & bias from feedforwardnet
问题描述
我的问题很简单.我已经训练了一个前馈网络.现在,我想提取其权重和偏差,以便可以在另一种编程语言上对其进行测试.但是当我用自己的代码测试那些经过训练的权重时,与神经工具箱相比,它总是返回不同的结果.这是我的代码
My problem is simple. I have trained a feedforwardnet. now I want to extract its weights and biases so i can test it on another programming language. but while i tested those trained weights by my own code, it always returns different results compare with neural tool box.here is my code
close all
RandStream.setGlobalStream (RandStream ('mrg32k3a','Seed', 1234));
[x,t] = simplefit_dataset;
plot(t)
hold on
topo = [2]
net = feedforwardnet(topo);
net = train(net,x,t);
view(net)
y = net(x);
plot(y)
%rewrite net
BI = net.B{1};
WI = net.IW{1};
BO = net.B{2};
WO = net.LW{2};
% input layer
Z = WI*x + BI*ones(1,length(x));
Z = 2./(1+exp(-2*Z))-1;
Y = WO*Z + BO*ones(1,length(x));
plot(Y)
legend('target','tool box result','my result')
它是一个只有两层的简单神经网络. 没有暗示缩放或归一化 这是结果
it is a simple neural network only have two layer. no scaling or normalization be implied here is the result
推荐答案
默认情况下,神经网络输入和输出映射到[-1;1]
范围,因此Z
和Y
的计算对于映射值是正确的,而不是实际的输入和输出.为避免这种情况,您可以取消设置processFcns
属性:
Neural network inputs and outputs are mapped to the [-1;1]
range by default, so the calculation of Z
and Y
is correct for the mapped values, not for the actual inputs and outputs. To avoid this, you can unset the processFcns
properties:
....
net = feedforwardnet(topo);
net.inputs{1}.processFcns= {};
net.outputs{2}.processFcns= {};
net = train(net,x,t);
....
或者,您可以手动映射输入和输出值:
Alternatively, you can map the input and output values manually:
x= mapminmax(x,-1,1);
Z = WI*x + BI*ones(1,length(x));
Z = 2./(1+exp(-2*Z))-1;
Y = WO*Z + BO*ones(1,length(x));
Y= mapminmax(Y,min(y),max(y));
这篇关于Matlab神经网络工具箱,关于提取重量和重量来自前馈网的偏见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!