多输入多输出 | MATLAB实现GA-BP遗传算法优化BP神经网络多输入多输出

多输入多输出 | MATLAB实现GA-BP遗传算法优化BP神经网络多输入多输出

目录

    • 多输入多输出 | MATLAB实现GA-BP遗传算法优化BP神经网络多输入多输出
      • 预测效果
      • 基本介绍
      • 程序设计
      • 往期精彩
      • 参考资料

预测效果

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

基本介绍

多输入多输出 | MATLAB实现GA-BP遗传算法优化BP神经网络多输入多输出
1.data为数据集,10个输入特征,3个输出变量。
2.main.m为主程序文件。
3.命令窗口输出MBE、MAE和R2,可在下载区获取数据和程序内容。

程序设计

  • 完整程序和数据下载方式:私信博主回复MATLAB实现GA-BP遗传算法优化BP神经网络多输入多输出
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function [x, endPop, bPop, traceInfo] = ga(bounds, evalFN, evalOps, startPop, opts, ...
termFN, termOps, selectFN, selectOps, xOverFNs, xOverOps, mutFNs, mutOps)% Output Arguments:
%   x            - the best solution found during the course of the run
%   endPop       - the final population 
%   bPop         - a trace of the best population
%   traceInfo    - a matrix of best and means of the ga for each generation
%
% Input Arguments:
%   bounds       - a matrix of upper and lower bounds on the variables
%   evalFN       - the name of the evaluation .m function
%   evalOps      - options to pass to the evaluation function ([NULL])
%   startPop     - a matrix of solutions that can be initialized
%                  from initialize.m
%   opts         - [epsilon prob_ops display] change required to consider two 
%                  solutions different, prob_ops 0 if you want to apply the
%                  genetic operators probabilisticly to each solution, 1 if
%                  you are supplying a deterministic number of operator
%                  applications and display is 1 to output progress 0 for
%                  quiet. ([1e-6 1 0])
%   termFN       - name of the .m termination function (['maxGenTerm'])
%   termOps      - options string to be passed to the termination function
%                  ([100]).
%   selectFN     - name of the .m selection function (['normGeomSelect'])
%   selectOpts   - options string to be passed to select after
%                  select(pop,#,opts) ([0.08])
%   xOverFNS     - a string containing blank seperated names of Xover.m
%                  files (['arithXover heuristicXover simpleXover']) 
%   xOverOps     - A matrix of options to pass to Xover.m files with the
%                  first column being the number of that xOver to perform
%                  similiarly for mutation ([2 0;2 3;2 0])
%   mutFNs       - a string containing blank seperated names of mutation.m 
%                  files (['boundaryMutation multiNonUnifMutation ...
%                           nonUnifMutation unifMutation'])
%   mutOps       - A matrix of options to pass to Xover.m files with the
%                  first column being the number of that xOver to perform
%                  similiarly for mutation ([4 0 0;6 100 3;4 100 3;4 0 0])%%  初始化参数
n = nargin;
if n < 2 || n == 6 || n == 10 || n == 12disp('Insufficient arguements') 
end% 默认评估选项
if n < 3 evalOps = [];
end% 默认参数
if n < 5opts = [1e-6, 1, 0];
end% 默认参数
if isempty(opts)opts = [1e-6, 1, 0];
end%%  判断是否为m文件
if any(evalFN < 48)% 浮点数编码 if opts(2) == 1e1str = ['x=c1; c1(xZomeLength)=', evalFN ';'];  e2str = ['x=c2; c2(xZomeLength)=', evalFN ';']; % 二进制编码elsee1str = ['x=b2f(endPop(j,:),bounds,bits); endPop(j,xZomeLength)=', evalFN ';'];end
else% 浮点数编码if opts(2) == 1e1str = ['[c1 c1(xZomeLength)]=' evalFN '(c1,[gen evalOps]);'];  e2str = ['[c2 c2(xZomeLength)]=' evalFN '(c2,[gen evalOps]);'];% 二进制编码elsee1str=['x=b2f(endPop(j,:),bounds,bits);[x v]=' evalFN ...'(x,[gen evalOps]); endPop(j,:)=[f2b(x,bounds,bits) v];'];  end
end%%  默认终止信息
if n < 6termOps = 100;termFN = 'maxGenTerm';
end%%  默认变异信息
if n < 12% 浮点数编码if opts(2) == 1mutFNs = 'boundaryMutation multiNonUnifMutation nonUnifMutation unifMutation';mutOps = [4, 0, 0; 6, termOps(1), 3; 4, termOps(1), 3;4, 0, 0];% 二进制编码elsemutFNs = 'binaryMutation';mutOps = 0.05;end
end%%  默认交叉信息
if n < 10% 浮点数编码if opts(2) == 1xOverFNs = 'arithXover heuristicXover simpleXover';xOverOps = [2, 0; 2, 3; 2, 0];% 二进制编码elsexOverFNs = 'simpleXover';xOverOps = 0.6;end
end%%  仅默认选择选项,即轮盘赌。
if n < 9selectOps = [];
end%%  默认选择信息
if n < 8selectFN = 'normGeomSelect';selectOps = 0.08;
end%%  默认终止信息
if n < 6termOps = 100;termFN = 'maxGenTerm';
end%%  没有定的初始种群
if n < 4startPop = [];
end%%  随机生成种群
if isempty(startPop)startPop = initializega(80, bounds, evalFN, evalOps, opts(1: 2));
end%%  二进制编码
if opts(2) == 0bits = calcbits(bounds, opts(1));
end%%  参数设置
xOverFNs     = parse(xOverFNs);
mutFNs       = parse(mutFNs);
xZomeLength  = size(startPop, 2); 	          % xzome 的长度
numVar       = xZomeLength - 1; 	          % 变量数
popSize      = size(startPop,1); 	          % 种群人口个数
endPop       = zeros(popSize, xZomeLength);   % 第二种群矩阵
numXOvers    = size(xOverFNs, 1);             % Number of Crossover operators
numMuts      = size(mutFNs, 1); 		      % Number of Mutation operators
epsilon      = opts(1);                       % Threshold for two fittness to differ
oval         = max(startPop(:, xZomeLength)); % Best value in start pop
bFoundIn     = 1; 			                  % Number of times best has changed
done         = 0;                             % Done with simulated evolution
gen          = 1; 			                  % Current Generation Number
collectTrace = (nargout > 3); 		          % Should we collect info every gen
floatGA      = opts(2) == 1;                  % Probabilistic application of ops
display      = opts(3);                       % Display progress %%  精英模型
while(~done)[bval, bindx] = max(startPop(:, xZomeLength));            % Best of current popbest =  startPop(bindx, :);if collectTracetraceInfo(gen, 1) = gen; 		                        % current generationtraceInfo(gen, 2) = startPop(bindx,  xZomeLength);      % Best fittnesstraceInfo(gen, 3) = mean(startPop(:, xZomeLength));     % Avg fittnesstraceInfo(gen, 4) = std(startPop(:,  xZomeLength)); end%%  最佳解if ( (abs(bval - oval) > epsilon) || (gen==1))% 更新显示if displayfprintf(1, '\n%d %f\n', gen, bval);          end% 更新种群矩阵if floatGAbPop(bFoundIn, :) = [gen, startPop(bindx, :)]; elsebPop(bFoundIn, :) = [gen, b2f(startPop(bindx, 1 : numVar), bounds, bits)...startPop(bindx, xZomeLength)];endbFoundIn = bFoundIn + 1;                      % Update number of changesoval = bval;                                  % Update the best valelseif displayfprintf(1,'%d ',gen);	                      % Otherwise just update num genendend
%%  选择种群endPop = feval(selectFN, startPop, [gen, selectOps]);% 以参数为操作数的模型运行if floatGAfor i = 1 : numXOversfor j = 1 : xOverOps(i, 1)a = round(rand * (popSize - 1) + 1); 	     % Pick a parentb = round(rand * (popSize - 1) + 1); 	     % Pick another parentxN = deblank(xOverFNs(i, :)); 	         % Get the name of crossover function[c1, c2] = feval(xN, endPop(a, :), endPop(b, :), bounds, [gen, xOverOps(i, :)]);% Make sure we created a new if c1(1 : numVar) == endPop(a, (1 : numVar)) c1(xZomeLength) = endPop(a, xZomeLength);elseif c1(1:numVar) == endPop(b, (1 : numVar))c1(xZomeLength) = endPop(b, xZomeLength);elseeval(e1str);endif c2(1 : numVar) == endPop(a, (1 : numVar))c2(xZomeLength) = endPop(a, xZomeLength);elseif c2(1 : numVar) == endPop(b, (1 : numVar))c2(xZomeLength) = endPop(b, xZomeLength);elseeval(e2str);endendPop(a, :) = c1;endPop(b, :) = c2;endendfor i = 1 : numMutsfor j = 1 : mutOps(i, 1)a = round(rand * (popSize - 1) + 1);c1 = feval(deblank(mutFNs(i, :)), endPop(a, :), bounds, [gen, mutOps(i, :)]);if c1(1 : numVar) == endPop(a, (1 : numVar)) c1(xZomeLength) = endPop(a, xZomeLength);elseeval(e1str);endendPop(a, :) = c1;endend%%  运行遗传算子的概率模型else for i = 1 : numXOversxN = deblank(xOverFNs(i, :));cp = find((rand(popSize, 1) < xOverOps(i, 1)) == 1);if rem(size(cp, 1), 2) cp = cp(1 : (size(cp, 1) - 1)); endcp = reshape(cp, size(cp, 1) / 2, 2);for j = 1 : size(cp, 1)a = cp(j, 1); b = cp(j, 2); [endPop(a, :), endPop(b, :)] = feval(xN, endPop(a, :), endPop(b, :), ...bounds, [gen, xOverOps(i, :)]);endendfor i = 1 : numMutsmN = deblank(mutFNs(i, :));for j = 1 : popSizeendPop(j, :) = feval(mN, endPop(j, :), bounds, [gen, mutOps(i, :)]);eval(e1str);endendend%  更新记录gen = gen + 1;done = feval(termFN, [gen, termOps], bPop, endPop); % See if the ga is donestartPop = endPop; 			                      % Swap the populations[~, bindx] = min(startPop(:, xZomeLength));         % Keep the best solutionstartPop(bindx, :) = best; 		                  % replace it with the worstend
[bval, bindx] = max(startPop(:, xZomeLength));%%  显示结果
if display fprintf(1, '\n%d %f\n', gen, bval);	  
end%%  二进制编码
x = startPop(bindx, :);
if opts(2) == 0x = b2f(x, bounds,bits);bPop(bFoundIn, :) = [gen, b2f(startPop(bindx, 1 : numVar), bounds, bits)...startPop(bindx, xZomeLength)];
elsebPop(bFoundIn, :) = [gen, startPop(bindx, :)];
end%%  赋值
if collectTracetraceInfo(gen, 1) = gen; 		                      % 当前迭代次数traceInfo(gen, 2) = startPop(bindx, xZomeLength);   % 最佳适应度traceInfo(gen, 3) = mean(startPop(:, xZomeLength)); % 平均适应度
end

往期精彩

MATLAB实现RBF径向基神经网络多输入多输出预测
MATLAB实现BP神经网络多输入多输出预测
MATLAB实现DNN神经网络多输入多输出预测

参考资料

[1] https://blog.csdn.net/kjm13182345320/article/details/116377961
[2] https://blog.csdn.net/kjm13182345320/article/details/127931217
[3] https://blog.csdn.net/kjm13182345320/article/details/127894261

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/85474.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

《向量数据库指南》——向量搜索库Faiss 迁移到 Milvus 2.x

Faiss -> Milvus 2.x 1. Faiss 数据准备 前提条件是用户已经准备好了自己的 faiss 数据文件。(为了能快速体验,在项目源码的 testfiles 目录下放置了 faiss 测试数据方便用户体验: faiss_ivf_flat.index. 2. 编译打包 这部分同上,不再展开介绍。 3. 配置 migration.ymal…

vue下载Excel文件

前端vue实现导出Excel文件 用到的是 上代码 var wb XLSX.utils.table_to_book(document.querySelector(#my-table));//关联dom节点 这个是表格绑定的id名称var wbout XLSX.write(wb, {bookType: xlsx,bookSST: true,type: array})try {FileSaver.saveAs(new Blob([wbout], {…

【教学类】公开课学号挂牌(15*15CM手工纸)

作品展示&#xff1a; 15*15CM手工纸 文本框12磅加粗。学号数字是段落写入&#xff0c;黑体270磅 背景需求 最近都在小班、中班、大班里做“Python学具测试”&#xff0c;由于都是陌生的孩子&#xff0c;上课时&#xff0c;我通常只能喊“白衣服的女孩”“花格子衣服的男孩”…

精华回顾:Web3 前沿创新者在 DESTINATION MOON 共话未来

9 月 17 日&#xff0c;由 TinTinLand 主办的「DESTINATION MOON: Web3 Dev Summit Shanghai 2023」线下活动在上海黄浦如约而至。 本次 DESTINATION MOON 活动作为 2023 上海区块链国际周的 Side Event&#xff0c;设立了 4 场主题演讲与 3 个圆桌讨论&#xff0c;聚集了诸多…

strtok()函数的使用方法

strtok() 函数用于将字符串分割成子字符串&#xff08;标记&#xff09;。它在 C 语言中非常常用&#xff0c;可以通过指定分隔符来拆分原始字符串&#xff0c;并依次返回每个子字符串。 以下是 strtok() 函数的使用方法&#xff1a; #include <stdio.h> #include <…

Python方法汇总:轻松实现功能!

在爬虫开发中&#xff0c;有时需要模拟登录网站以获取更多的数据或执行特定的操作。本文将为你总结几种常用的Python爬虫模拟登录方法&#xff0c;帮助你轻松实现登录功能&#xff0c;让你的爬虫更加强大有用。 一、基于Requests库的模拟登录 1. 使用Session对象&#xff1a;…

UOS Deepin Ubuntu Linux 开启 ssh 远程登录

UOS Deepin Ubuntu Linux 开启 ssh 远程登录 打开控制台 安装 openssh-server sudo apt -y install openssh-server修改 /etc/ssh/ssh_config 文件 sudo vim /etc/ssh/ssh_config找到 # Port 22 去掉 # 注释后 保存 重启 ssh 服务 sudo systemctl restart ssh设置 ssh 服务 开机…

ros开发中编译cpp文件的2个办法

方式一&#xff1a; 在Ubuntu控制台输入指令 cd catkin_ws 进入到工作空间 然后在输入&#xff1a; catkin_make --pkg catkin_practice 注释&#xff1a;以上catkin_ws是工作空间名称&#xff0c;catkin_practice是工作空间中将要被编译的包的名称 方式二&#xff1a; …

前端控制小数点精度及数字千位分割

前端控制小数点精度及数字千位分割&#xff0c;表头居中&#xff0c;每行单元格内容居右。 前端控制小数点精度&#xff1a; <el-table-column prop"cycz" label"差异产值" header-align"center" align"right"><template s…

JVM高级性能调试

标准的JVM是配置为了高吞吐量&#xff0c;吞吐量是为了科学计算和后台运行使用&#xff0c;而互联网商业应用&#xff0c;更多是为追求更短的响应时间&#xff0c;更低的延迟Latency&#xff08;说白了就是更快速度&#xff09;&#xff0c;当用户打开网页没有快速响应&#xf…

安卓机型-MTK芯片掉串码 掉基带 如何用工具进行修复 改写参数

在早期MTK芯片机型中较多使用AP BP方式来修复mtk芯片机型的串码。目前MTK机型对于丢基带 掉串码问题大都使用MODEM META工具来进行修复串码或者改写参数。今天以一款mtk芯片机型来做个演示&#xff0c; 高通芯片类的可以参考; 高通改串相关 工具仅支持在联发科芯片组上运行的…

WEB使用VUE3实现地图导航跳转

我们在用手机查看网页时可以通过传入经纬度去设置目的地然后跳转到对应的地图导航软件&#xff0c;如果没有下载软件则会跳转到下载界面 注意&#xff1a; 高德地图是一定会跳转到一个新网页然后去询问用户是否需要打开软件百度和腾讯地图是直接调用软件的这个方法有缺陷&…

iOS——引用计数(一)

自动引用计数 自动引用计数&#xff08;ARC&#xff0c;Automatic Reference Counting&#xff09;是指内存管理中对引用采取自动计数的技术。 满足以下要求后&#xff0c;我们的代码就无需再次键入retain或者是release代码了&#xff1a; 使用Xcode 4.2或以上版本使用LLVM编…

Android 启动优化案例:WebView非预期初始化排查

去年年底做启动优化时&#xff0c;有个比较好玩的 case 给大家分享下&#xff0c;希望大家能从我的分享里 get 到我在做一些问题排查修复时是怎么看上去又low又土又高效的。 1. 现象 在我们使用 Perfetto 进行app 启动过程性能观测时&#xff0c;在 UI 线程发现了一段 几十毫…

Mybatis分页框架-PageHelper

Mybatis分页框架-PageHelper 一、PageHelper基础使用1.引入jar包2.配置conifg3.测试使用 二、PageHelper的多种用法1.使用PageHelper.startPage传入对象2.不使用PageHelper.startPage,而使用PageHelper.offsetPage3.使用Lambda进行分页4.不使用PageHelper直接分页5.想要使用分页…

Google拟放弃博通自行研发AI芯片 | 百能云芯

谷歌计划自行研发人工智能&#xff08;AI&#xff09;芯片&#xff0c;考虑将博通&#xff08;Broadcom&#xff09;从其供应商名单中剔除&#xff0c;但谷歌强调双方的合作关系不会受到影响。 根据美国网络媒体《The Information》的报道&#xff0c;谷歌高层正在讨论可能在20…

【计算机网络】图解路由器(二)

本系列包含&#xff1a; 图解路由器&#xff08;一&#xff09;图解路由器&#xff08;二&#xff09; 图解路由器&#xff08;二&#xff09; 21、什么是静态路由&#xff1f;22、什么是动态路由&#xff1f;23、动态路由有哪些类型&#xff1f;24、什么是 RIP &#xff1f;2…

Python教程(14)——Python函数的入门学习

函数是什么&#xff1f;在编程中&#xff0c;函数是一段可重用的代码块&#xff0c;用于完成特定任务或执行特定操作。它可以接输入参数并返回一个值或执行一系列操作。函数可以帮助程序员将代码模块化&#xff0c;提高代码的可读性和可维护性。 函数通常包括以下组成部分&…

排序算法之归并排序

一、归并排序的形象理解 原题链接 示例代码 void merge_sort(int q[], int l, int r) {if (l > r) return;int mid l r >> 1;merge_sort(q, l, mid), merge_sort(q, mid 1, r);int k 0, i l, j mid 1;while (i < mid && j < r) //第一处if (q[i]…

003 linux 自动化构建工具-make/makefile

前言 本文将会向您介绍make/makefile的原理与操作 引入 首先先向您介绍linux的编译器gcc的编译过程&#xff1a; 预处理 预处理功能主要包括宏定义,文件包含,条件编译,去注释等。 预处理指令是以#号开头的代码行。 实例: gcc –E hello.c –o hello.i 选项“-E”,该选项的作…