24小时热门版块排行榜    

查看: 2734  |  回复: 7

free0121

木虫 (著名写手)

[求助] 关于全局最优法和遗传算法 已有2人参与

大家好,最近尝试了一下遗传算法,初始种群是系统随机抽取的,以致于每次算出来的结果都不太一样。本来想说通过遗传算法得到接近全局最优的解,结果这些解好像都是局部最优。于是尝试了一个全局最优的算法,先做了个小实验,但不成功。希望大侠们帮忙看看问题出在哪里了,不胜感激!
对于遗传算法很熟悉的朋友,也向大家请教一下在使用遗传算法时当注意什么问题,怎么使得到的解能比较接近全局最优。谢谢!

function main
    clear all
    close all
    clc

    A=[];b=[];
    Aeq=[];beq=[];
    lb=[0.2;0.1];
    ub=[4.0;1.6];
    x0=[2.5;1.0];
      
    opts1 = optimset('Algorithm','interior-point');
    opts2 = optimset('Algorithm','sqp');
    opts3 = optimset('Algorithm','trust-region-reflective');
    opts4 = optimset('Algorithm','active-set');
   
    problem1 = createOptimProblem('fmincon','objective',...
         @objfun,'x0',x0, 'Aineq', A, 'bineq', b, 'nonlcon', @mycon, 'options',opts1);
    problem2 = createOptimProblem('fmincon','objective',...
         @objfun,'x0',x0, 'Aineq', A, 'bineq', b, 'nonlcon', @mycon, 'options',opts2);
    problem3 = createOptimProblem('fmincon','objective',...
         @objfun,'x0',x0, 'Aineq', A, 'bineq', b, 'nonlcon', @mycon, 'options',opts3);
    problem4 = createOptimProblem('fmincon','objective',...
         @objfun,'x0',x0, 'Aineq', A, 'bineq', b, 'nonlcon', @mycon, 'options',opts4);
    gs = GlobalSearch;
    [x1,fval1] = run(gs,problem1);
    [x2,fval2] = run(gs,problem2);
    [x3,fval3] = run(gs,problem3);
    [x4,fval4] = run(gs,problem4);
end

% objective function
function f0=objfun(x)
f0=x(1)*sqrt(1.0+x(2)^2);
end

% constraint function
function [f,ceq]=mycon(x)
f=(0.124*(8.0/x(1)+1.0/(x(1)*x(2)))*sqrt(1.0+x(2)^2))-1.0;
ceq=[];
end

运行后得到

GlobalSearch stopped because it analyzed all the trial points.
1 out of 39 local solver runs converged with a positive local solver exit flag.
No solution found.

GlobalSearch did not find any solutions after 399 local solver runs.
Warning: The default trust-region-reflective algorithm does not solve problems
with the constraints you have specified. FMINCON will use the active-set
algorithm instead. For information on applicable algorithms, see Choosing the
Algorithm in the documentation.
> In fmincon at 486
  In C:\Program Files\MATLAB\R2011b\toolbox\globaloptim\globaloptim\private\globalsearchnlp.p>globalsearchnlp at 152
  In GlobalSearch>GlobalSearch.run at 330
  
GlobalSearch stopped with one or more of the local solver runs stopping prematurely.

15 out of 39 local solver runs exceeded the iteration limit (problem.options.MaxIter) or
the function evaluation limit (problem.options.MaxFunEvals).
None of the 39 local solver runs converged with a positive local solver exit flag.

GlobalSearch stopped with one or more of the local solver runs stopping prematurely.

13 out of 36 local solver runs exceeded the iteration limit (problem.options.MaxIter) or
the function evaluation limit (problem.options.MaxFunEvals).
None of the 36 local solver runs converged with a positive local solver exit flag.

这是为什么呢?
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

free0121

木虫 (著名写手)

哦,自己發現問題所在了~~
2楼2014-01-20 21:46:47
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

张天天__

铁虫 (初入文坛)

【答案】应助回帖

★ ★ ★ ★ ★ ★ ★ ★ ★ ★
感谢参与,应助指数 +1
free0121: 金币+10, ★★★很有帮助, 谢谢! 2014-02-04 03:43:20
我也是研究不久,遗传算法使用时应当在基本遗传算法的基础上附加一些避免算法早熟、不收敛的策略,进化过程中既要保持种群多样度,避免收敛于局部最优,又得保证每次迭代得到的优个体得到保存从而使得算法收敛。。。。总儿言之就是既要收敛又不能过早收敛,既要成熟由不要早熟。。。
3楼2014-01-20 21:50:37
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

张天天__

铁虫 (初入文坛)

引用回帖:
2楼: Originally posted by free0121 at 2014-01-20 21:46:47
哦,自己發現問題所在了~~

你怎样保证得到全局最优
4楼2014-01-20 21:54:56
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

戴钢盔的猪头

木虫 (知名作家)

【答案】应助回帖

