Changeset 44 for liacs


Ignore:
Timestamp:
Dec 17, 2009, 10:23:16 PM (15 years ago)
Author:
Rick van der Zwet
Message:

Make it cute

Location:
liacs/nc/low-correlation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • liacs/nc/low-correlation/autocorrelation.m

    r43 r44  
    33%-----------------------------------------------------------------------
    44function [f] = autocorrelation(pop)
    5 % Given a population of binary sequences, this function calculates
    6 % the merit function according to the formula specified in the exercise description.
    7 % The input pop is the given matrix.
     5% Given a population of binary sequences, this function calculates the merit
     6% function according to the formula specified in the exercise description.  The
     7% input pop is the given matrix.
    88% The output f is the merit factor calculated (row vector).
    99
     
    1313
    1414% Calculated efficiently in a matrix-notation; auxilary matrices - Y1,Y2 - are
    15 % initialized in every iteration. They are shifted form of the original y vectors.
    16 % The diaganol of the dot-squared Y2*Y1 matrix is exactly the inner sum of merit function.
     15% initialized in every iteration. They are shifted form of the original y
     16% vectors. The diagonal of the dot-squared Y2*Y1 matrix is exactly the inner
     17% sum of merit function.
    1718for k=1:n-1
    1819    Y1=pop(1:n-k,:);
  • liacs/nc/low-correlation/sa.m

    r43 r44  
    22% BSDLicence
    33% Rick van der Zwet - 0433373 - <hvdzwet@liacs.nl>
     4% $Id$
    45
    56function [iteration_history,fitness_history] = sa(seq, stopLimit)
    6     fitness = 0;
    7     temperature = stopLimit;
     7  fitness = 0;
     8  temperature = stopLimit;
    89
    9     iteration_history = [];
    10     fitness_history = [];
     10  iteration_history = [];
     11  fitness_history = [];
    1112
    12     for iteration = 1:stopLimit
    13         % Generate new mutation
    14         newseq = mutation(seq);
     13  for iteration = 1:stopLimit
     14    % Generate new mutation
     15    newseq = mutation(seq);
    1516
    16         new_fitness = autocorrelation(newseq);
     17    new_fitness = autocorrelation(newseq);
    1718
    18         % Better is always accept
    19         if (new_fitness > fitness)
    20             fitness = new_fitness;
    21             % disp(rot90(newseq,-1));
    22             temperature = temperature - 10;
    23         else
    24             % Make the next 'move' less atractive
    25             temperature = temperature + 1;
     19    % Better is always accept
     20    if (new_fitness > fitness)
     21      fitness = new_fitness;
     22      % disp(rot90(newseq,-1));
     23      temperature = temperature - 10;
     24    else
     25      % Make the next 'move' less atractive
     26      temperature = temperature + 1;
    2627
    27             % Accept on an certain probability
    28             if (temperature < 1)
    29                 break;
    30             else
    31                 % XXX: Some more cleaver cooling would be great
    32                 if( exp(1)^((fitness - new_fitness) / temperature) > rand())
    33                     seq = newseq;
    34                end
    35            end
    36         end
    37         iteration_history = [ iteration_history, iteration ];
    38         fitness_history = [ fitness_history, fitness ];
     28      % Accept on an certain probability
     29      if (temperature < 1)
     30        break;
     31      else
     32        % XXX: Some more cleaver cooling would be great
     33        if( exp(1)^((fitness - new_fitness) / temperature) > rand())
     34          seq = newseq;
     35         end
     36       end
    3937    end
     38    iteration_history = [ iteration_history, iteration ];
     39    fitness_history = [ fitness_history, fitness ];
     40  end
    4041end
Note: See TracChangeset for help on using the changeset viewer.