Monday, March 23, 2009
Another Weasel
I know picking on creationists isn't clever or grown-up and posting notes to mock people so confused as to believe that the bible is a biology text book to a blog that has been left vacant for years borders on churlishness but this is just too cool not to contribute to.
As you may creationists having transitioned through cdesign proponentsism have recently evolved changed into Intelligent Design theorists. The unsophisticated of the past "it's all just too complex to have happened without god" have been replaced with sciency-sounding objections like "you can't get that much information by chance" or "you can't get that much complexity by chance". There are even whole labs devoted to proving this headed up by people with PhDs in maths!
It seems the leading lights of this new movement have spend the last several years worrying about a computer program that Richard Dawkins wrote on a a first generation Apple Mac in the 1980s. Dawkins' program is a toy aimed at showing just how powerful selection is as a force when compared to the blind "chance" that creationists often talk about. Dawkins showed that a room full of monkeys bashing keyboards (or a computer randomly choosing letters) would not merely fail to write Shakespeare's complete works in the lifetime of the universe - they'd be hard pressed to hit upon Hamlet's description of a cloud - "Methinks it is like a weasel". On the other hand, altering letters to a random sequence then selecting those most like a target to serve as the template for more rounds of variation and section can get you the phrase in a few minutes.
Ian Musgrave can tell you just how confused the creationists are by this program and provide details of their latest bizarre ideas. But the most interesting bit of all of this was the last line on a post from William Dembski the intellectual leader of the IDers:
In any case, our chief programmer at the Evolutionary Informatics Lab (www.evoinfo.org) is expanding our WEASEL WARE software to model both these possibilities. Stay tuned.
So the ID movement, which is a real and viable scientific objection to mainstream science and should be taught in higshchool and has "information science" labs and everything is working on recreating a program than an ethologist created in BASIC in the 1980s! Just for fun I wrote my own weasel program in python this morning (I was away for the weekend so only caught up with this on my return) which I share with you below. Keep in mind here I am not a real programmer, i have learnt to write a few scripts in BioPython for a research project but my skills are really very lacking. If the "chief programmer at the Evolutionary Informatics Lab" can't do this then what are they doing?
(You should also check out this completely different Pythonic weasel program from Anders Gorm)
*edited to intigrate the locked/unlocked bit Dembski et al have been talking about as an optional argument to make_gen() and add a bit to the comments
# -*- coding: utf-8 -*- # Dawkins' weasel algorithm from /The Blind Watchmaker/ wrought in python import string from random import Random def make_initial(target): '''Make a random string, containing upper and lower case letters and the same length as the target sequence for the run ''' return ''.join(Random().sample(string.letters + ' ', len(target))) def mutate(template, mutationrate): '''Mutate a string at given rate without locking in chars that match the target. The arguments are the template string followed by the probability that each char is changed (there is a ~1/50 mutated character will actually remain the same since the replacement is selected from the same pool of characters) ''' l = list(template) for i in range(len(l)): if Random().random() <= mutationrate: l[i] = Random().sample(string.letters + " ", 1)[0] else: continue return ''.join(l) def mutate_locked(template, mutationrate, target): '''Mutate a string but if any any chars already match the target sequence leave them alone. Arguments are the template string, probability that each char is changed and the target string ''' l = list(template) for i in range(len(l)): if l[i] == target[i]: continue elif Random().random() <= mutationrate: l[i] = Random().sample(string.letters + " ", 1)[0] else: continue return ''.join(l) def make_gen(template, target, popsize, mutationrate, locked = False): '''Makes a new generation from a template string by adding new mutants (from mutate() above) then scores each against the target string and returns WeaselGen instance (defined above) The arguments are the template string to base the new genetation, the target string (to score offspring), the size of the population to make, the rate of mutation at each char and whether or not characters are locked in place once they match the target (a boolean defaulted to false) ''' generation = [] genscores = [] if locked == True: for i in range(int(popsize)): generation.append(mutate_locked(template, mutationrate, target)) elif locked == False : for i in range(int(popsize)): generation.append(mutate(template, mutationrate)) for string in generation: score = 0 for i in range(len(string)): if string[i] == target[i]: score = score + 1 else: continue stringscore = score, string genscores.append(stringscore) return sorted(genscores, reverse = True) target = "Methinks it is like a weasel" survivor = make_initial(target) print "evolving ", target, " from ", survivor generation = 0 fitness = 0 while fitness != len(target): generation = generation + 1 nextgen = make_gen(survivor, target, 100, 0.1, True) fitness, survivor = nextgen[0] print "Generation %i: %s %i matches" % (fitness, survivor, generation) print "Target evolved in", generation, "generations"
Labels: Dawkins, Evoution, mutation, python, sci-blogs, weasel
2 Comments:
With the academic job market being what it is (if every professor has ~ 4 PhD students at a time for 30 years and no one is building new Universities...) cashing in my PhD to be rent-a-sophist for a church group is not a bad career plan at all.