感谢参与,应助指数 +1
任何所谓全局最优算法几乎都不可能找到最优解,可以以全局优化的结论作为初始猜测再执行若干次经典优化算法,保证尽最大可能获取最优解。

[ 发自手机版 http://muchong.com/3g ]
5楼2014-01-21 08:49:39
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

free0121

木虫 (著名写手)

是的,所谓全局最优也无法找到最优解,但是它可以搜索到很多局部最优解,然后从这些局部最优解中找出最优的解。这个方法不适合计算量大的问题。3楼说的遗传算法要注意的问题确实是那样,弄不好得到的解会很糟糕。
6楼2014-02-04 03:42:36
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

冷烨000

新虫 (初入文坛)

引用回帖:
6楼: Originally posted by free0121 at 2014-02-04 03:42:36
是的,所谓全局最优也无法找到最优解,但是它可以搜索到很多局部最优解,然后从这些局部最优解中找出最优的解。这个方法不适合计算量大的问题。3楼说的遗传算法要注意的问题确实是那样,弄不好得到的解会很糟糕。

你好,我想问下全局最优用算法怎么实现啊?
回首向来萧瑟处,归去,也无风雨也无晴
7楼2014-04-25 18:57:51
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

冷烨000

新虫 (初入文坛)

引用回帖:
2楼: Originally posted by free0121 at 2014-01-20 21:46:47
哦,自己發現問題所在了~~

你好,我想问下,你这个是全局最优的程序吗?你能给我解释下这个程序的意思吗。我现在也在用遗传算法,进行系统结构和参数识别,但是我根据已知的样本数据得到的结果很不理想,而且参数的取值范围是未知的,这种情况下,怎么尝试设置参数的范围?
回首向来萧瑟处,归去,也无风雨也无晴
8楼2014-04-25 19:01:03
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 free0121 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 让我中一个面上吧! +4 大萍1987 2026-08-20 4/200 2026-08-20 20:22 by ran2233
[基金申请] 时间戳又变了 +12 wuchongjun 2026-08-20 17/850 2026-08-20 20:05 by spzhao
[基金申请] 时间戳变了,能看出什么问题? +18 基诺咪客 2026-08-17 23/1150 2026-08-20 17:19 by Godzela
[基金申请] 只有每年这种时候来逛逛小木虫 +21 yaoyewhu2008 2026-08-20 22/1100 2026-08-20 17:03 by yaoyewhu2008
[基金申请] 放榜前的不淡定 40+3 snowwithsea 2026-08-19 12/600 2026-08-20 15:56 by lfy8008
[基金申请] 言之凿凿,明天官网会通知放榜? +14 医学老男孩 2026-08-20 16/800 2026-08-20 15:47 by LNP@mRNA
[基金申请] 重要消息,中午系统在维护 +11 yuleib84 2026-08-18 12/600 2026-08-20 11:09 by xskun
[基金申请] 今天基金会出结果吗?20260819 +14 kkkl_v 2026-08-19 15/750 2026-08-20 08:21 by sunzitan
[基金申请] filecode,4个jtjc了 +11 ziyangfang 2026-08-19 13/650 2026-08-19 21:28 by aasahr
[教师之家] 为什么余额宝的年化利率越来越低?主要原因有哪些? +5 瞬息宇宙 2026-08-15 5/250 2026-08-19 20:23 by super2002521
[基金申请] 今天放榜没戏了吧 +4 yuleib84 2026-08-19 5/250 2026-08-19 19:52 by hhs666
[基金申请] 今天放榜吗? +14 布布和一二 2026-08-19 15/750 2026-08-19 18:07 by gltch
[基金申请] 快农历七夕节了,轻松一下,男人悄悄话,女施主请不要进来。 +6 Tide man 2026-08-14 7/350 2026-08-19 09:56 by ZJTJZ
[基金申请] 什么时候开奖? +6 CrisMessi 2026-08-18 6/300 2026-08-19 08:06 by Equinoxhua
[基金申请] 明天放榜? +5 Shxjjxjkx 2026-08-18 5/250 2026-08-18 18:14 by -大大大大大-
[基金申请] 时间戳又变了8-15 +14 archvillain 2026-08-15 26/1300 2026-08-18 13:37 by phantomgost
[基金申请] 93BebMhtakh前后11位开头都是大写 +4 且听虎啸 2026-08-17 5/250 2026-08-18 00:49 by 蔡棒棒菂
[基金申请] 感觉是下周放榜了 +6 angus9576 2026-08-17 11/550 2026-08-17 23:57 by angus9576
[精细化工] 招聘 金属平磨液,抛光液研发工程师 +3 小天0311 2026-08-14 3/150 2026-08-16 07:31 by H9PLUS
[基金申请] 各位道友,我要去昆明玩几天,回来见。 +7 Tide man 2026-08-14 8/400 2026-08-15 01:11 by arzu_hma
信息提示
请填处理意见