gpt4 book ai didi

matlab - MATLAB 中的简单前馈 (newff) 网络

转载 作者:行者123 更新时间:2023-11-30 09:38:47 25 4
gpt4 key购买 nike

我多次使用 ffnew 函数,但当我尝试创建一个简单的前馈网络以使输入向量为 P=[1;2;3;4] code> ,所需输出为 T=[1 ;0;0;1]。所以我只有一个样本输入向量

代码是

net = newff(P,T,[4 1],{'tansig','tansig'});
net=train (net,P,T);

当我写下最后一行时,我得到:

??? Error using ==> plus
Matrix dimensions must agree.

Error in ==> calcperf2 at 163
N{i,ts} = N{i,ts} + Z{k};

Error in ==> trainlm at 253
[perf,El,trainV.Y,Ac,N,Zb,Zi,Zl] = calcperf2(net,X,trainV.Pd,trainV.Tl,trainV.Ai,Q,TS);

Error in ==> network.train at 216
[net,tr] = feval(net.trainFcn,net,tr,trainV,valV,testV);

最佳答案

也许一个简单的例子会有帮助。考虑一下著名的异或问题:

input = [0 0; 0 1; 1 0; 1 1]';               %'# each column is an input vector
ouputActual = [0 1 1 0]; %#

net = newpr(input, ouputActual, 2); %# 1 hidden layer with 2 neurons
net.divideFcn = ''; %# use the entire input for training

net = init(net); %# init
[net,tr] = train(net, input, ouputActual); %# train
outputPredicted = sim(net, input); %# predict

[err,cm] = confusion(ouputActual,outputPredicted);

请注意,我使用了 NEWPR 而不是 NEWFF。原因是它在输出上使用逻辑函数(NEWFF 是线性的),这更适合分类任务。如果您使用 1-of-N 目标编码,输出将在 [0,1] 范围内,并且可以解释为每个类别的后验概率(NEWFF 将不限于 [0,1])

关于matlab - MATLAB 中的简单前馈 (newff) 网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3120839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com