[Tutor] migration simulation
Joshua Pollack
j.pollack@m.cc.utah.edu
Fri Dec 13 23:04:01 2002
This is a multi-part message in MIME format.
--Boundary_(ID_iur2IoBeA0oaJNJIFtY31Q)
Content-type: text/plain; charset=us-ascii; format=flowed
Content-transfer-encoding: 7BIT
I
Hi all,
There's been some talk of simulation stuff using python lately, and I
thought I'd pose a question I had. I'm super new to python and
programming general
so this isn't particularly noteworthy but...
I've a migration simulation that's part of a bigger drift and selection
model. In the migration section, I define a population as being made of
subpopulations and then pop out migrants from the subpops at a given
probability. The migrants then get re-inserted into subpops randomly.
It's all very simple except I'm having a problem with back migration.
Migrants will sometimes migrate back to their original population.
Does anyone know of a
a way to tag each migrant so that I can make sure they don't
back-migrate? See attached code.
Thanks so much!!
Joshua Pollack
P.S. -f this gets sent twice, please ignore message #2. Thanks again.
--Boundary_(ID_iur2IoBeA0oaJNJIFtY31Q)
Content-type: text/plain; name=migrate.py
Content-transfer-encoding: 7BIT
Content-disposition: inline; filename=migrate.py
## Migration Simulation
import random
## Create subpopulations
sf=[0]*5+[1]*5
la=[2]*5+[3]*5
biloxi=[4]*5+[5]*5
migrants=[]
## Join subpops into single pop
all=[sf,la,biloxi]
print "pre-migrate:", all
## Pull out migrants at a probability of 5%
for i in all:
for j in i:
if random.random()<=.05:
migrants.append(i.pop(j))
## Drop migrants back into random subpopulations
for i in migrants:
random.choice(all).append(i)
print "post-migrate:", all
--Boundary_(ID_iur2IoBeA0oaJNJIFtY31Q)--