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

📄 da_gp1.&&&

📁 收集的GA的一些源程序
💻 &&&
字号:
% 
% da_gp1.m
%
% GP initialisation script
%
da_front;
drawnow;

%
% Initialise variables
%
pop_size=50;
p_mutate=0.25;
p_cross=0.65;
p_perm=0.1;
p_old=0.1;
num_gen=50;

gp_function(1,:)=' ^  ';
gp_function(2,:)=' *  ';
gp_function(3,:)=' -  ';
gp_function(4,:)=' +  ';
gp_function(5,:)=' /  ';
gp_function(6,:)='sqrt';
gp_function(7,:)='log ';
gp_function(8,:)='^2  ';
gp_function(9,:)='exp ';
include_functional=ones(9,1);
gen_function_weight=ones(9,1);
mut_function_weight=ones(9,1);

set(w1,'NumberTitle','off','Name','Initialising Static GP');

%
% Frames
%
box1=uicontrol(w1,...
	'style','frame',...
	'position',[20 260 580 160],...
	'foregroundColor',[1 1 1],...
	'backgroundcolor',[0 0 1]);
box1=uicontrol(w1,...
	'style','frame',...
	'position',[20 10 580 240],...
	'foregroundColor',[1 1 1],...
	'backgroundcolor',[0 0 1]);
%
% Probability settings
%
text(1)=da_text(w1,50,400,200,15,'Population Size:',[1 1 1],[0 0 1]);
text(2)=uicontrol(w1,...
	'position',[280 400 50 15],'style','edit',...
	'HorizontalAlignment','left',...
	'foregroundcolor',[1 1 1],'backgroundcolor',[1 0 0],...
	'string',num2str(pop_size),...
	'callback','pop_size=str2num(get(text(2),''string''));');
text(50)=da_text(w1,50,375,200,15,'Number of Generations:',[1 1 1],[0 0 1]);
text(51)=uicontrol(w1,...
	'position',[280 375 50 15],'style','edit',...
	'HorizontalAlignment','left',...
	'foregroundcolor',[1 1 1],'backgroundcolor',[1 0 0],...
	'string',num2str(num_gen),...
	'callback','num_gen=str2num(get(text(51),''string''));');
text(3)=da_text(w1,50,350,200,15,'Mutation Probability:',[1 1 1],[0 0 1]);
text(4)=uicontrol(w1,...
	'position',[280 350 50 15],'style','edit',...
	'HorizontalAlignment','left',...
	'foregroundcolor',[1 1 1],'backgroundcolor',[1 0 0],...
	'string',num2str(p_mutate),...
	'callback','p_mutate=str2num(get(text(4),''string''));');
text(5)=da_text(w1,50,325,200,15,'Crossover Probability:',[1 1 1],[0 0 1]);
text(6)=uicontrol(w1,...
	'position',[280 325 50 15],'style','edit',...
	'HorizontalAlignment','left',...
	'foregroundcolor',[1 1 1],'backgroundcolor',[1 0 0],...
	'string',num2str(p_cross),...
	'callback','p_cross=str2num(get(text(6),''string''));');
text(7)=da_text(w1,50,300,200,15,'Permutation Probability:',[1 1 1],[0 0 1]);
text(8)=uicontrol(w1,...
	'position',[280 300 50 15],'style','edit',...
	'HorizontalAlignment','left',...
	'foregroundcolor',[1 1 1],'backgroundcolor',[1 0 0],...
	'string',num2str(p_perm),...
	'callback','p_perm=str2num(get(text(8),''string''));');
text(9)=da_text(w1,50,275,200,15,'Proportion of old members:',[1 1 1],[0 0 1]);
text(10)=uicontrol(w1,...
	'position',[280 275 50 15],'style','edit',...
	'HorizontalAlignment','left',...
	'foregroundcolor',[1 1 1],'backgroundcolor',[1 0 0],...
	'string',num2str(p_old),...
	'callback','p_old=str2num(get(text(10),''string''));');

text(10)=da_text(w1,50,220,150,15,'Functional Set:',[1 1 1],[0 0 1]);
text(39)=da_text(w1,250,220,75,15,'Include:',[1 1 1],[0 0 1]);
text(40)=da_text(w1,350,220,120,15,'Generation weight:',[1 1 1],[0 0 1]);
text(41)=da_text(w1,480,220,100,15,'Mutation weight:',[1 1 1],[0 0 1]);
%
% Functional set settings
%
for i=1:9
	text(i+11)=da_text(w1,150,190-((i-1)*20),20,15,gp_function(i,:),[1 1 1],[0 0 1]);
	text(20+i)=da_text(w1,50,190-((i-1)*20),75,15,['Function: ' num2str(i)],[1 1 1],[0 0 1]);
	but(i)=uicontrol(w1,'position',[240 190-((i-1)*20) 75 15],...
		'style','push',...
		'callback',[
			['if include_functional(' num2str(i) ')==1;'],...
				['include_functional(' num2str(i) ')=0;'],...
				['set(but(' num2str(i) '),''string'',''NO'');'],...
			['else;'],...
				['include_functional(' num2str(i) ')=1;'],...
				['set(but(' num2str(i) '),''string'',''YES'');'],...
			['end;']]);
	if include_functional(i)==1
		set(but(i),'string','YES');
	else
		set(but(i),'string','NO');
	end

	text(29+i)=uicontrol(w1,'style','edit','foregroundcolor',[1 1 1],'backgroundcolor',[1 0 0],...
		'style','edit','position',[370 190-((i-1)*20) 50 15],...
		'string',num2str(gen_function_weight(i)),...
		'callback',['gen_function_weight(' num2str(i) ')=num2str(get(text(29+i),''string''));']);

	text(41+i)=uicontrol(w1,'style','edit','foregroundcolor',[1 1 1],'backgroundcolor',[1 0 0],...
		'style','edit','position',[505 190-((i-1)*20) 50 15],...
		'string',num2str(mut_function_weight(i)),...
		'callback',['mut_function_weight(' num2str(i) ')=num2str(get(text(41+i),''string''));']);
 
end	


%
% Initialise the functional set
%
farg(1)=2; fname(1)='^'; % ^
farg(2)=2; fname(2)='*'; % *
farg(3)=2; fname(3)='-'; % -
farg(4)=2; fname(4)='+'; % +
farg(5)=2; fname(5)='/'; % /
farg(6)=1; fname(6)='r'; % sqrt
farg(7)=1; fname(7)='l'; % log
farg(8)=1; fname(8)='s'; % ^2
farg(9)=1; fname(9)='p'; % exp
%
% Start button
%
but(10)=uicontrol(w1,...
	'style','push',...
	'position',[440 310 100 60],...
	'string','START GP',...
	'callback',[
	'num_fun_arg=[];',...
	'fun_name=[];',...
	'fun_wgt=[];',...
	'mut_fun_wgt=[];',...
	'count=1;',...
	'for i=1:9;',...
		'if include_functional(i)==1;',...
			'num_fun_arg(count)=farg(i);',...
			'fun_name(count)=fname(i);',...
			'fun_wgt(count)=gen_function_weight(i);',...
			'mut_fun_wgt(count)=mut_function_weight(i);',...
			'count=count+1;',...
		'end;',...
	'end;',...
	'ga_ini']);


⌨️ 快捷键说明

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