source: liacs/nc/low-correlation/mcs.m@ 45

Last change on this file since 45 was 43, checked in by Rick van der Zwet, 15 years ago

I mean keywords ;-)

  • Property svn:keywords set to Id
File size: 712 bytes
Line 
1% Monte-Carlo Search Algoritm on low-autocorrelation program
2% BSDLicence
3% Rick van der Zwet - 0433373 - <hvdzwet@liacs.nl>
4% $Id: mcs.m 43 2009-12-17 22:18:48Z rick $
5
6% Brute-force result of length 20
7% best_20 = [-1,1,1,-1,-1,-1,1,1,-1,1,-1,-1,-1,1,-1,1,1,1,1,1];
8% autocorrelation(best_20);
9
10function [fitness,value] = mcs(length, iterations)
11 best_fitness = 0;
12 for i = 1:iterations
13 % Generate a random column s={-1,1}^n
14 n = length;
15 s = rand(n,1);
16 s = round(s);
17 s = s - (s == 0);
18
19 % Find whether we are better than everything else
20 fitness = autocorrelation(s);
21 if (fitness > best_fitness)
22 best_value = s;
23 best_fitness = fitness;
24 end
25 end
26 fitness = best_fitness;
27 value = best_value;
28end
Note: See TracBrowser for help on using the repository browser.