Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -2,27 +2,26 @@ global target;
|
|||
target = split("METHINKS IT IS LIKE A WEASEL", "");
|
||||
charset = ["A":"Z", " "];
|
||||
p = ones(length(charset), 1) ./ length(charset);
|
||||
parent = discrete_rnd(length(target), charset, p)';
|
||||
mutaterate = 0.01;
|
||||
parent = discrete_rnd(charset, p, length(target), 1);
|
||||
mutaterate = 0.1;
|
||||
|
||||
C = 100;
|
||||
C = 1000;
|
||||
|
||||
function r = fitness(parent, thetarget)
|
||||
r = sum(parent == thetarget) ./ length(thetarget);
|
||||
function r = fitness(parent, target)
|
||||
r = sum(parent == target) ./ length(target);
|
||||
endfunction
|
||||
|
||||
function r = mutate(parent, therate, charset)
|
||||
function r = mutate(parent, mutaterate, charset)
|
||||
r = parent;
|
||||
p = unifrnd(0, 1, length(parent), 1);
|
||||
nmutants = sum( p < therate );
|
||||
nmutants = sum( p < mutaterate );
|
||||
if (nmutants)
|
||||
s = discrete_rnd(nmutants, charset, ones(length(charset), 1) ./ length(charset))';
|
||||
r( p < therate ) = s;
|
||||
s = discrete_rnd(charset, ones(length(charset), 1) ./ length(charset),nmutants,1);
|
||||
r( p < mutaterate ) = s;
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function r = evolve(parent, mutatefunc, fitnessfunc, C, mutaterate, \
|
||||
charset)
|
||||
function r = evolve(parent, mutatefunc, fitnessfunc, C, mutaterate, charset)
|
||||
global target;
|
||||
children = [];
|
||||
for i = 1:C
|
||||
|
|
@ -42,10 +41,11 @@ function printgen(p, t, i)
|
|||
endfunction
|
||||
|
||||
i = 0;
|
||||
|
||||
while( !all(parent == target) )
|
||||
i++;
|
||||
parent = evolve(parent, @mutate, @fitness, C, mutaterate, charset);
|
||||
if ( mod(i, 20) == 0 )
|
||||
if ( mod(i, 1) == 0 )
|
||||
printgen(parent, target, i);
|
||||
endif
|
||||
endwhile
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue