- Timestamp:
- Dec 17, 2009, 10:23:16 PM (15 years ago)
- Location:
- liacs/nc/low-correlation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
liacs/nc/low-correlation/autocorrelation.m
r43 r44 3 3 %----------------------------------------------------------------------- 4 4 function [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 % Theinput 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. 8 8 % The output f is the merit factor calculated (row vector). 9 9 … … 13 13 14 14 % 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. 17 18 for k=1:n-1 18 19 Y1=pop(1:n-k,:); -
liacs/nc/low-correlation/sa.m
r43 r44 2 2 % BSDLicence 3 3 % Rick van der Zwet - 0433373 - <hvdzwet@liacs.nl> 4 % $Id$ 4 5 5 6 function [iteration_history,fitness_history] = sa(seq, stopLimit) 6 7 7 fitness = 0; 8 temperature = stopLimit; 8 9 9 10 10 iteration_history = []; 11 fitness_history = []; 11 12 12 13 14 13 for iteration = 1:stopLimit 14 % Generate new mutation 15 newseq = mutation(seq); 15 16 16 17 new_fitness = autocorrelation(newseq); 17 18 18 19 20 21 22 23 24 25 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; 26 27 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 39 37 end 38 iteration_history = [ iteration_history, iteration ]; 39 fitness_history = [ fitness_history, fitness ]; 40 end 40 41 end
Note:
See TracChangeset
for help on using the changeset viewer.