-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevolve.m
41 lines (35 loc) · 1.01 KB
/
evolve.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
function pop = evolve(pop,nSteps)
% Run a population through a specified number of iterations of the discrete replicator
% dynamics
%
% USAGE:
%
% updatedPopulation = evolve(population, numberOfTimeSteps)
%
% INPUTS:
% population: structure containing the population
% numberOfTimeSteps: for how many iterations the dynamics is run
%
% OUTPUTS:
% updatedPopulation: the input population with updated 'densities'
% the previous densities are stored in a field 'history'
% where each column is a time step
% check for payoff matrix
if ~isfield(pop,'payoffMatrix')
pop = createPayoffMatrix(pop);
end
payoffMatrix = pop.payoffMatrix;
densities = pop.densities;
history = [];
for step=1:nSteps
avgPayoffInd = payoffMatrix*densities;
avgPayoffPop = densities'*avgPayoffInd;
history = [history densities];
densities = times(densities,avgPayoffInd)/avgPayoffPop;
end
if ~isfield(pop, 'history')
pop.history = history;
else
pop.history = [pop.history history];
end
pop.densities = densities;