Hello Walt, you wrote:
*****
I tried to model DWM + NS by mathematically choosing an “ENTITY” as a
string of binary numbers. I allowed the process of change to be random
(with a probability “p” for each digit). I then used a rule of
(0=BAD) and (1=GOOD). I allowed a certain number of “NEW GENERATIONS” in
each step of the program. These were the “DWM”. I then applied “NS” by
selecting the best 50% (by a sum of the
digits (as a figure of NS merit) to continue ---- while extinguishing
the other 50%. Despite this logical extension to preserving the best of
each new generation, the net result has been (so far) to be no
particular improvement in survival. That is very confusing to me and I
surely must be doing something very fundamentally wrong.
Any advice or comments?
*****
Try the following VBA program... It's structured pretty much as
what you've described. The "MutationAndNS()" subroutine is the
main sub to run.
Note that the program initializes all digits in an "organisms
genome" to zero. You can randomize the population at the start.
Changing the "mutation rate" affects the speed with which the
population stabilizes around a particular average as well as the
steady-state "fitness" score.
- Tim Ikeda (email address in transition)
'***** PROGRAM BEGINS *****
'This program starts with a population of 100 "individuals". Each
'"individual" has a genome of 100 "bases". These bases are either
'(0) or (1). The _absolute_ "fitness" of an individual is the
'sum of all its "bases".
'Individuals are ranked according to "fitness". After every
'"generation", only the fittest half of the population is
'propagated. Every "parent genome" gives rise to two "children".
'Every "base" in each child's genome has a chance of mutating.
'The odds of a base changing is set by the MutationFactor variable.
'(a setting of 0.1 means there is a 10% of mutation, 0.01 = 1%).
'Some stats on each "generation" are reported with the "debug.print..."
'command. Output appears in the "Immediate" window when the program is
'run under Microsoft's Visual Basic for Applications (eg. MS Excel,
'Word, Access & etc.)
'Written under MS Excel VBA but should work in almost any dialect
'of Basic. You may have to tweak the random number generator and
'"print" statements. The 'RND' function should return a value
'between (0) and (1).
'Program slapped together in about 15 minutes by T. Ikeda on
'10-JAN-2002, who makes no claims about its accuracy in modelling
'evolutionary processes or whether it even works as described.
Option Explicit
Private Type Individual
Genome(1 To 100) As Integer
Score As Integer
End Type
Dim Population(1 To 100) As Individual
Dim TempValue As Individual
'Run _this_ subroutine.
Sub MutationAndNS()
Dim MutationFactor As Double
Dim MaxGenerationNumber As Integer
Dim GroupFitness As Integer
Dim i As Integer 'a excessive bunch of loop counters.
Dim j As Integer
Dim h As Integer
Dim q As Integer
Dim r As Integer
Dim s As Integer
'Play with these values
'Mutation "rate": Set between (0) and (1).
' a factor of 0.1 = 10% chance of mutation, 0.01 = 1%
MutationFactor = 0.01
'Number of generations to follow.
MaxGenerationNumber = 101
'Initialize population
For i = 1 To 100
With Population(i)
For j = 1 To 100
.Genome(j) = 0
'or start with roughly 50% absolute "fitness"
'.Genome(j) = Int(Rnd + 0.5)
Next j
End With
Next i
'Score the population
ScorePopulation
SortPopulation
h = 1 'initialize loop counter
Do 'loop until exit conditions met
'Reproduce and mutagenize top half of population
'(Individual "q" of the "Population" is reproduced into q and q+50)
For q = 1 To 50
'Temporarily retain parent's genotype for "reproduction"
TempValue = Population(q)
'First "offspring" through mutation...
With Population(q)
For r = 1 To 100
'Determines whether the "base" (r) at any position will
'mutate. How this formula works: If there is a 10% mutation
'rate, then there is a 10% chance of a "0" mutating into a
'"1" and a 90% chance that a "1" will remain a "1".
.Genome(r) = Int(Rnd + Abs(MutationFactor - .Genome(r)))
Next r
End With
'Second "offspring" through mutation
Population(q + 50) = TempValue
With Population(q + 50)
For r = 1 To 100
'Same rules for probability of mutation.
.Genome(r) = Int(Rnd + Abs(MutationFactor - .Genome(r)))
Next r
End With
Next q
'Score the population
ScorePopulation
'Sort the population
SortPopulation
'Calc "average fitness"
GroupFitness = 0
For s = 1 To 100
GroupFitness = GroupFitness + Population(s).Score
Next s
GroupFitness = GroupFitness / 100
'Output info about population:
'How output works depends on the dialect of Basic used.
Debug.Print "Generation:" & h & " Max:" & Population(1).Score & _
" Ave:" & GroupFitness
'or try "Print "Generation: & ..." if this isn't run under VBA...
h = h + 1 'increment loop counter
Loop Until h > MaxGenerationNumber
End Sub
Sub ScorePopulation()
'Goes through each member of the "Population", totals all
'the '1's on the "Genome" and sets the "Score" to the sum.
Dim f As Integer 'local loop index
Dim g As Integer 'another loop index
For f = 1 To 100
With Population(f)
.Score = 0
For g = 1 To 100
.Score = .Score + .Genome(g)
Next g
End With
Next f
End Sub
Sub SortPopulation()
Dim n As Integer 'local loop index
Dim p As Integer 'another loop index
Dim HighScoreIndex As Integer 'holds index of currently "fittest"
Dim CurrentHighScore As Integer 'holds temp high score.
For n = 1 To 100
HighScoreIndex = n
CurrentHighScore = Population(n).Score
For p = n + 1 To 100
If CurrentHighScore < Population(p).Score Then
HighScoreIndex = p
CurrentHighScore = Population(p).Score
End If
Next p
' Swap positions
TempValue = Population(n)
Population(n) = Population(HighScoreIndex)
Population(HighScoreIndex) = TempValue
Next n
End Sub
--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .
This archive was generated by hypermail 2b29 : Thu Jan 10 2002 - 23:39:15 EST