Psychic bug

Raymond Hettinger python at rcn.com
Thu Feb 23 07:19:08 EST 2006


>  a mutate function for a genetic algorithm which is giving me
> odd results. I suspect I'm missing somthing really simple, so I'd be
> grateful for any suggestions. Basically, when I comment out the line
> which is commented out below, it works fine (although of course it
> doesn't change the genome). When I uncomment it gen[letter]
> automagically gets the value base in the print statements, before the
> assignment has been made. And it still doesn't update the genome.

The code looks fine to me and your description suggests that the
problem lies elsewhere -- the genome instance is getting updated
but the tool to look at it is working on an unmutated copy.

When you see the "automagic" value assignment appearing before
the assignment is even made, it is a cue that the assignment got
made on a previous run and was esssentially already done when
the function was called a second time.

An easy way to see this in action is to add print statements to the
beginning and end of the mutate function:

    print self.genome[:70]

So, I think the error is likely in the calling code and not in the
mutate function.


Raymond




More information about the Python-list mailing list