05:00 pm - Evolution is not Pokemon! On Saturday night, I told the story of the fundie who insisted that because the person who posited the possibility of MRI scanners was a creationist, the science behind magnetic resonance imaging must be creationism. I joked that I wanted to do something with evolutionary biology, and call it computing science.
Well, naturally, someone beat me to it:-
function GENETIC ALGORITHM(population, FITNESS-FN) returns an individual
inputs: population, a set of individuals
FITNESS-FN, a function that measures the fitness of an individual
repeat
new_population ← empty set
loop for i from 1 to SIZE(population) do
x ← RANDOM-SELECTION(population, FITNESS-FN)
y ← RANDOM-SELECTION(population, FITNESS-FN)
child ← REPRODUCE(x, y)
if (small random probability) then child ← MUTATE(child)
add child to new_population
population ← new_population
until some individual is fit enough, or enough time has elapsed
return the best individual in population, according to FITNESS-FN
function REPRODUCE(x, y) returns an individual
inputs: x, y, parent individuals
n ← LENGTH(x)
c ← random number from 1 to n
return APPEND(SUBSTRING(x, 1, c), SUBSTRING(y, c+1, n))
Thing o' beauty. I loves it!
(I suppose this theoretically counts as studying, but if anything won't come up in tomorrow's exam, it's genetic algorithms :/ )
|