Changeset 47 for liacs/nc/laser-pulse-shaping
- Timestamp:
- Dec 19, 2009, 1:36:02 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
liacs/nc/laser-pulse-shaping/pso.m
r37 r47 10 10 iteration_break = 5; 11 11 max_iterations = 1000; 12 max_time = 5* 60; % in sec12 max_time = 10 * 60; % in sec 13 13 14 14 % Flock properties … … 38 38 39 39 % Global best placeholder 40 g_best = zeros(parameters,1);41 g_fitness = 1;40 g_best = ones(parameters,1) .* 9; 41 g_fitness = 0; 42 42 % at (:,x) lives the neighbor best of local_swarm 'x' 43 n_best = zeros(parameters,local_swarms);44 n_fitness = ones(parameters,local_swarms);43 n_best = ones(parameters,local_swarms) .* 9; 44 n_fitness = zeros(parameters,local_swarms); 45 45 % at (:,p,x) leves the local best of particle 'p' in local_swarm 'x' 46 l_best = zeros(parameters,local_swarm_size,local_swarms);47 l_fitness = ones(local_swarm_size, local_swarms);46 l_best = ones(parameters,local_swarm_size,local_swarms) .* 9; 47 l_fitness = zeros(local_swarm_size, local_swarms); 48 48 49 49 idle_counter = 0; … … 56 56 % See if we got any better local optimum 57 57 for p = 1:local_swarm_size 58 if fitness(p) <l_fitness(p,s)58 if fitness(p) > l_fitness(p,s) 59 59 l_fitness(p,s) = fitness(p); 60 60 l_best(:,p,s) = flock_p(:,p,s); … … 64 64 % See if we got any better neighbor optimum 65 65 for p = 1:local_swarm_size 66 if l_fitness(p,s) <n_fitness(s)66 if l_fitness(p,s) > n_fitness(s) 67 67 n_fitness(s) = l_fitness(p,s); 68 68 n_best(:,s) = l_best(:,p,s); … … 75 75 % See wether we have a new global optimum 76 76 for s = 1:local_swarms 77 if n_fitness(s) <g_fitness77 if n_fitness(s) > g_fitness 78 78 g_fitness = n_fitness(s); 79 79 g_best = n_best(:,s); … … 85 85 if idle_counter == iteration_break 86 86 fprintf('Caught by idle_counter\n'); 87 return;87 break; 88 88 end 89 89 if toc > max_time 90 90 fprintf('Caught by max_time used \n'); 91 return;91 break; 92 92 end 93 93 94 94 95 fprintf('% i : %.15f\n', i, g_fitness);95 fprintf('%04i : %.15f\n', i, g_fitness); 96 96 fitness_iterations = [fitness_iterations, i]; 97 97 fitness_history = [fitness_history, g_fitness]; … … 113 113 end 114 114 115 g_best 115 116 116 117 plot(fitness_iterations,fitness_history); … … 120 121 grid on; 121 122 legend(sprintf('Parameters %i',parameters)); 122 print( 'pso-fitness.eps','-depsc2');123 print(sprintf('pso-fitness-%f.eps', max(fitness_history)),'-depsc2');
Note:
See TracChangeset
for help on using the changeset viewer.