📄 kolmogorov.m
字号:
% FUNCTION: kolmogorov.m
% DATE: 9th Feb 2005
% AUTHOR: Stephen Faul (stephenf@rennes.ucc.ie)
%
% Function for estimating the Kolmogorov Complexity as per:
% "Easily Calculable Measure for the Complexity of Spatiotemporal Patterns"
% by F Kaspar and HG Schuster, Physical Review A, vol 36, num 2 pg 842
%This function estiamtes the Kolmogorov Complexity of a binary sequence. The algorithm is as described in Lempel and Ziv (IEEE trans inf theory IT-22, 75 (1976)) and Kaspar and Schuster (Physical Review A, vol 36, no 2, pg 842).
%Input is binary sequence, output is kolmogorov complexity
% Input is a digital string, so conversion from signal to a digital stream
% must be carried out a priori
function complexity=kolmogorov(s);
n=length(s);
c=1;
l=1;
i=0;
k=1;
k_max=1;
stop=0;
while stop==0
if s(i+k)~=s(l+k)
if k>k_max
k_max=k;
end
i=i+1;
if i==l
c=c+1;
l=l+k_max;
if l+1>n
stop=1;
else
i=0;
k=1;
k_max=1;
end
else
k=1;
end
else
k=k+1;
if l+k>n
c=c+1;
stop=1;
end
end
end
b=n/log2(n);
% a la Lempel and Ziv (IEEE trans inf theory it-22, 75 (1976),
% h(n)=c(n)/b(n) where c(n) is the kolmogorov complexity
% and h(n) is a normalised measure of complexity.
complexity=c/b;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -