PDA

View Full Version : Evo computer program (partly for Worldtraveller)


IanC
August 1, 2005, 12:23 PM
Hey y'all.

This is kinda in response to something Worldtraveller said:
You could probably do a more accurate model of evolution by starting with 5 decks of cards, and determining a 'fitness' criteria.

For example, with 5 decks, you get 52 hands. Let's assume your fitness criteria is the following:

1) The first card dealt must be at least a 7 (this represents being born with say, a functional cirulatory system).

2) The overall hand must be equal to pair or better. (general fitness criteria)

3) No more than 30 hands can survive.(limited resources)

The 'surviving' hands then get reshuffled and dealt again.

Maybe someone could run a quick computer simulation of this (would this be easy?) and see what happens after a few dozen generations?

I'll have to adapt the system I've just made, but anyway.

Heres the setup, I have begun making a framework for evolutionary simulations, nothing fancy, but I've only been working on it for about an hour.

Heres what it can do so far:
Generate individuals
Generate a population of these
Generate a world with multiple populations
Rate each individual based on fitness, then choose the better ones and recombine them. This is done randomly, so being a fit individual increases your chances of survival, but doesnt make it certain you will pass on your genes.
Mutate some individuals. When recombining the 'DNA' there is a certain chance that it goes wrong and flips the binary digit.
Create a new generation from the last one.
I've also added population drift, to keep diversity.


Im thinking of adding more, namely:
Genetic drift. At the moment, all of the phenotypes (right term?) are the same length, and I want to have a certain chance that they can add or remove part of themselves (random process). Would I be right in saying that this is what genetic drift is?
Example: little guy A is like this [1,0,0,1,0,0,1] (length 7) and he mutates, becoming [1,0,0,1,0,1,0,1] (length 8)


Other than that, Im thinking of adding an ability to create a new population, and new world. Analgous to moving to a different area and becoming a new species respectively.

Thats it really, was wondering if anyone could correct me on what I've covered so far, or give me some guidance on what else I could add, based on known evolutionary principles.

If anyone wants the source code, tis all yours, Ill post it soon. Its written in python, so you need python to run it.

Oh yeah, Worldtraveller - I have run this as it is with a very simple fitness function, where it just adds the numbers together ([1,0,0,1]=2) and it very quickly ends up with a population of very good individuals. Not perfect, but close, and with diversity.

Ian

Worldtraveller
August 1, 2005, 12:27 PM
Cool. I'm pretty sure I can run python code. I'm not a hacker, but my wife is. I would love to play with the fitness criteria and tinker around with it.

Oh goodie...a new toy!! :D

Cheers,
Lane

IanC
August 1, 2005, 12:38 PM
Here ya go:
www.apieceofstring.com/genetic.py

Before you run it...
Sorry if its wrong, and buggers things up. Shouldnt do, Ive been playing with it for quite a while and all is good, but just covering myself here.
Also, since it is a framework, it wont do anything run directly in python. Best to open it in an interpreter (like the included IDLE, if you have python you'll have this).

Once opened in something like IDLE, run like this:
To make a population called p, do this:
>>>p=genpop()
tadaaa!
Its set to make a population of 30, each with a size of 6 (plus the fitness)
You can set it to whatever you want like this:
>>>p=genpop(40,10) for population size 40, individual size 10

then get the next population by doing this
>>>p=nextgen(p)
Ping!
If you want to see what the population looks like, just type the name and hit enter
>>>p

That'll do to play with, you can run it a load of times like this:
for i in range(100):
p=nextgen(p)

erm... cant really think of anything else. You can change the fitness function by playing around with the very top of the file:

def fitness(phen):
return sum(phen)-phen[0]

just change what it returns.

All the rest should be explained in the file, or self-explanatory.


Have fun!

edit- Oh yeah, have any problems, want to know anything, or want anything adding/fixing, just tell me :thumbs:

Ian

jwu
August 1, 2005, 12:46 PM
I'm working on a similar thing myself (in java though), with different regions, species, sexual and asexual reproduction, carnivores and herbivores, migration, different characteristics and lots of easy customizability and exchangeability of parts. Next on my schedule are different seasons.

If you're interested we could cooperate a bit in regards of ideas for algorithms, what works and what doesn't work and so on.

IanC
August 1, 2005, 01:03 PM
Sounds good, jwu. The system you are working on sounds fantastic, I would love to hear more about it.

Im heading at it from a different angle, mainly to produce solutions to problems, rather than simulating evolution on a large scale, but most of the principles are the same. Have you heard of avida (http://dllab.caltech.edu/avida/)?

Ian

jwu
August 1, 2005, 01:19 PM
That's my current UML (without attributes and methods)
http://tinypic.com/9s9lia.jpg

I'm using cascades of strategy patterns for a maximum of flexibility. This way the algorithms can be exchanged even during runtime, which will be especially helpful when i implement seasons - by assigning different selectionmethods to the regions.

Basically the current structure is that a world consists of severall regions and species. Regions have populations, which include all individuals of the same species that live in that region.
Selection is a region dependent thing because different environments may favour different traits, procreation and mutation are species things of course.

IanC
August 1, 2005, 02:46 PM
Ill rewrite the code tomorrow. I meant to make it OO, but wanted to keep adding stuff to it. Ill move it around and hopefully it should be easier to work with.

EDIT - Major error found in the code, I changed something halfway through, and found I'd forgotten to alter one function. Now fixed, with a little speedup
For a population of 50, with a genome length of 10 (fixed), I can do 500 generations in under 2 seconds, which is alright.
Ian