✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
🍎个人主页:Matlab科研工作室
🍊个人信条:格物致知。
更多Matlab仿真内容点击👇
⛄ 内容介绍
人工神经网络的结构设计没有系统的规律可循,而基于传统学习的神经网络参数优化又易于陷入局 部最优解.用带退化的协同进化遗传算法可以优化神经网络结构,同时优化网络参数.将网络参数作为实数编码基因进行遗传选择.参数个体的受损率超过退化阚值 时发生结构退化.退化进程由协同进化的控制个体动态控制.试验证明,该方案能有效简化神经网络的结构和优化网络参数,收敛速度比常规遗传算法快.
⛄ 部分代码
function TESTHybrid(x,t,net,outjadid)
% Choose Input and Output Pre/Post-Processing Functions
% For a list of all processing functions type: help nnprocess
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
net.outputs{2}.processFcns = {'removeconstantrows','mapminmax'};
% Setup Division of Data for Training, Validation, Testing
% For a list of all data division functions type: help nndivide
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'sample'; % Divide up every sample
net.divideParam.trainRatio = 80/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% For help on training function 'trainlm' type: help trainlm
% For a list of all training functions type: help nntrain
net.trainFcn = 'trainlm'; % Levenberg-Marquardt
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
net.performFcn = 'mse'; % Mean squared error
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','ploterrhist','plotregression','plotfit'};
net.trainParam.showWindow=true;
net.trainParam.showCommandLine=true;
net.trainParam.show=1;
net.trainParam.epochs=100;
net.trainParam.goal=1e-8;
net.trainParam.max_fail=20;
%% Start
inputs=x;
targets=t;
% Train the Network
[net,tr] = train(net,inputs,targets);
% Test the Network
outputs = outjadid;
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs);
%% Recalculate Training Performance
trainInd=tr.trainInd;
trainInputs = inputs(:,trainInd);
trainTargets = targets(:,trainInd);
trainOutputs = outputs(:,trainInd);
trainErrors = trainTargets-trainOutputs;
trainPerformance = perform(net,trainTargets,trainOutputs);
%% Recalculate Validation Performance
valInd=tr.valInd;
valInputs = inputs(:,valInd);
valTargets = targets(:,valInd);
valOutputs = outputs(:,valInd);
valErrors = valTargets-valOutputs;
valPerformance = perform(net,valTargets,valOutputs);
%% Recalculate Test Performance
testInd=tr.testInd;
testInputs = inputs(:,testInd);
testTargets = targets(:,testInd);
testOutputs = outputs(:,testInd);
testError = testTargets-testOutputs;
testPerformance = perform(net,testTargets,testOutputs);
%% View the Network
view(net);
%% Plots
% Uncomment these lines to enable various plots.
figure;
plotperform(tr);
figure;
plottrainstate(tr);
figure;
plotregression(trainTargets,trainOutputs,'Train Data',...
valTargets,valOutputs,'Validation Data',...
testTargets,testOutputs,'Test Data',...
targets,outputs,'All Data')
figure;
ploterrhist(errors);
end
⛄ 运行结果
⛄ 参考文献
[1]罗兵, 严圣华. 基于改进遗传算法的ANN结构优化[J]. 长江大学学报:自然科学版, 2005, 2(10):3.