我是 MATLAB 的新手,我想验证 C 中的在线反向传播(BP)代码。我需要测试代码是否与相同的网络设置完全相同。网络设置为原始 BP(针对 XOR 问题)2 个输入、2 个隐藏节点和 1 个输出。使用的学习率设置为 0.01,动量为 0.95,而停止标准为 0.01,性能度量为 sse。纪元为 1(因为我想检查从前向传播到后向传播的精确计算,以验证网络设置与 C 中的完全相同)这是我的代码:
clear all;clc
input = [0 0; 0 1; 1 0; 1 1]';
target = [0 1 1 0]; % p = [-1 -1 2 2; 0 5 0 5]; % t = [-1 -1 1 1];
state0 = 1367;
rand('state',state0)
net = newff(input,target,2,{},'traingd');
net.divideFcn = '';
%set max epoh, goal, learning rate, show stp
net.trainParam.epochs =1;
net.trainParam.goal = 0.01;
net.performFcn ='sse';
net.trainParam.lr = 0.01;
net.adaptFcn=' ';
net.trainParam.show = 100;
net.trainparam.mc = 0.95;
net.layers{1}.transferFcn = 'logsig';
net.layers{2}.transferFcn = 'logsig';
wih = net.IW{1,1};
wihb= net.b{1,1};
who = net.LW{2,1};
whob = net.b{2,1};
%Train
net = train(net,input,target); %adapt
y= sim(net,input);
e=target-y;
perf = sse(e)
运行后,我发现 y(1) 为 0.818483286935909 它与手动计数不同,即 0.609299823823181(我通过计算重新检查 ==>
for i=1:size(input,2)
hidden(1) = logsig( wih (1)*input(1) + wih(2)*input(2) + wihb(1) );
hidden(2) = logsig( wih (3)*input(1) + wih(4)*input(2) + wihb(2) );
out(i) = logsig( hidden(1)*who(1) + hidden(2)*who(2) + whob(1) );end )
我的问题是:1)原来的 MATLAB 是在使用 traingd 吗?2) 真正的 net = train(net,input,target); y = sim(网络,输入);使用 train 和 sim 手动计算得到 0.609299823823181 而不是 0.818483286935909 的地方。
3)与上面的matlab代码相比,我在C中的粗略前向传播有什么不同?
拜托,请帮助我。