Richard Dawkins’s computer simulation algorithm explores how long it takes a 28-letter-long phrase to evolve to become the phrase “Methinks it is like a weasel”. The Weasel program has a single example of the phrase which produces a number of offspring, with each letter subject to mutation, where there are 27 possible letters, the 26 letters A-Z and a space. The offspring that is closest to that target replaces the single parent. The purpose of the program is to show that creationist orators who argue that evolutionary biology explains adaptations by “chance” are misleading their audiences. Pure random mutation without any selection would lead to a random sequence of 28-letter phrases. There are possible 28-letter phrases, so it should take about different phrases before we found the target. That is without arranging that the phrase that replaces the parent is the one closest to the target. Once that highly nonrandom condition is imposed, the number of generations to success drops dramatically, from to mere thousands.

Although Dawkins’s Weasel algorithm is a dramatic success at making clear the difference between pure “chance” and selection, it differs from standard evolutionary models. It has only one haploid adult in each generation, and since the offspring that is most fit is always chosen, the strength of selection is in effect infinite. How does this compare to the standard Wright-Fisher model of theoretical population genetics?

The Wright-Fisher model, developed 85 years ago, independently, by two founders of theoretical population genetics, is somewhat similar. But it has an infinite number of newborns, precisely of whom survive to adulthood. In its simplest form, with asexual haploids, the adult survivors each produce an infinitely large, but equal, number of offspring. In that infinitely large offspring population, mutations occur exactly in the expected frequencies. Each genotype has a fitness, and the proportions of the genotypes change according to them, exactly as expected. Since there are an infinite number of offspring, there is no genetic drift at that stage. Then finally a random sample of of the survivors is chosen to become the adults of this new generation.

In one case we get fairly close to the Weasel. That is when , so that there is only one adult individual. Now for some theory, part of which I explained before, in a comment here. We first assume that a match of one letter to the target multiplies the fitness by a factor of , and that this holds no matter how many other letters match. This is the fitness scheme in the genetic algorithm program by keiths. A phrase that has matches to the target has fitness . We also assume that mutation occurs independently in each letter of each offspring with probability , and produces one of the other 26 possibilities, chosen uniformly at random. This too is what happens in keiths’s program. If a letter matches the target, there is a probability that it will cease to match after mutation. If it does not match, there is a probability that it will match after mutation.

The interesting property of these assumptions is that, in the Wright-Fisher model with , *each site evolves independently* because neither its mutational process nor its selection coefficients depend on the the state of the other sites. So we can simply ask about the evolution of one site.

If the site matches, after mutation of the offspring will still match, and of them will not. Selection results in a ratio of of matching to nonmatching letters. Dividing by the sum of these, the probability of ending up with a nonmatch is then divided by the sum, or

Similarly if a letter does not match, after mutation the ratio of nonmatches to matches is . After selection the ratio is . Dividing by the sum of these, the probability of ending up with a match is

Thus, what we see at one position in the 28-letter phrase is that if it is not matched, it has probability of changing to a match, and if it is matched, it has probability of changing to not being matched. This is a simple 2-state Markov process. I’m going to leave out the further analysis — I can explain any point in the comments. Suffice it to say that

1. The probability, in the long run, of a position matching is .

2. This is independent in each of the 28 positions. So the number of matches will, in the long run, be a Binomial variate with 28 trials each with probability .

3. The “relaxation time” of this system, the number of generations to approach the long-term equilibrium, will be roughly .

4. At what value of do we expect selection to overcome genetic drift? There is no value where drift does not occur, but we can roughly say that when the equilibrium frequency is twice as great as the no-selection value of 1/27, that selection is then having a noticeable effect. The equation for this value is a quadratic equation in whose coefficients involve as well. If is much smaller than , then this value of is close to 0.44.

5. The probability of a match at a particular position, one which started out not matching, will be after generations

and the probability of a nonmatch given that one started out matching is

I don’t have the energy to see whether the runs of keiths’s program verify this, but I hope others will.

Tom EnglishI get mean 13.40 and s.d. 2.19.

Mean 12.84 and s.d. 2.25. The entire plot is not very interesting — I’m just dumping in all of the data at present, meaning that there are 10 + 20 = 30 curves — so I’m going with just the early generations. If you look closely, you can distinguish the “heavier” group of 20 parents in the second run from the group of 10 parents in the first run.

