from CAentropy.m by ehsan tahami
Computes the entropy for Cellular Automata

[entropy]=CAentropy(pattern)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CAentropy.m
% Ehsan Tahami
% September 2013
% Email:etahami@gmail.com
% http://tahami.mshdiau.ac.ir

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CAentropy computes the entropy of CA(Cellular Automata) zero-one pattern
% matrix. For some information about the mathematical basis of CAentropy see:
% http://demonstrations.wolfram.com/CellularAutomataEntropy/

function [entropy]=CAentropy(pattern) % Pattern is the zero-one matrix of CA

global m n r1 c1 

[m,n]=size(pattern); 
Total=m*n;  % m is the number of steps for CA (Rows of pattern matrix) 
            % n is the number of CA Cells(columns of pattern matrix) 

A=find(pattern==1); 
[r1,c1]=size(A);% Number of ones in the pattern matrix

B=Total-r1;% Number of zeros in the pattern matrix

P_A=r1/Total; % Comput the probability of ones in the CA pattern
P_B=B/Total; % Comput the probability of zeros in the CA pattern

entropy=-(r1*P_A*log(P_A)/log(2))-(B*P_B*log(P_B)/log(2));


Contact us