MATLAB 神经网络并行运算与神经网络基于CPUGPU的并行神经网络运算.docx
- 文档编号:23827508
- 上传时间:2023-05-21
- 格式:DOCX
- 页数:9
- 大小:70.70KB
MATLAB 神经网络并行运算与神经网络基于CPUGPU的并行神经网络运算.docx
《MATLAB 神经网络并行运算与神经网络基于CPUGPU的并行神经网络运算.docx》由会员分享,可在线阅读,更多相关《MATLAB 神经网络并行运算与神经网络基于CPUGPU的并行神经网络运算.docx(9页珍藏版)》请在冰豆网上搜索。
MATLAB神经网络并行运算与神经网络基于CPUGPU的并行神经网络运算
清空环境变量
clearall
clc
warningoff
打开matlabpool
matlabpoolopen
poolsize=matlabpool('size');
Startingmatlabpoolusingthe'local'profile...connectedto2workers.
加载数据
loadbodyfat_dataset
inputs=bodyfatInputs;
targets=bodyfatTargets;
创建一个拟合神经网络
hiddenLayerSize=10;%隐藏层神经元个数为10
net=fitnet(hiddenLayerSize);%创建网络
指定输入与输出处理函数(本操作并非必须)
net.inputs{1}.processFcns={'removeconstantrows','mapminmax'};
net.outputs{2}.processFcns={'removeconstantrows','mapminmax'};
设置神经网络的训练、验证、测试数据集划分
net.divideFcn='dividerand';%随机划分数据集
net.divideMode='sample';%划分单位为每一个数据
net.divideParam.trainRatio=70/100;%训练集比例
net.divideParam.valRatio=15/100;%验证集比例
net.divideParam.testRatio=15/100;%测试集比例
设置网络的训练函数
net.trainFcn='trainlm';%Levenberg-Marquardt
设置网络的误差函数
net.performFcn='mse';%Meansquarederror
设置网络可视化函数
net.plotFcns={'plotperform','plottrainstate','ploterrhist',...
'plotregression','plotfit'};
单线程网络训练
tic
[net1,tr1]=train(net,inputs,targets);
t1=toc;
disp(['单线程神经网络的训练时间为',num2str(t1),'秒']);
单线程神经网络的训练时间为0.93209秒
并行网络训练
tic
[net2,tr2]=train(net,inputs,targets,'useParallel','yes','showResources','yes');
t2=toc;
disp(['并行神经网络的训练时间为',num2str(t2),'秒']);
ComputingResources:
ParallelWorkers:
Worker1onWang_Matlab,MEXonPCWIN
Worker2onWang_Matlab,MEXonPCWIN
Lab1:
TrainingwithTRAINLM.
Epoch0/1000,Time0.096,Performance7115.2407/0,Gradient12833.5776/1e-07,Mu0.001/10000000000,ValidationChecks0/6
Epoch12/1000,Time0.397,Performance5.1658/0,Gradient3.4342/1e-07,Mu0.01/10000000000,ValidationChecks6/6
TrainingwithTRAINLMcompleted:
Validationstop.
并行神经网络的训练时间为2.2013秒
网络效果验证
outputs1=sim(net1,inputs);
outputs2=sim(net2,inputs);
errors1=gsubtract(targets,outputs1);
errors2=gsubtract(targets,outputs2);
performance1=perform(net1,targets,outputs1)
performance2=perform(net2,targets,outputs2)
performance1=
19.6247
performance2=
14.5379
神经网络可视化
figure,plotperform(tr1);
figure,plotperform(tr2);
figure,plottrainstate(tr1);
figure,plottrainstate(tr2);
figure,plotregression(targets,outputs1);
figure,plotregression(targets,outputs2);
figure,ploterrhist(errors1);
figure,ploterrhist(errors2);
matlabpoolclose
Sendingastopsignaltoalltheworkers...stopped.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- MATLAB 神经网络并行运算与神经网络基于CPUGPU的并行神经网络运算 神经网络 并行 运算 基于 CPUGPU
![提示](https://static.bdocx.com/images/bang_tan.gif)