Number of parents: 10

************************************************************************

Number of sites L : 28

Number of possible alleles A : 27

Number of parents : 10

Number of offspring per parent : 500

Mutation rate u : 0.01

Selection parameter s : 0.3

p = u * (1 + s) / (A-1 + u * s) : 0.000499942314348

q = u / (1 + s * (1 – u)) : 0.0077101002313

Assume equilibrium at generation: 10000

W-F probability of fit allele at site P = p/(p+q) : 0.0608939979992

Expected num. of fit alleles in parent L*P : 1.70503194398

Mean observed num. of fit alleles in parent : 14.6011827261

Expected std. dev. of observed nums. of fit alleles: 1.26538758181

Std. dev. of observed numbers of fit alleles : 2.19382371378

************************************************************************

Number of parents: 20

************************************************************************

Number of sites L : 28

Number of possible alleles A : 27

Number of parents : 20

Number of offspring per parent : 250

Mutation rate u : 0.005

Selection parameter s : 0.15

p = u * (1 + s) / (A-1 + u * s) : 0.0002211474669

q = u / (1 + s * (1 – u)) : 0.00435066347618

Assume equilibrium at generation: 10000

W-F probability of fit allele at site P = p/(p+q) : 0.0483719623697

Expected num. of fit alleles in parent L*P : 1.35441494635

Mean observed num. of fit alleles in parent : 15.1601330201

Expected std. dev. of observed nums. of fit alleles: 1.13529698209

Std. dev. of observed numbers of fit alleles : 2.24921122137

************************************************************************

CPU times: user 23min 37s, sys: 7.93 s, total: 23min 45s

Wall time: 23min 50s

keithsTom:

Sorry, Tom, but with those parameters the fitnesses would range from 1 to 10,001^10,000, which is far beyond the range of the double-precision fitness variable I use.

Augmenting the precision doesn’t seem worth it to me.

keithskeiths:

Tom:

keiths:

Tom:

Pretty good agreement.

Tom EnglishSeparate figures now for min-mean-max of two runs. My quick-and-dirty code “likes” to process offspring in big batches, not split into 200 little fragments.

Mean 11.13 and s.d. 2.04 for the last 900,000 of 1,000,000 generations.

Mean and s.d. 2.04.

Number of parents: 100

************************************************************************

Number of sites L : 28

Number of possible alleles A : 27

Number of parents : 100

Number of offspring per parent : 50

Mutation rate u : 0.01

Selection parameter s : 0.1

Assume equilibrium at generation: 10000

Mean observed num. of fit alleles in parent : 16.86679268

Std. dev. of observed numbers of fit alleles : 2.04897128063

************************************************************************

Number of parents: 200

************************************************************************

Number of sites L : 28

Number of possible alleles A : 27

Number of parents : 200

Number of offspring per parent : 25

Mutation rate u : 0.005

Selection parameter s : 0.05

Assume equilibrium at generation: 10000

Mean observed num. of fit alleles in parent : 16.9037339205

Std. dev. of observed numbers of fit alleles : 2.03701360181

************************************************************************

CPU times: user 2h 24min 32s, sys: 1min 11s, total: 2h 25min 44s

Wall time: 2h 26min 11s

Tom EnglishInteresting that the population mean seems less variable here.

Tom EnglishI’ve wondered all along just what it is that you value. I’d genuinely like to know.

keithsTom,

I answered that already:

It also validates, and is validated by, the predictions of Joe’s Wright-Fisher model.

MungWhy look any further?

Tom EnglishJoe Felsenstein,

Would you please, now that the Weaseling has died down, recommend one of the many simulations, available on the Web, of the Wright-Fisher model? Or perhaps you would like to share one of your own implementations. (I suspect that you’ve done various of them over the decades, and also that you’ve made assignments of them in your teaching.)

In 2016, one needs a compelling reason

notto run computational experiments within an interactive environment. Have you, in planning future development of PHYLIP, had a look at Jupyter (the offshoot of IPython)? The project recently obtained over $6 million in funding.Joe FelsensteinPost authorMung may have forgotten what the purpose of this thread was: it was to use the Wright-Fisher model to get a good sense of what the effect of moderate amounts of selection is, and what the effect of different numbers of surviving adults is. So we of course need to look further than , and further than having infinitely strong selection.

