これは進化ゲームのモランプロセスを説明するための基本的なプログラムですが、Matlabに関する知識が限られているため、コードの意味をすばやく理解するのは困難です。誰かがそれが何を意味するのか説明するのを手伝ってもらえますか?
コードを見ると、私が混乱していることがいくつかあります。
state
コード内の 変数は配列ですか?- が配列の場合
state
、それはどういう意味ですかstate(2,:), state(:,2), state(:)
- 機能において
unique
、このステートメントはどういう意味ですか?u(u((1:end-1)')==u((2:end)')) = [];
- 機能において
mnrnd
、このステートメントはどういう意味ですか?r = find(rand < cumsum(p),1);
frequency = histc(state(:,2), livingTypes)./length(state(:,2));
、特にの意味は何histc
ですか?
関数は次のとおりです。
function state = moranprocess(initialState, nSteps, tau)
%# assume 1 step if not specified
if(nargin < 2)
nSteps = 1;
end
%# if it isn't specified, assume frequency indepdence.
if(nargin < 3)
tau = 0;
end
%# initialize with starting state
state = initialState;
%# perform the moran process
for t = 1:nSteps
state(selection(state, 0), :) = state(selection(state, tau), :);
end
end
%# frequency dependent selection with parameter tau determining the
%# strength of selection
function i = selection(state, tau)
%# find all of the living types
livingTypes = unique(state(:,2))';
%# create a multinomial of living type frequencies.
frequency = histc(state(:,2), livingTypes)./length(state(:,2));
%#frequency = makemultinomial(state(:,2));
fitness = (frequency.^tau)./sum(frequency.^tau);
%# selection is proportional to fitnesss
selected_type = livingTypes(mnrnd(1, (frequency.*fitness) ./ sum(frequency.*fitness)));
%# choose randomly among those of the selected type
thoseOfSelectedType = find(state(:,2) == selected_type);
i = thoseOfSelectedType(ceil(length(thoseOfSelectedType)*rand));
end
%# fast unique
function u = unique(x)
u = sort(x(:));
u(u((1:end-1)')==u((2:end)')) = [];
end
%# fast mnrnd
function r = mnrnd(n,p)
r = find(rand < cumsum(p),1);
end