Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -0,0 +1,27 @@
|
|||
function evolve(parent,target,mutation_rate,num_children)
|
||||
println("Initial parent is $parent, its fitness is $(fitness(parent,target))")
|
||||
gens=0
|
||||
while parent!=target
|
||||
children=[mutate(parent,mutation_rate) for i=1:num_children]
|
||||
bestfit,best=findmax(map(child->fitness(child,target),children))
|
||||
parent=children[best]
|
||||
gens+=1
|
||||
if gens%10==0
|
||||
println("After $gens generations, the new parent is $parent and its fitness is $(fitness(parent,target))")
|
||||
end
|
||||
end
|
||||
println("After $gens generations, the parent evolved into the target $target")
|
||||
end
|
||||
|
||||
fitness(s1,s2)=count(x->x,convert(Array{Char,1},s1).==convert(Array{Char,1},s2))
|
||||
|
||||
function mutate(s,rate)
|
||||
new_s=""
|
||||
for c in s
|
||||
new_s*=string(rand()<rate?
|
||||
" ABCDEFGHIJKLMNOPQRSTUVWXYZ"[rand(1:27)]:c)
|
||||
end
|
||||
return new_s
|
||||
end
|
||||
|
||||
evolve("IU RFSGJABGOLYWF XSMFXNIABKT","METHINKS IT IS LIKE A WEASEL",0.08998,100)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
Initial parent is IU RFSGJABGOLYWF XSMFXNIABKT, its fitness is 1
|
||||
After 10 generations, the new parent is M TBINGJ IGOYSYV KIAM WIAXEL and its fitness is 13
|
||||
After 20 generations, the new parent is MRTBINKJ IT SYO KT Z WEAIEL and its fitness is 18
|
||||
After 30 generations, the new parent is MGTHINKJ IT ISYLMKJ A WEASEL and its fitness is 23
|
||||
After 40 generations, the new parent is MBTHINKS IT ISYLIKE A WEASEL and its fitness is 26
|
||||
After 49 generations, the parent evolved into the target METHINKS IT IS LIKE A WEASEL
|
||||
Loading…
Add table
Add a link
Reference in a new issue