Joe FelsensteinPost authorTom English,I presume you mean multi-locus selection simulations. For a single-locus program using the Wright-Fisher model to simulate natural selection, migration, and mutation, and genetic drift, the interactive program PopG, distributed by our lab here should be good.

Don’t have time to write using a new language. I have a two-page multilocus selection program, one I used to show a creationist troll that his assertions were wrong. I could post that here and then you all could put a better interface on it.

Joe FelsensteinPost authorLet me qualify what I just said. If you had some number of loci, say 10 of them, and they were not linked, so that there was free recombination between them, and if the fitness scheme was multiplicative, so that the fitness of a genotype that had favorable alleles was , then each at each locus the gene frequency would change essentially indepndently.

So a single-locus simulation program like PopG will show what happens. 10 loci would act essentialy the same as 10 independent runs of PopG, or one run of 10 independent populations. There doesn’t seem to be much point in posting a 10-locus program.

Tom EnglishYes, I do. Some days back, I Googled Wright-Fisher model simulation, and got about 456,000 results. I decided not to wade through what was available, and instead to demonstrate just how little is required to do the the particular job at hand. (OK, I did just sample what’s out there, and found that I can’t tell for sure what would have worked for us.)

I’ve always worked on guts, not skin. I’m interested now in learning some leading-edge techniques for presentation online. That’s bound to take some time.

Joe FelsensteinPost authorI looked at the first page of the Google search. Some of the papers were about teaching programs — one was an assignment to a class asking them to write the program. There was an interesting (if flawed) paper on simulating conditioned WF processes.

All were one-locus programs.

I am not sure whether you are asking me to post my multilocus program, or to let you write your own. I will post it (in a comment a few minutes from now) so as to let anyone who wants to play with it do so. As I indicated, the results will be little different from what you would get running

`PopG`

once for each locus.Joe FelsensteinPost authorDelayes in posting a multilocus program. I found the one that I had and discovered that it was both (a) a modification of a program someone else had sent me, and (b) didn’t really do selection for favorable alleles at all loci.

I will think about doing a completely new version. But for now folks should use PopG for one locus at a time.

keithsTom:

Ah,

nowI’m beginning to see why Tom is so grumpy regarding the modified Weasel, and what’s behind comments like this:He’s got a bad case of Weasel envy. 🙂

P.S. No one said it was difficult, Tom. I’m sure you could do a fine full-featured Weasel, long and furry.

Tom EnglishI’ve got something else I’d rather address right now. When you first contacted me, way back when, I was working on a response to a Weasely paper by a Templeton Foundation grant recipient:

David H. Glass, University of Ulster, “Parameter Dependence in Cumulative Selection,” 2014.

His Templeton project was “Explaining and Explaining Away.”

You’ve set things up beautifully with this post. Glass claims that there’s biological relevance in his study. I think you’ll want to say a thing or two about that. It’s a very brief paper. I’m about to start an OP.

I’d love to have keiths join in, but he’s pretty busy with real work, keeping the likes of kairosfocus and Mung in check.

Joe FelsensteinPost authorHmm. Northern Ireland does seem to be an epicenter of creationism.

Glass seems surprised that if you have half as much mutation, it can take twice as long to reach the target.

Will await your OP.

MungIt’s that insidious plot to force his children to hear about intelligent design in science classes. It’s becoming more and more likely to become a reality as each day passes.

Can you just imagine the damage if they taught Weasel Testing in CS courses?

keithsTom,

Responding to Glass might require us to “whack our Weasels in public”, as you put it. Are you up for that?

Glass’s misconceptions have a lot in common with those of KF, Mung, and Sal. His concern with a separate “CCM” (correct character mutation rate) mirrors KF’s “latching” obsession. And like Mung and Sal, he wants to overstate the problem that drift presents to selection.

Joe FelsensteinPost authorThe equations that I gave, above, allow there to be a separate Correct Character Mutation rate. Just replace the mutation rate from Match to Not, by that rate. The alphabet size only comes into my math in that term.

Joe FelsensteinPost authorIt is evident from Glass’s paper that there is a lack of teaching of population genetics in the science courses he took.

Joe FelsensteinPost authorWoops. Reverse that. Make it: Replace the mutation rate from Nonmatch to Match, , …

Tom EnglishNot really. I’m very lazy in documenting code that I plan to use only once. And I don’t keep notes. I find now that I wrote, 16 months ago, an alternative main program that tests the routines I’m using. So I have to figure out what the testing actually was, before I can decide whether I’m actually satisfied with it.

