• 1.首家专业真正意义的悬赏问答赚钱网站!
  • 2.我们相信:重金之下必有勇者,钱能促进回答!
  • 3.购买答案别害怕,网站有担保,不满意可退款,拒绝恶意操作!
  • 4.回答售出就有收益,永久不限次数为您持续产生收益!
  • 5.提问也可以赚钱了,提问所属答案被购买确认,也可产生收益!
  • 6.收益计量都是不限次数、时间、地点,真正意义上的摇钱树!
  • 7.购买者是提问者本人,回答者享有百分百收益!
  • 8.自问自答模式已开启!经验/文章博客/聊天记录变问答赚钱!
    未登录
    当前位置: 首页 经验之谈 问题详情

    遗传算法新手教学?(最好有案例,一步一步的分解)

    发布时间:2020-03-23 17:39 注:该提问由177*****796 发起的自问自答(由他的知识、经验、图书/文章等拆分演变为问答形式而来),该自问自答产生所有收益的0%归发布人所有。如果你觉得你有更好的回答,也可以参与回答,回答收益分成70%
    以下为提问人的全部回答内容

    这是本人见过最详细的步骤了:

    需要如下主函数:

       编码和种群生成

     function [pop] = initializega(num,bounds,evalFN,evalOps,options)

    % pop    - the initial, evaluated, random population

    % num    - the size of the population, i.e. the number to create

    % bounds - the number of permutations in an individual (e.g., number

    %          of cities in a tsp

    % evalFN - the evaluation fn, usually the name of the .m file for evaluation

    % evalOps- any options to be passed to the eval function defaults [ ]

    % options- options to the initialize function, ie. [eps, float/binary, prec]

    %        where eps is the epsilon value and the second option is 1 for

    %     orderOps, prec is the precision of the variables defaults [1e-6 1]

       交叉

    function [c1,c2] = arithXover(p1,p2,bounds,Ops)

    % Arith crossover takes two parents P1,P2 and performs an interpolation

    % along the line formed by the two parents.

    %

    % function [c1,c2] = arithXover(p1,p2,bounds,Ops)

    % p1      - the first parent ( [solution string function value] )

    % p2      - the second parent ( [solution string function value] )

    % bounds  - the bounds matrix for the solution space

    % Ops     - Options matrix for arith crossover [gen #ArithXovers]

     

    选择

    normGeomSelectNormGeomSelect is a ranking selection

     function based on the normalized geometric distribution.

    (基于正态分布的序列选择函数)

     

    变异

    function[newPop] = normGeomSelect(oldPop,options)

    % NormGeomSelect is a ranking selection function based on

     the normalized

    % geometric distribution. 

    %

    % function[newPop] = normGeomSelect(oldPop,options)

    % newPop  - the new population selected from the oldPop

    % oldPop  - the current population

    % options - options to normGeomSelect

    [gen probability_of_selecting_best]

    一些辅助函数

        f2b Return the binary representation of the float number

     fval(将浮点数转化为二进制数)

        b2fReturn the float number corresponing to the binary

    representation of bval. (将二进制数转化为

    浮点数)

        nonUnifMutation Non uniform mutation changes one

     of the parameters of the parent based on a non-uniform

    probability distribution.  This Gaussian distribution starts wide,

     and narrows to a point distribution as the current generation

     approaches the maximum generation.

    (基于非均一概率分布进行非均一变异)

    maxGenTermReturns 1, i.e. terminates the GA when the

    maximal_generation is reached.

    (当迭代次数大于最大迭代次数时,终止遗传算法,返回

    1,否则返回为0。)

    rouletteroulette is the traditional selection function with the

     probability of surviving equal to the fittness of i / sum of the

     fittness of all individuals

    三、应用举例

    1.计算下列函数的最大值。

     f(x)=x+10*sin(5x)+7cos(4x) , x[0,9]

     方式1  >>gademo

     方式2  

      step 1 编写目标函数gademo1eval1.m

     

    function [sol, val] = gaDemo1Eval(sol,options)

    x=sol(1);

    val = x + 10*sin(5*x)+7*cos(4*x);

      step 2 生成初始种群,大小为10

      initPop=initializega(10,[0, 9],'gademo1eval1',[],[1e-6,1]);

    step 3  25次遗传迭代

       [x, endPop,bpop,trace] = ga([0 9],'gademo1eval1',[],initPop,...

    [1e-6 1 1],'maxGenTerm',25,...

                  'normGeomSelect',[0.08],...

    ['arithXover'],[2],...

    'nonUnifMutation',[2, 25 ,3])

    % 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

    展开阅读全文
    0 ID:5018418 0人购买 0人评价 好评率:0%
    收起
    0条回答
    抱歉,暂无数据
    返回顶部 联系客服 消息中心0