求助:如何运用MATLAB编写一个BP神经网络程序,要求是二维输入,一维输出(输出值只能是0或者1),多谢!

输入0.45 42;0.32 42;0.47 51;0.52 50;0.88 6;0.92 3;0.01 21;0.06 4;0.58 48;0.78 44
对应输出1 0 1 1 0 0 0 0 1 1
要求能够得到相关的权值矩阵、阈值矩阵~
万分感谢!急用!望不吝赐教

程序中的输入值可以不是提到的,但是输出值只能对应1或0,能够参考的程序也好!多谢了

x=[0.45 42;0.32 42;0.47 51;0.52 50;0.88 6;0.92 3;0.01 21;0.06 4;0.58 48;0.78 44];
y=[1;0;1;1;0;0;0;0;1;1]
inputs = x';
targets = y';

hiddenLayerSize = 8;
net = patternnet(hiddenLayerSize);

net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
net.outputs{2}.processFcns = {'removeconstantrows','mapminmax'};

net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'sample'; % Divide up every sample
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;

net.trainFcn = 'trainlm'; % Levenberg-Marquardt

net.performFcn = 'mse'; % Mean squared error

net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotregression', 'plotfit'};

[net,tr] = train(net,inputs,targets);

outputs = net(inputs);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs)

trainTargets = targets .* tr.trainMask{1};
valTargets = targets .* tr.valMask{1};
testTargets = targets .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,outputs)
valPerformance = perform(net,valTargets,outputs)
testPerformance = perform(net,testTargets,outputs)

view(net)

训练的模型保存在net这个结构体中,想通过输入得到输出用sim()函数追问

麻烦再问一下,在MATLAB7.0中运行时总说

[net,tr] = train(net,inputs,targets);有问题,提示是The expression to the left of the equals sign is not a valid target for an assignment.

是为什么啊?

追答

你是全部把代码复制过去的吗,因为我对你的y变量进行了一个装置,变成了列向量,才符合神经网络的训练要求,你全部复制过去再训练看看,我的运行没有问题。

温馨提示:答案为网友推荐,仅供参考
相似回答