-
Notifications
You must be signed in to change notification settings - Fork 1
/
ga_pdi.m
55 lines (49 loc) · 1.28 KB
/
ga_pdi.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function resultado = ga_pdi(I,out)
%%
addpath('metricas');
if ndims(I)==3
I=rgb2gray(I);
end
I=gpuArray(I);
mkdir(out);
fbest=fopen(strcat(out,'bests.csv'),'w');
size_cuadrante=17;
f_fitness = @(S)funcion_objetivo(I,S,size_cuadrante,CONTRASTE(I)/127.5);
% definir los parametros del GA
opts = gaoptimset(@ga);
opts.TolFun=0;
opts.StallGenLimit=800;
opts.Display='iter';
opts.PopulationType='bitstring';
opts.PopulationSize=80;
opts.Generations=800;
opts.CrossoverFcn=@crossovertwopoint;
opts.CrossoverFraction=0.75;
opts.UseParallel=false;
opts.MutationFcn={@mutationuniform, 0.025};
opts.SelectionFcn=@selectiontournament;
fprintf(fbest,'Tiempo; best; promedio; cuartil3; max; min; quartil1;c ;ssim\n');
F=[];
tt=tic()
for i=1:2
fid=fopen(strcat(out,'iter_',int2str(i),'.csv'),'w');
try
tini=tic();
opts.OutputFcns=@(options,state,flag)log_in_file(options,state,flag,fid,fbest,tini,I,size_cuadrante,out,int2str(i));
[x,Fval,exitFlag,Output] = ga(f_fitness,size_cuadrante*size_cuadrante-1,opts);
F(i)=Fval;
catch ME
fprintf(fbest,'NO SE TERMONO ITER NRO %f\n',i);
ME
end
fclose(fid);
end
fclose(fbest);
final=toc(tt);
if isa(I,'gpuArray')
clear I;
end
resultado={};
resultado.mejor=mean(1-F);
resultado.tiempo=final;
end