训练中的简单线性神经网络权重与训练结果不兼容

时间:2012-08-04 08:42:01

标签: matlab neural-network

我从训练中获得的权重,当直接隐含在输入上时,会返回不同的结果! 我将在一个非常简单的例子中展示它 假设我们有一个输入向量x= 0:0.01:1; 和目标向量t=x^2(我知道使用非线性网络更好) 经过训练,2层,线性网络,每层有一个神经元,我们得到:

sim(net,0.95) = 0.7850(训练中出现一些错误 - 没关系,应该是) 权重来自net.IW,net.LW,net.b:

IW =

0.4547

LW =

2.1993

b =

0.3328   -1.0620

如果我使用权重:Out = purelin(purelin(0.95 * IW + b(1))* LW + b(2))= 0.6200! ,我从sim的结果得到不同的结果! 怎么会这样?怎么了?

代码:

%Main_TestWeights
close all
clear all
clc


t1 = 0:0.01:1;
x = t1.^2;

hiddenSizes = 1;
net = feedforwardnet(hiddenSizes);


[Xs,Xi,Ai,Ts,EWs,shift] = preparets(net,con2seq(t1),con2seq(x));
net.layers{1,1}.transferFcn = 'purelin';
[net,tr,Y,E,Pf,Af] = train(net,Xs,Ts,Xi,Ai);
view(net);


IW = cat(2,net.IW{1});
LW = cat(2,net.LW{2,1});
b = cat(2,[net.b{1,1},net.b{2,1}]);

%Result from Sim
t2=0.95;
Yk = sim(net,t2)

%Result from Weights
 x1 = IW*t2'+b(1)
 x1out = purelin(x1)
 x2 = purelin(x1out*(LW)+b(2))

1 个答案:

答案 0 :(得分:0)

神经网络工具箱将输入和输出重新调整为[-1,1]范围。因此,您必须对其进行重新缩放和非缩放,以便模拟输出与sim()的输出相同:

 %Result from Weights
 x1 = 2*t2 - 1; # rescale 
 x1 = IW*x1+b(1);
 x1out = purelin(x1);
 x2 = purelin(x1out*(LW)+b(2));
 x2 = (x2+1)/2 # unscale

然后

>> x2 == Yk

ans =

     1