?? main.m
字號:
%GA與神經(jīng)網(wǎng)絡的結(jié)合的程序
clear;
% Generate a set of points in the space
source_point = -10+20*rand(2,200);
% Classified boundary is y = sin(x)+2*cos^2(x)
points_c = zeros(1,200)
for i = 1:200
point_c(i) = source_point(2,i)>(sin(source_point(1,i))+2*(cos(source_point(1,i))^2));
end
save training_data
% Plot the result
figure();
hold on;
for i = 1:200
if point_c(i) == 1
plot(source_point(1,i),source_point(2,i),'*');
else
plot(source_point(1,i),source_point(2,i),'+');
end
end
%plot the boundary
x = -10:0.01:10;
y = sin(x)+2.*cos(x).^2;
plot(x,y,'r');
hold off;
% The training progress
% Defined the lower boundary
LB = zeros(1,25);
LB(1:18) = -1*ones(1,18);
LB(19:25) = -10*ones(1,7);
% Defined the upper boundary
UB = zeros(1,25);
UB(1:18) = 1*ones(1,18);
UB(19:25) = 10*ones(1,7);
% Set the training option
options=gaoptimset;
options.PopulationSize=20;
options.Generations=100;
options.StallGenLimit=Inf;
options.StallTimeLimit=Inf;
options = gaoptimset(options,'PlotFcns',{@gaplotbestf}')
[par,fval] = ga(@fitness_fuction,25,[],[],[],[],LB,UB,[],options);
% Generate 50 points to test the parameter
exam_point = -10+20*rand(2,50);
output = exam_function(par,exam_point);
% Plot the result
figure();
hold on;
for i = 1:50
if output(i) == 1
plot(exam_point(1,i),exam_point(2,i),'*');
else
plot(exam_point(1,i),exam_point(2,i),'+');
end
end
%plot the boundary
x = -10:0.01:10;
y = sin(x)+2.*cos(x).^2;
plot(x,y,'r');
hold off;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -