求助:如何运用MATLAB编写一个BP神经网络程序,要求是二维输入,一维输出(输出值只能是0或者1),多谢!
输入0.4542;0.3242;0.4751;0.5250;0.886;0.923;0.0121;0.064;0.5848;0.7844对应输出1011000011要求能...
输入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,能够参考的程序也好!多谢了 展开
对应输出1 0 1 1 0 0 0 0 1 1
要求能够得到相关的权值矩阵、阈值矩阵~
万分感谢!急用!望不吝赐教
程序中的输入值可以不是提到的,但是输出值只能对应1或0,能够参考的程序也好!多谢了 展开
1个回答
展开全部
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()函数
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.
是为什么啊?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询