enttim.m

来自「一个利用元胞自动机进行生态仿真的matlab程序」· M 代码 · 共 51 行

M
51
字号
function ah=enttim(X,lns)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% Calculate time-entropy of CA configuration
%
%
%	Fist Coded			5   June  1998
%	Last Modefied		5   June  1998
%
%	Copyright (c)
%	T. Suzudo JAERI-CAIL
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Argument
% X	  : CA Matrix x time
% lns ; state per cell
%
% Variables
%  ah	: average time entropy
%  tn: total number per state
%  nx: x-number of local sites
%  ny: y-number of local sites
%  ps : number of state per patch

% Matrix size
nlx = size(X,1);
nly = size(X,2);
tfin = size(X,3);
if ~(nlx==nly) erorr('ERROR: Rectangle Matrix is not allowed.')
else nl=nlx;
end

sk=[1:2:tfin];
sk1=[2:2:tfin];

tp = fix(size(X,3)/2);

Y=zeros(nl,nl,tp);

% how many states?
% We take 2 patchs, so
ps = lns^2;

% Calculate the probability
Y = X(:,:,sk) + 2*X(:,:,sk1);
h = zeros(nl);
for ii=0:ps-1
	tn = sum(~(Y-ii),3);
	h = h - (tn/tp).*log(max(tn/tp,0.001))/log(ps);
end
ah=mean(mean(h));

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?