-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiple_simulations.m
52 lines (48 loc) · 1.35 KB
/
multiple_simulations.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
clc, clear
%%
n = 4; % number of genes !!!!!!!!!!!!!!!!!!!!!!
a = 0.3; % random tune param
N = 10^8; % population size
mu = 1.1 *10^-8; % mutation rate
gene_to_fitness = assignFitness(n, a); % maps genotype to fitness value
genotypes = gene_to_fitness.keys(); % string array of genotypes
plotFitnessLandscape(gene_to_fitness, true);
% save("interesting-landscape.mat")
%%
avg_fitness = zeros(n, 1);
mutated_gene_count = zeros(n, 1);
for i = 2:2^n
gene = genotypes(i);
num_mutated = length(find(convertStringsToChars(gene) == '1'));
avg_fitness(num_mutated) = avg_fitness(num_mutated) + gene_to_fitness(gene);
mutated_gene_count(num_mutated) = mutated_gene_count(num_mutated) + 1;
end
avg_fitness = avg_fitness ./ mutated_gene_count;
%%
selective_pressure = 1;
MU = [ 1 5 1000] * 10^-8;
numSimulation = 5;
numGen = 600; % 600
numPlot = 1;
figure
for mu = MU
disp(numPlot)
for i = 1:numSimulation
[fitness, genotype_count_gen] = adaptiveWalk(gene_to_fitness, N, mu, numGen, selective_pressure);
subplot(1, 3, numPlot)
plot([1:numGen], fitness);
title(sprintf("mutation rate %g", mu))
hold on
end
ax = gca;
ax.XGrid = 'on';
ax.YGrid = 'off';
numPlot = numPlot + 1;
end
%%
figure
plot([1:numGen], fitness);
for i = 1:n
hold on
plot(1:numGen, avg_fitness(i)*ones(numGen), 'r')
end