【本科毕业设计】基本遗传算法及其在函数优化中的应用

上传人:仙*** 文档编号:28338428 上传时间:2021-08-26 格式:DOC 页数:13 大小:171.52KB
返回 下载 相关 举报
【本科毕业设计】基本遗传算法及其在函数优化中的应用_第1页
第1页 / 共13页
【本科毕业设计】基本遗传算法及其在函数优化中的应用_第2页
第2页 / 共13页
【本科毕业设计】基本遗传算法及其在函数优化中的应用_第3页
第3页 / 共13页
点击查看更多>>
资源描述
人工智能及其应用大作业(一) 题 目: 基本遗传算法及其在函数优化中的作用 学 号: 姓 名: 基本遗传算法及其在函数优化中的应用摘要:从遗传算法的编码、遗传算子等方面剖析了遗传算法求解无约束函数优化问题的一般步骤,并以一个实例说明遗传算法能有效地解决函数优化问题。本文利用基本遗传算法求解函数优化问题,选用 f(x)=xsin(10x)+2.0,取值范围在中,利用基本遗传算法求解两个函数的最优值,遗传算法每次100代,一共执行10次,根据运算结果分析得到最优解。关键字:遗传算法 选择 交叉 变异 函数优化1.前言1.1基本概念 遗传算法(Genetic Algorithm)是一类借鉴生物界的进化规律(适者生存,优胜劣汰遗传机制)演化而来的随机化搜索方法。遗传算法是一种群体型操作,该操作以群体中的所有个体为对象。选择(Selection)、交叉(Crossover)和变异(Mutation)是遗传算法的3个主要操作算子,它们构成了所谓的遗传操作(genetic operation),使遗传算法具有了其它传统方法所没有的特性。1.2 遗传算法的特点 其主要特点是直接对结构对象进行操作,不存在求导和函数连续性的限定;具有内在的隐并行性和更好的全局寻优能力;采用概率化的寻优方法,能自动获取和指导优化的搜索空间,自适应地调整搜索方向,不需要确定的规则。1.3遗传算法的应用 函数优化,组合优化,机器人智能控制,及组合图像处理和模式识别等。 2. 基本遗传算法2.1简单遗传算法的求解步骤Step1:参数设置及种群初始化;Step2:适应度评价;Step3:选择操作;Step4:交叉操作;Step5:变异操作;Step6:终止条件判断,若未达到终止条件,则转到Step3;Step7:输出结果。2.2停机准则(1) 完成了预先给定的进化代数则停止;(2) 群体中的最优个体在连续若干代没有改进或平均适应度在连续若干代基本没有改进时停止。2.3基本遗传算法框图开始Gen=0编码随机产生M个初始个体满足终止条件?计算群体中各个体适应度从左至右依次执行遗传算子j = 0j = 0j = 0根据适应度选择复制个体选择两个交叉个体选择个体变异点执行变异执行交叉执行复制将复制的个体添入新群体中将交叉后的两个新个体添入新群体中将变异后的个体添入新群体中j = j+1j = j+2j = j+1 j = M? j = pcM? j = pmLM?Gen=Gen+1输出结果终止YNYYYNNNpcpm3.实验与结果 本小节采用以下函数: f(x)=xsin(10x)+2.0,x-1,23.1编码 表现型:x 基因型:二进制编码(串长取决于求解精度) 按编码原理:假设要求求解精度到6位小数,区间长度为2-(-1)3,即需将区间分为3/0.000001=3106等份。 所以编码的二进制串长应为22位。3.2产生初始种群 产生的方式:随机 产生的结果:长度为22的二进制串 产生的数量:种群的大小(规模),如30,50, 1111010011100001011000 1100110011101010101110 1010100011110010000100 1011110010011100111001 0001100101001100000011 0000011010010000000000 .3.3计算适应度直接用目标函数作为适应度函数 解码:将个体s转化为-1,2区间的实数: s= x=0.637197 计算x的函数值(适应度): f(x)=xsin(10x)+2.0=2.5863453.4遗传操作 选择:比例选择法; 交叉:单点交叉; 变异:小概率变异3.5模拟结果 设置的参数: 种群大小80;交叉概率0.75;变异概率0.05;最大代数100。 运行结果如下表: 12345678910best_fit16.850316.850316.845416.850316.846116.849116.795216.850016.8120 16.8500best_f3.85033.85033.84543.85033.84613.84913.79523.85003.81203.8501best_x1.80061.80091.80381.80121.79791.79921.79031.80151.80001.810由上表可以分析得出的最优解为x=1.8,最大值为3.85。4.结论 遗传算法在适应度函数选择不当的情况下有可能收敛于局部最优,而不能达到全局最优。 选择的过程很重要,决定着最终结果和收敛速度等。对于任何一个具体的优化问题,调节遗传算法的参数可能会有利于更好的更快的收敛,这些参数包括个体数目、交叉律和变异律。 遗传算法并不一定总是最好的优化策略,优化问题要具体情况具体分析。参考文献:(1)蔡自兴,徐光祐人工智能及其应用(2)马永,贾俊芳.遗传算法研究综述.第23卷.第三期.2007年12月;附录:1.代码主函数:clearclcmy_scale=50; %种群规模gen_len=22; %基因长度M=100; %迭代次数pc=0.75; %交叉概率pm=0.05; %变异概率new_scale=produscale(my_scale,gen_len); %产生初始种群fitfit=; fittimer=; best_f1=;best_x1=; for i=1:M my_f=cal_my_f(new_scale); %计算函数值 my_fit=cal_my_fit(my_f); %计算适应度值 next_scale=my_sellect(new_scale,my_fit); %采用赌轮盘法选择 cross_scale=my_cross(next_scale,pc); %按概率交叉 mut_scale=my_mutat(cross_scale,pm); %按概率变异 %寻找每一代中的最优适应度值所对应的个体 best_fit=my_fit(1); sx,sy=size(new_scale); for j=2:length(my_fit) if best_fitmy_fit(j) best_fit=my_fit(j); best_f=my_f(j); best_x=my2to10(new_scale(j,:); best_x=-2+best_x.*4./(2sy-1); end end new_scale=mut_scale; fitfit=fitfit,best_fit; best_f1=best_f1,best_f; best_x1=best_x1,best_x; fittimer=fittimer,i;end best_fit,loca=max(fitfit); best_f=best_f1(loca); best_x=best_x1(loca); disp(best_fit,best_f,best_x=)disp(best_fit,best_f,best_x)subplot(2,2,1) plot(fittimer,fitfit) xlabel(迭代次数(1)-wxb); ylabel(适应度函数) grid on%子函数:产生初始种群function initscale=produscale(my_scale,gen_len) initscale=round(rand(my_scale,gen_len);end%子函数:计算函数值function my_f=cal_my_f(new_scale) mychange=my2to10(new_scale); sx,sy=size(new_scale); change_x=-1+mychange.*3./(2sy-1); my_f=change_x*sin(10*change_x)+2; end%子函数:计算适应度值function my_fit=cal_my_fit(my_f) f_min=5; for i=1:length(my_f) if my_f(i)+f_min=0 my_fit(i)=0; else my_fit(i)=my_f(i)+f_min; end end my_fit=my_fit;end %子函数:采用赌轮盘法选择function next_scale=my_sellect(new_scale,my_fit) sum_of_f=sum(my_fit); accum=my_fit/sum_of_f; accum=cumsum(accum); sx,sy=size(new_scale); j=1; while j=a next_scale(j,:)=new_scale(1,:); else if accum(i)=a next_scale(j,:)=new_scale(i+1,:); j=j+1; end end end endend%子函数:按概率交叉function cross_scale=my_cross(new_scale,pc) sx,sy=size(new_scale); cross_scale=new_scale; for i=1:2:sx-1 if randpc a=round(rand*sy); cross_scale(i,:)=new_scale(i,1:a),new_scale(i+1,a+1:end); cross_scale(i+1,:)=new_scale(i+1,1:a),new_scale(i,a+1:end); end end %子函数:按概率变异function mut_scale=my_mutat(new_scale,pm) sx,sy=size(new_scale); mut_scale=new_scale; for i=1:sx if randpm a=round(rand*sy); if a=0 a=1; end if mut_scale(i,a)=0 mut_scale(i,a)=1; else mut_scale(i,a)=0; end end end%子函数:2进制转10进制function mychange=my2to10(new_scale) sx,sy=size(new_scale); new_scale1=new_scale; for i=1:sy new_scale1(:,i)=2.(sy-i).*new_scale(:,i); end mychange=sum(new_scale1,2);end2.实验结果截图g an employment tribunal claimEmployment tribunals sort out disagreements between employers and employees.You may need to make a claim to an employment tribunal if: you dont agree with the disciplinary action your employer has taken against you your employer dismisses you and you think that you have been dismissed unfairly.For more information about dismissal and unfair dismissal, seeDismissal.You can make a claim to an employment tribunal, even if you haventappealedagainst the disciplinary action your employer has taken against you. However, if you win your case, the tribunal may reduce any compensation awarded to you as a result of your failure to appeal.Remember that in most cases you must make an application to an employment tribunal within three months of the date when the event you are complaining about happened. If your application is received after this time limit, the tribunal will not usually accept it.If you are worried about how the time limits apply to you, take advice from one of the organisations listed underFurther help.Employment tribunals are less formal than some other courts, but it is still a legal process and you will need to give evidence under an oath or affirmation.Most people find making a claim to an employment tribunal challenging. If you are thinking about making a claim to an employment tribunal, you should get help straight away from one of the organisations listed underFurther help.If you are being represented by a solicitor at the tribunal, they may ask you to sign an agreement where you pay their fee out of your compensation if you win the case. This is known as adamages-based agreement. In England and Wales, your solicitor cant charge you more than 35% of your compensation if you win the case.If you are thinking about signing up for a damages-based agreement, you should make sure youre clear about the terms of the agreement. It might be best to get advice from an experienced adviser, for example, at a Citizens Advice Bureau. To find your nearest CAB, including those that give advice by e-mail, click onnearest CAB.For more information about making a claim to an employment tribunal, seeEmployment tribunals.The (lack of) air up there Watch mCayman Islands-based Webb, the head of Fifas anti-racism taskforce, is in London for the Football Associations 150th anniversary celebrations and will attend Citys Premier League match at Chelsea on Sunday.I am going to be at the match tomorrow and I have asked to meet Yaya Toure, he told BBC Sport.For me its about how he felt and I would like to speak to him first to find out what his experience was.Uefa hasopened disciplinary proceedings against CSKAfor the racist behaviour of their fans duringCitys 2-1 win.Michel Platini, president of European footballs governing body, has also ordered an immediate investigation into the referees actions.CSKA said they were surprised and disappointed by Toures complaint. In a statement the Russian side added: We found no racist insults from fans of CSKA.Age has reached the end of the beginning of a word. May be guilty in his seems to passing a lot of different life became the appearance of the same day; May be back in the past, to oneself the paranoid weird belief disillusionment, these days, my mind has been very messy, in my mind constantly. Always feel oneself should go to do something, or write something. Twenty years of life trajectory deeply shallow, suddenly feel something, do it.一字开头的年龄已经到了尾声。或许是愧疚于自己似乎把转瞬即逝的很多个不同的日子过成了同一天的样子;或许是追溯过去,对自己那些近乎偏执的怪异信念的醒悟,这些天以来,思绪一直很凌乱,在脑海中不断纠缠。总觉得自己自己似乎应该去做点什么,或者写点什么。二十年的人生轨迹深深浅浅,突然就感觉到有些事情,非做不可了。The end of our life, and can meet many things really do?而穷尽我们的一生,又能遇到多少事情是真正地非做不可?During my childhood, think lucky money and new clothes are necessary for New Year, but as the advance of the age, will be more and more found that those things are optional; Junior high school, thought to have a crush on just means that the real growth, but over the past three years later, his writing of alumni in peace, suddenly found that isnt really grow up, it seems is not so important; Then in high school, think dont want to give vent to out your inner voice can be in the high school children of the feelings in a period, but was eventually infarction when graduation party in the throat, later again stood on the pitch he has sweat profusely, looked at his thrown a basketball hoops, suddenly found himself has already cant remember his appearance.童年时,觉得压岁钱和新衣服是过年必备,但是随着年龄的推进,会越来越发现,那些东西根本就可有可无;初中时,以为要有一场暗恋才意味着真正的成长,但三年过去后,自己心平气和的写同学录的时候,突然就发现是不是真正的成长了,好像并没有那么重要了;然后到了高中,觉得非要吐露出自己的心声才能为高中生涯里的懵懂情愫划上一个句点,但毕业晚会的时候最终还是被梗塞在了咽喉,后来再次站在他曾经挥汗如雨的球场,看着他投过篮球的球框时,突然间发现自己已经想不起他的容颜。Originally, this world, can produce a chemical reaction to an event, in addition to resolutely, have to do, and time.原来,这个世界上,对某个事件能产生化学反应的,除了非做不可的坚决,还有,时间。A persons time, your ideas are always special to clear. Want, want, line is clear, as if nothing could shake his. Also once seemed to be determined to do something, but more often is he backed out at last. Dislike his cowardice, finally found that there are a lot of love, there are a lot of miss, like shadow really have been doomed. Those who do, just green years oneself give oneself an arm injection, or is a self-righteous spiritual.一个人的时候,自己的想法总是特别地清晰。想要的,不想要的,界限明确,好像没有什么可以撼动自己。也曾经好像已经下定了决心去做某件事,但更多的时候是最后又打起了退堂鼓。嫌恶过自己的怯懦,最终却发现有很多缘分,有很多错过,好像冥冥之中真的已经注定。那些曾经所谓的非做不可,只是青葱年华里自己给自己注射的一支强心剂,或者说,是自以为是的精神寄托罢了。At the moment, the sky is dark, the air is fresh factor after just rained. Suddenly thought of blue plaid shirt; Those were broken into various shapes of stationery; From the corner at the beginning of deep friendship; Have declared the end of the encounter that havent start planning. Those years, those days of do, finally, like youth, will end in our life.此刻,天空是阴暗的,空气里有着刚下过雨之后的清新因子。突然想到那件蓝格子衬衫;那些被折成各种各样形状的信纸;那段从街角深巷伊始的友谊;还有那场还没有开始就宣告了终结的邂逅计划那些年那些天的非做不可,终于和青春一样,都将在我们的人生中谢幕。Baumgartner the disappointing news: Mission aborted. r plays an important role in this mission. Starting at the ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will climb higher than the tip of Mount Everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratosphere. As he crosses the boundary layer (called the tropopause),e can expect a lot of turbulence.The supersonic descent could happen as early as Sunda.The weatheThe balloon will slowly drift to the edge of space at 120,000 feet ( Then, I would assume, he will slowly step out onto something resembling an Olympic diving platform.Below, the Earth becomes the concrete bottom of a swimming pool that he wants to land on, but not too hard. Still, hell be traveling fast, so despite the distance, it will not be like diving into the deep end of a pool. It will be like he is diving into the shallow end. Skydiver preps for the big jumpWhen he jumps, he is expected to reach the speed of sound - 690 mph (1,110 kph) - in less than 40 seconds. Like hitting the top of the water, he will begin to slow as he approaches the more dense air closer to Earth. But this will not be enough to stop him completely.If he goes too fast or spins out of control, he has a stabilization parachute that can be deployed to slow him down. His team hopes its not needed. Instead, he plans to deploy his 270-square-foot (25-square-meter) main chute at an altitude of around 5,000 feet (1,524 meters).In order to deploy this chute successfully, he will have to slow to 172 mph (277 kph). He will have a reserve parachute that will open automatically if he loses consciousness at mach speeds.Even if everything goes as planned, it wont. Baumgartner still will free fall at a speed that would cause you and me to pass out, and no parachute is guaranteed to work higher than 25,000 feet (7,620 meters).cause there
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!