Patching CA demo scripts for full Matlab compatibility, including loading initial state of CAs from file (since octave and matlab generate different initial states)

This commit is contained in:
joseph.lizier 2013-09-10 14:37:28 +00:00
parent 28911ef2f4
commit 6cd0e522fa
3 changed files with 68 additions and 8 deletions

View File

@ -0,0 +1,60 @@
% To recreate the plots in:
% chapter 5 of T. Bossomaier, L. Barnett, M. Harré and J.T. Lizier, "An Introduction to Transfer Entropy: Information Flow in Complex Systems", Springer, to be published, 2013.
% These plots were first published in (see DirectedMeasuresChapterDemo2013.m):
% J. T. Lizier, "Measuring the dynamics of information processing on a local scale in time and space",
% accepted for "Directed Information Measures in Neuroscience", edited by M. Wibral, R. Vicente, J. T. Lizier, to be published by Springer, 2013
clear all;
% Set up simulation options:
cells = 10000;
timeSteps = 600;
neighbourhood = 3;
caStates = 2;
% Set up options for information dynamics analysis, and which segment of the CA to plot
measureParams.k=16;
options.saveImages = true;
options.saveImagesFormat = 'pdf';
options.plotOptions.scaleColoursToSubsetOfPlot = true;
scaleColoursToExtremesDefault = false;
options.plotOptions.scaleColoursToExtremes = scaleColoursToExtremesDefault;
% Turn up the contrast so that the small values aren't disproportionately visible: (0.15, 0.30 was good, except for separable which was better with 0.15, 0.35)
options.plotOptions.scalingMainComponent = 0.15;
options.plotOptions.scalingScdryComponent = 0.30;
options.plotOptions.gammaPower = 0.5;
%%%%%%%%%
% Examining rule 54:
options.plotOptions.plotRows = 35;
options.plotOptions.plotCols = 35;
options.plotOptions.plotStartRow = 20+20;
options.plotOptions.plotStartCol = 1+10;
options.seed = 3; % Set up the random number generator to give reproducible initial states for all measurements
if (exist('initialStates/DirectedMeasuresChapterDemo2013-rule54.txt', 'file'))
% A file specifying the initial state exists -- this
% ensures that Matlab and Octave use the same initial state
% (otherwise only Octave recreates the same initial state used in our chapter).
% (You can delete/move the initial state file if you want them generated from scratch.)
options.initialState = load('initialStates/DirectedMeasuresChapterDemo2013-rule54.txt');
end
fprintf('\nStarting rule 54 ...\n');
fprintf('\nPlotting apparent transfer entropy j = 1 ...\n');
% Use the full red scale for transfer and separable info, since we need to see the extreme negative values properly
options.plotOptions.scaleColoursToExtremes = true;
options.plotOptions.scalingScdryComponent = 0.35;
options.plotOptions.scalingMainComponent = 0.35;
measureParams.j = 1;
plotLocalInfoMeasureForCA(neighbourhood, caStates, 54, cells, timeSteps, 'transfer', measureParams, options);
fprintf('\nPress any key when ready for apparent transfer entropy j = -1 ...\n');
pause
options.plotRawCa = false;
measureParams.j = -1;
plotLocalInfoMeasureForCA(neighbourhood, caStates, 54, cells, timeSteps, 'transfer', measureParams, options);
% If we were going to apply this to another rule:
% fprintf('\nPress any key when ready to apply to the next rule\n')
% pause
options.plotOptions.scaleColoursToExtremes = scaleColoursToExtremesDefault; % return to default value
options.plotOptions.scalingScdryComponent = 0.30; % return to previous value

View File