I did leave myself one interesting note, and it’s one that you might want to ponder. The speedup is relative to a “slow_mutate” routine that is much faster than what you’re doing. By the way, you need to get rid of your sort, if you haven’t done so already.

keithsTom,

There are lots of things I would have changed if my goal were to minimize execution time, but given that my program typically reaches equilibrium in a matter of seconds, I haven’t seen the need.

I left that code there in case I later wanted to implement a pure Weasel option where the fittest offspring was always selected. I’ve since decided that it’s better to maintain separate versions — a pure Weasel and a modified drift/selection Weasel.

Tom EnglishThe

comes early in sophomore-level courses on data structures. Should you take the radical leap to C++, you’ll have access to standard algorithms for heap manipulation. It’s really no harder to do selection right than to make excuses for doing it wrong — unless you’ve invested a lot of ego in what you’ve done wrong.heapI’ve always seen the need, because I see the Weasel as a special (very limited) case of evolutionary computation, not evolutionary computation as a generalization of the Weasel. I see pitfalls galore in seeing things the latter way. I’ll of course let Joe speak to analogous concerns, if any, about theoretical evolutionary genetics.

I’ve previously had the need for arbitrary-precision calculations in evolutionary computation, and I saw immediately the need for them in a simulation with multiplicative fitness. An “obvious” (only after reading Joe’s post) response to Glass is to redo his study with multiplicative fitness contributions. So what do you think now about calculating for largish ?

keithsWow. You actually

areexperiencing Weasel envy!Don’t worry, Tom — we still think you’re smart, even if your program hasn’t been getting the attention you would have liked.

Tom EnglishNo one who could read my program would make much of it. It dawns on me only now that you’re someone who can’t read my program. I’m actually a bit on the slow side, don’t you think?

You’ve derided Mung for not understanding C, and now you play games with me, when you actually don’t understand my code?

Perhaps you should tell us what languages you can handle.

MungAn interesting open question is the extent to which more traditional programming languages are evolution friendly. As one might expect, languages like C and Java are much better suited for humans than evolution.– Kenneth De Jong

keithsThat’s pitiful, Tom.

You aren’t the only competent programmer around here, and you’ll need to come to grips with that fact, like it or not.

Mungkeiths admits Tom is a competent programmer.

Meanwhile … in case keiths wants to come out of the dark ages…

Seven Languages in Seven Weeks

keithsMung,

Of course I do. I’m not threatened by Tom’s competence.

It’s sad that he seems to be threatened by mine.

Alan FoxCan I just remind folks that Noyau is available for those wishing to step outside the rules perimeter.

keithsAlan,

“That’s pitiful, Tom” is not a violation of the rules, and in any case your intervention is neither needed nor required.

Alan FoxDidn’t say it was, Keiths. Stay within the rules and there’ll be no need for me to intervene.

MungPitiful is allowed. Pathetic is not allowed.

Utterly lamentable.

Alan FoxMung, I’ll respond in “moderation issues”.ETA link

MungPoking around online a bit today.

Genetic Drift

Simulating Genetic Drift

Sorry to disappoint all those folks who thinks I ought to be writing yet another Weasel program just because “I just might learn something.”

Joe FelsensteinPost authorOne might think that Mung is proposing a bet. Does Mung envisage betting on how much cumulative selection occurs in a run of Dawkins’s Weasel simulation? Perhaps this time there will be a clear bet proposed.

My own view is that it is worth no one’s money to ask whether the Weasel simulates cumulative selection. It just does. Does someone here say it doesn’t? maybe Mung?

keithsMung,

Here’s a “quantitative measure of cumulative selection” that is similar to the one that Joe proposed:

1. Run my basic Weasel

ntimes using a set of parameters chosen to give a reasonable convergence time. Record the number of generations it takes to reach the target phrase each time, and take the average.2. Repeat the process using the same parameters but with selection turned off.

Compare the results.

Having been spanked again and again by the Weasel, are you willing to bet against it, Mung?

OMagainMung,

I don’t read your posts so if you are serious then someone else will have to pass on your message.

I’m happy to apply my usual rate card. When you specify the project in sufficient detail so a proper estimate can be made be sure to find a way to let me know.

However, there will be no

mates ratesfor you!