【ANN预测】基于遗传算法优化 ANN附matlab代码

✅作者简介:热爱科研的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.

⛳️ 完整代码

❤️部分理论引用网络文献,若有侵权联系博主删除

❤️ 关注我领取海量matlab电子书和数学建模资料

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值