@ -119,7 +119,7 @@ function [caStates, localValues] = plotLocalInfoMeasureForCA(neighbourhood, base
%============================
% Active information storage
if ((ischar(measureId) && (strcmpi('active', measureId) || strcmpi('all', measureId))) || ...
((measureId == 0) || (measureId == -1)))
(not(ischar(measureId)) && ((measureId == 0) || (measureId == -1))))
% Compute active information storage
activeCalc = javaObject('infodynamics.measures.discrete.ActiveInformationCalculator', base, measureParams.k);
activeCalc.initialise();
@ -149,7 +149,7 @@ function [caStates, localValues] = plotLocalInfoMeasureForCA(neighbourhood, base
%============================
% Apparent transfer entropy
if ((ischar(measureId) && (strcmpi('transfer', measureId) || strcmpi('all', measureId) || strcmpi('apparenttransfer', measureId))) || ...
((measureId == 1) || (measureId == -1)))
(not(ischar(measureId)) && ((measureId == 1) || (measureId == -1))))
% Compute apparent transfer entropy
if (measureParams.j == 0)
error('Cannot compute transfer entropy from a cell to itself (setting measureParams.j == 0)');
@ -182,7 +182,7 @@ function [caStates, localValues] = plotLocalInfoMeasureForCA(neighbourhood, base
%============================
% Complete transfer entropy
if ((ischar(measureId) && (strcmpi('transfercomplete', measureId) || strcmpi('completetransfer', measureId) || strcmpi('all', measureId))) || ...
((measureId == 2) || (measureId == -1)))
(not(ischar(measureId)) && ((measureId == 2) || (measureId == -1))))
% Compute complete transfer entropy
if (measureParams.j == 0)
error('Cannot compute transfer entropy from a cell to itself (setting measureParams.j == 0)');
@ -218,7 +218,7 @@ function [caStates, localValues] = plotLocalInfoMeasureForCA(neighbourhood, base
%============================
% Separable information
if ((ischar(measureId) && (strcmpi('separable', measureId) || strcmpi('all', measureId))) || ...
((measureId == 3) || (measureId == -1)))
(not(ischar(measureId)) && ((measureId == 3) || (measureId == -1))))
% Compute separable information
separableCalc = javaObject('infodynamics.measures.discrete.SeparableInfoCalculator', ...
base, measureParams.k, neighbourhood - 1);
@ -251,7 +251,7 @@ function [caStates, localValues] = plotLocalInfoMeasureForCA(neighbourhood, base
%============================
% Entropy
if ((ischar(measureId) && (strcmpi('entropy', measureId) || strcmpi('all', measureId))) || ...
((measureId == 4) || (measureId == -1)))
(not(ischar(measureId)) && ((measureId == 4) || (measureId == -1))))
% Compute entropy
entropyCalc = javaObject('infodynamics.measures.discrete.EntropyCalculator', ...
base);
@ -283,7 +283,7 @@ function [caStates, localValues] = plotLocalInfoMeasureForCA(neighbourhood, base
%============================
% Entropy rate
if ((ischar(measureId) && (strcmpi('entropyrate', measureId) || strcmpi('all', measureId))) || ...
((measureId == 5) || (measureId == -1)))
(not(ischar(measureId)) && ((measureId == 5) || (measureId == -1))))
% Compute entropy rate
entRateCalc = javaObject('infodynamics.measures.discrete.EntropyRateCalculator', base, measureParams.k);
entRateCalc.initialise();
@ -313,7 +313,7 @@ function [caStates, localValues] = plotLocalInfoMeasureForCA(neighbourhood, base
%============================
% Excess entropy
if ((ischar(measureId) && (strcmpi('excess', measureId) || strcmpi('all', measureId))) || ...
((measureId == 6) || (measureId == -1)))
(not(ischar(measureId)) && ((measureId == 6) || (measureId == -1))))
% Compute excess entropy
excessEntropyCalc = javaObject('infodynamics.measures.discrete.PredictiveInformationCalculator', base, measureParams.k);
excessEntropyCalc.initialise();

View File

@ -49,7 +49,7 @@ function [caStates, ruleTable, executedRules] = runCA(neighbourhood, base, rule,
else
% User has supplied the initial state for the CA:
fprintf('User has supplied initial state for CA\n');
if (length(seedOrState) != cells)
if (length(seedOrState) ~= cells)
error('Supplied initial ca state vector [seedOrState] is not of length [cells]');
end
ca = seedOrState;