shiv wrote:samuel wrote: The more someone scores, the better their fitness, for example.

S

In fact this is exactly what I wanted to do - but the coding for that is still experimental. I was attempting to reduce (or increase) the population of any group by a percentage that reflects the amount by which they have scored less (or more) than the opposing group. That would give the "population" of the second generation. This would then have to go through one more iteration of the existing program to create a third generation with new population figures and so on.

The tools you need are to a) renormalize and b) sample from a distribution.

Allow me to illustrate. Let us say you have a scoring rule within a loop:

if (condition)

score[0] = score[0]+1

else

score[1] = score[1]+1

etc.

Each index in the score array (a vector) is a score that said species got. A species would be mullah=0, dhimmi=1, etc. You could even have a two dimensional array score[0,0], score[0,1]...score[0,k], representing here the the k-traits that a mullah (species 0) can have. Its scoring looks just like the one-dimensional table, just more rules. So at the end of a few epochs (trials), you will have score table or vector.

Then you must renormalize:

- sum up all the values in score.

- divide each element by the sum.

call the renormalized score pscore.

Then you must resample the population from pscore.

To resample, you can use the CDF method or the Hit-miss method, they are the easiest.

The CDF method, useful for vectors, goes like this:

generate a cumulative distribution:

cum[0] = pscore[0];

for i =1:number of species

cum[i] = pscore[i]+cum[i]

end

cum[number of species] = 1 - it is the cumulative sum.

Then, pick a random number between 0 and 1, inclusive.

Find the closest value in cum array to it. use the index of that value as your sample.

Add species sample to population.

Repeat until the population is N (which remains constant between epochs).

in the hit and miss method, which is most useful for higher dimensional arrays, you do this:

sample three numbers from the uniform distribution.

scale the first two numbers, call them m and n, to be between 0 and number of species and 0 and k (number of traits) respectively.

leave the third one between 0 and 1 (assuming you are working with pscore).

if score(m,n) <=pscore(m,n) select species m with trait n else reject.

Do this N times to maintain a population of N, each epoch.

An epoch is a few trials (of the loop), say 100. Otherwise you resample too quickly.

Hope that helps,

S