fps.m

来自「王小平《遗传算法——理论、应用与软件实现》随书光盘」· M 代码 · 共 30 行

M
30
字号
% function fps_num = fps(fit)
%
% This function uses Fitness Proportionate Reproduction (FPS) to select
% an individual for reproduction, mutation, or cross over. For use with
% tree_ga2.m
%

% Author             Date     Predecessor   Modification
% ======             ====     ===========   ============
% B.McKay M.Willis   25/5/95       -             -
%
% Function Calls: 
% ==============  
%    
% Last Modification: 25/5/95
% =================
%

function fps_num = fps(fit)

% Find the cumulative probability
prob=fit./sum(fit);
cum_prob=cumsum(prob);

% Select a random number between 0 and 1
r_num=rand(1);

I=find(cum_prob > r_num);
fps_num=I(1);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?