⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ga_ini.std

📁 用MATLAB实现遗传算法中的好多问题
💻 STD
字号:
% Initialise Parameters for tree_ga v2.0, then call tree_ga
% Last Modification: 30/5/95
% Population Size
pop_size=25;
% Number of Generations
num_gen=60;
%--------------------------------------------------------------
% Equation Generation
%--------------------------------------------------------------
% p_sub_tree: probability of a sub tree
% p_const: probability of a constant
% Note: Probability of an input = 1 - p_sub_tree - p_const
%
% s_length: Number of sub trees concatenated in equ-gen
%

p_sub_tree=0.5;
p_const=0.2;
s_length=6;

equ_par = [p_sub_tree p_const];


%--------------------------------------------------------------
% Least Squares Optimisation Options
%--------------------------------------------------------------

%options(1)  = 1;  % Display results
%options(5)  = 1;  % Gauss Newton
options(14) = 1000; % Maximum itterations

time_out = 20;

%--------------------------------------------------------------
% Reproduction
%--------------------------------------------------------------

% Generation Gap
% Proportion of old population included in new population

p_old=0.1;

% Mutation and Cross Over Probabilities

p_mutate=0.3;
p_cross=0.7;

% Probability of converting a constant to an input during mutation
% equal to P(converting an input to a constant during mutation)

p_c2u = 0.1; 
 
%--------------------------------------------------------------
% Fitness Function
%--------------------------------------------------------------

ffunc = 'ccf';
%ffunc = 'mse';

%--------------------------------------------------------------
% Displaying Results, Saving and Reinitialising
%--------------------------------------------------------------

% Display frequency
presults=10

% Save best solution, and write to file
dump_num = 2;

% Re-initialise population from best solution at given generation interval
rein_num = 100;
 
%--------------------------------------------------------------
% Basic Set of Functionals
%--------------------------------------------------------------

% Number of Arguments and Function Identifier

 num_fun_arg(1)=2; fun_name(1)='^'; % ^
 num_fun_arg(2)=2; fun_name(2)='*'; % *
 num_fun_arg(3)=2; fun_name(3)='-'; % -
 num_fun_arg(4)=2; fun_name(4)='+'; % +
 num_fun_arg(5)=2; fun_name(5)='/'; % /
 num_fun_arg(6)=1; fun_name(6)='r'; % sqrt
 num_fun_arg(7)=1; fun_name(7)='l'; % log
 num_fun_arg(8)=1; fun_name(8)='s'; % ^2
 num_fun_arg(9)=1; fun_name(9)='p'; % exp

%-------------------------------------------------------------- 
% User Defined Functions (UDF's)
%--------------------------------------------------------------
% Function Socket Types
% <1> = Constant Only
% <2> = Input Only
% <3> = Sub Tree
%--------------------------------------------------------------

% Arrhenius Type Function

num_fun_arg(10)=2; fun_name(10)='1';
user_def_fun='{7.2e9*<3>*p(9.5e3/u3)*<3>}';

 
% Residence Time

num_fun_arg(11)=2; fun_name(11)='2';
user_def_fun=str2mat(user_def_fun,'{1000*<3>/u1*<3>}');  
  
% Remember to set up function weightings for each UDF 

%-------------------------------------------------------------- 
% Functional Weightings for Initial Population Generation
%-------------------------------------------------------------- 

% Basic Set of Functionals

fun_wgt(1)=2; % ^
fun_wgt(2)=3; % *
fun_wgt(3)=3; % -
fun_wgt(4)=3; % +
fun_wgt(5)=3; % /
fun_wgt(6)=1; % sqrt
fun_wgt(7)=1; % log
fun_wgt(8)=1; % ^2
fun_wgt(9)=1; % exp

% User Defined Functions

fun_wgt(10)=0; % Arrhenius type function 
fun_wgt(11)=0; % Residence Time
%fun_wgt(12)=1; % Test function 2
%fun_wgt(13)=1; % Test function 3

%-------------------------------------------------------------- 
% Functional Weightings for Mutation
%-------------------------------------------------------------- 

% Basic Set of Functionals

mut_fun_wgt(1)=2; % ^
mut_fun_wgt(2)=3; % *
mut_fun_wgt(3)=3; % -
mut_fun_wgt(4)=3; % +
mut_fun_wgt(5)=3; % /
mut_fun_wgt(6)=1; % sqrt
mut_fun_wgt(7)=1; % log
mut_fun_wgt(8)=1; % ^2
mut_fun_wgt(9)=1; % exp

% User Defined Functions

mut_fun_wgt(10)=0; % Arrhenius type function 
mut_fun_wgt(11)=0; % Residence Time
%mut_fun_wgt(11)=1; % Test function 1
%mut_fun_wgt(12)=1; % Test function 2
%mut_fun_wgt(13)=1; % Test function 3

%-------------------------------------------------------------- 
% Generate fun_set

 for i=1:fun_wgt(1),
    fun_set(i)=fun_name(1);num_fun_arg_set(i)=num_fun_arg(1);
 end
 fun_ind=fun_wgt(1);
 
 for j=2:length(fun_wgt),
    for i=fun_ind+1:fun_ind+fun_wgt(j),
       fun_set(i)=fun_name(j);num_fun_arg_set(i)=num_fun_arg(j);
    end;
    fun_ind=fun_ind+fun_wgt(j);
 end        
 
%--------------------------------------------------------------
% Generate mut_fun_set

 for i=1:mut_fun_wgt(1),
    mut_fun_set(i)=fun_name(1);mut_num_fun_arg_set(i)=num_fun_arg(1);
 end
 fun_ind=mut_fun_wgt(1);
 
 for j=2:length(mut_fun_wgt),
    for i=fun_ind+1:fun_ind+mut_fun_wgt(j),
       mut_fun_set(i)=fun_name(j);mut_num_fun_arg_set(i)=num_fun_arg(j);
    end;
    fun_ind=fun_ind+mut_fun_wgt(j);
 end


%--------------------------------------------------------------
% Call tree_ga
%

tree_ga2


%
% End
%

⌨️ 快捷键说明

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