Changeset 47


Ignore:
Timestamp:
Dec 19, 2009, 1:36:02 PM (15 years ago)
Author:
Rick van der Zwet
Message:

It's MAX not minimum :-)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • liacs/nc/laser-pulse-shaping/pso.m

    r37 r47  
    1010iteration_break = 5;
    1111max_iterations = 1000;
    12 max_time = 5 * 60; % in sec
     12max_time = 10 * 60; % in sec
    1313
    1414% Flock properties
     
    3838
    3939% Global best placeholder
    40 g_best = zeros(parameters,1);
    41 g_fitness = 1;
     40g_best = ones(parameters,1) .* 9;
     41g_fitness = 0;
    4242% at (:,x) lives the neighbor best of local_swarm 'x'
    43 n_best = zeros(parameters,local_swarms);
    44 n_fitness = ones(parameters,local_swarms);
     43n_best = ones(parameters,local_swarms) .* 9;
     44n_fitness = zeros(parameters,local_swarms);
    4545% 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);
     46l_best = ones(parameters,local_swarm_size,local_swarms) .* 9;
     47l_fitness = zeros(local_swarm_size, local_swarms);
    4848
    4949idle_counter = 0;
     
    5656        % See if we got any better local optimum
    5757        for p = 1:local_swarm_size
    58             if fitness(p) < l_fitness(p,s)
     58            if fitness(p) > l_fitness(p,s)
    5959                l_fitness(p,s) = fitness(p);
    6060                l_best(:,p,s) = flock_p(:,p,s);
     
    6464        % See if we got any better neighbor optimum
    6565        for p = 1:local_swarm_size
    66             if l_fitness(p,s) < n_fitness(s)
     66            if l_fitness(p,s) > n_fitness(s)
    6767                n_fitness(s) = l_fitness(p,s);
    6868                n_best(:,s) = l_best(:,p,s);
     
    7575    % See wether we have a new global optimum
    7676    for s = 1:local_swarms
    77         if n_fitness(s) < g_fitness
     77        if n_fitness(s) > g_fitness
    7878          g_fitness = n_fitness(s);
    7979          g_best = n_best(:,s);
     
    8585    if idle_counter == iteration_break
    8686        fprintf('Caught by idle_counter\n');
    87         return;
     87        break;
    8888    end
    8989    if toc > max_time
    9090        fprintf('Caught by max_time used \n');
    91         return;
     91        break;
    9292    end
    9393   
    9494
    95     fprintf('%i : %.15f\n', i, g_fitness);
     95    fprintf('%04i : %.15f\n', i, g_fitness);
    9696    fitness_iterations = [fitness_iterations, i];
    9797    fitness_history = [fitness_history, g_fitness];
     
    113113end
    114114
     115g_best
    115116
    116117plot(fitness_iterations,fitness_history);
     
    120121grid on;
    121122legend(sprintf('Parameters %i',parameters));
    122 print('pso-fitness.eps','-depsc2');
     123print(sprintf('pso-fitness-%f.eps', max(fitness_history)),'-depsc2');
Note: See TracChangeset for help on using the changeset viewer.