Changeset 31 for liacs/nc/low-correlation
- Timestamp:
- Dec 13, 2009, 4:55:02 PM (15 years ago)
- Location:
- liacs/nc/low-correlation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
liacs/nc/low-correlation/Makefile
r29 r31 2 2 CFLAGS=-lm 3 3 4 mcs .out: mcs.m5 @octave - qmcs.m4 mcs: mcs.m 5 @octave --silent mcs.m -
liacs/nc/low-correlation/mcs.m
r30 r31 7 7 % autocorrelation(best_20); 8 8 9 function [fitness,value] = mcs(length, iterations) 10 best_fitness = 0; 11 for i = 1:iterations 12 % Generate a random column s={-1,1}^n 13 n = length; 14 s = rand(n,1); 15 s = round(s); 16 s = s - (s == 0); 17 18 % Find whether we are better than everything else 19 fitness = autocorrelation(s); 20 if (fitness > best_fitness) 21 best_value = s; 22 best_fitness = fitness; 23 endif 24 endfor 25 fitness = best_fitness; 26 value = best_value; 27 endfunction 9 28 10 best_fitness = 0; 11 while (1) 12 % Generate a random column s={-1,1}^n 13 n = 20; 14 s = rand(n,1); 15 s = round(s); 16 s = s - (s == 0); 29 % Basic variables 30 iterations = [1:10:200]; 31 repetitions = 20; 32 length = 20; 17 33 18 % Find whether we are better than everything else 19 fitness = autocorrelation(s); 20 if (fitness > best_fitness) 21 best_result = s; 22 best_fitness = fitness 34 35 % Plot the stuff 36 fitnesses = []; 37 for iteration = iterations 38 fitness = []; 39 for rep = 1:repetitions 40 printf('Iter:%i, Rep:%i\n',iteration,rep); 41 [new_fitness, value] = mcs(length,iteration); 42 fitness = [fitness, new_fitness]; 43 23 44 % Little hack to display output nicely 24 disp(rot90(best_result,-1)); 25 endif 26 endwhile 45 % disp(rot90(value,-1)); 46 endfor 47 48 fitnesses = [fitnesses,mean(fitness)]; 49 endfor 27 50 51 plot(iterations,fitnesses); 52 title(sprintf('Monte-Carlo Search on Low-Corretation set - repetitions %i',repetitions)); 53 ylabel('fitness'); 54 xlabel('iterations'); 55 grid on; 56 legend(sprintf('Length %i',length)); 57 print("mcs-fitness.eps","-depsc2"); 58
Note:
See TracChangeset
for help on using the changeset viewer.