Reputation: 7773
I have a set of n
genomes, and n
corresponding fitness values. I would like to sample the genomes with replacement according to their proportional fitness values, such that P(genome) = fitness(genome) / sum(fitness(genomes))
. Is there a built-in mechanism for sampling like this in Matlab?
Upvotes: 0
Views: 696
Reputation: 6569
You can use randsample
for this purpose:
>> f = [2 5 7 8 1]; %# fitness values (not normalized)
>> g = {'g1', 'g2', 'g3', 'g4', 'g5'}; %# genome names
>> gSampled = randsample(g,100,true,f) %# sample 100 genomes with replacement
Upvotes: 0
Reputation: 47392
If you wanted to get 10 samples from a population of 4 whose fitnesses are 0.4, 0.3, 0.2 and 0.1 respectively, then you can do:
>> fitness = [0.4 0.3 0.2 0.1];
>> mnrnd(10,fitness)
ans =
3 5 1 1
Upvotes: 1
Reputation: 2578
Matlab has built in multinomial random number generator. You can use mnrnd
for your purpose.
Upvotes: 0