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

📄 ga_ini.nn

📁 王小平《遗传算法——理论、应用与软件实现》随书光盘
💻 NN
字号:
% Initialise Parameters for tree_ga v2.0, then call tree_ga
%

% Author             Date     Predecessor   Modification
% ======             ====     ===========   ============
% B.McKay M.Willis   18/5/95  tree_ga.m     Extracted from tree_ga
% 
% Function Calls:  tree_ga2.m 
% ===============    
%
% 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
%--------------------------------------------------------------

% TAN SIGMOIDAL NEURONS
%
while 1==2,
%
num_fun_arg(10)=2; fun_name(10)='1';
user_def_fun='{tanh(<1>*<3>)}';

num_fun_arg(11)=4; fun_name(11)='2';
user_def_fun=str2mat(user_def_fun,'{tanh(<1>*<3>+<1>*<3>)}');
 
num_fun_arg(12)=6; fun_name(12)='3';
user_def_fun=str2mat(user_def_fun,'{tanh(<1>*<3>+<1>*<3>+<1>*<3>)}');

num_fun_arg(13)=8; fun_name(13)='4';
user_def_fun=str2mat(user_def_fun,'{tanh(<1>*<3>+<1>*<3>+<1>*<3>+<1>*<3>)}');
%
end
%

% LOG SIGMOIDAL NEURONS

num_fun_arg(10)=2; fun_name(10)='1';
user_def_fun='{logsig(<1>*<3>)}';

num_fun_arg(11)=4; fun_name(11)='2';
user_def_fun=str2mat(user_def_fun,'{logsig(<1>*<3>+<1>*<3>)}');
 
num_fun_arg(12)=6; fun_name(12)='3';
user_def_fun=str2mat(user_def_fun,'{logsig(<1>*<3>+<1>*<3>+<1>*<3>)}');

num_fun_arg(13)=8; fun_name(13)='4';
user_def_fun=str2mat(user_def_fun,'{logsig(<1>*<3>+<1>*<3>+<1>*<3>+<1>*<3>)}');


% LINEAR NEURONS

%num_fun_arg(14)=2; fun_name(14)='5';
%user_def_fun=str2mat(user_def_fun,'{<1>*<3>}');

%num_fun_arg(15)=4; fun_name(15)='6';
%user_def_fun=str2mat(user_def_fun,'{<1>*<3>+<1>*<3>}');

%num_fun_arg(16)=6; fun_name(16)='7';
%user_def_fun=str2mat(user_def_fun,'{<1>*<3>+<1>*<3>+<1>*<3>}');

%num_fun_arg(17)=8; fun_name(17)='8';
%user_def_fun=str2mat(user_def_fun,'{<1>*<3>+<1>*<3>+<1>*<3>+<1>*<3>}');




  

% Remember to set up function weightings for each UDF 

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

% Basic Set of Functionals

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

% User Defined Functions

% SIGMOISDAL NEURONS
fun_wgt(10)=1;  
fun_wgt(11)=1; 
fun_wgt(12)=1;  
fun_wgt(13)=1;

%% LINEAR NEURONS 
%fun_wgt(14)=1;  
%fun_wgt(15)=1; 
%fun_wgt(16)=1;  
%fun_wgt(17)=1;

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

% Basic Set of Functionals

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

% User Defined Functions

% SIGMOISDAL NEURONS
mut_fun_wgt(10)=1;  
mut_fun_wgt(11)=1; 
mut_fun_wgt(12)=1;  
mut_fun_wgt(13)=1;

%% LINEAR NEURONS 
%mut_fun_wgt(14)=1;  
%mut_fun_wgt(15)=1; 
%mut_fun_wgt(16)=1;  
%mut_fun_wgt(17)=1;


%-------------------------------------------------------------- 
% 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 + -