Skip to content

Commit

Permalink
Fixed demo of Kraskov TE on Schreiber heart-breath data to use new Kr…
Browse files Browse the repository at this point in the history
…askov TE calculator properly.

Added new demos to readme-template.
  • Loading branch information
jlizier committed Apr 17, 2014
1 parent 926f229 commit 4d1aac4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
%
%
% Inputs
% - kHistory - destination embedding length
% - lHistory - source embedding length
% - knns - a scalar specifying a single, or vector specifying multiple, value of K nearest neighbours to evaluate TE (Kraskov) with
% Outputs
% - teHeartToBreath - TE (heart -> breath) for each value of k nearest neighbours
% - teBreathToHeart - TE (breath -> heart) for each value of k nearest neighbours


function [teHeartToBreath, teBreathToHeart] = runHeartBreathRate(knns)
function [teHeartToBreath, teBreathToHeart] = runHeartBreathRateKraskov(kHistory, lHistory, knns)

starttime = tic;

Expand All @@ -41,32 +43,36 @@
fprintf('TE for heart rate <-> breath rate for Kraskov estimation with %d samples:\n', timeSteps);

% Using a single conditional mutual information calculator is the least biased way to run this:
teCalc=javaObject('infodynamics.measures.continuous.kraskov.ConditionalMutualInfoCalculatorMultiVariateKraskov1');
teCalc=javaObject('infodynamics.measures.continuous.kraskov.TransferEntropyCalculatorKraskov');

for knnIndex = 1:length(knns)
knn = knns(knnIndex);
% Compute a TE value for knn nearest neighbours

% Perform calculation for heart -> breath (lag 1)
teCalc.initialise(1,1,1); % Use history length 1 (Schreiber k)
teCalc.initialise(kHistory,1,lHistory,1,1);
teCalc.setProperty('k', sprintf('%d',knn));
teCalc.setObservations(octaveToJavaDoubleMatrix(heart(1:timeSteps-1)), ...
octaveToJavaDoubleMatrix(chestVol(2:timeSteps)), ...
octaveToJavaDoubleMatrix(chestVol(1:timeSteps-1)));
teCalc.setObservations(octaveToJavaDoubleMatrix(heart), ...
octaveToJavaDoubleMatrix(chestVol));
teHeartToBreath(knnIndex) = teCalc.computeAverageLocalOfObservations();

% Perform calculation for breath -> heart (lag 1)
teCalc.initialise(1,1,1); % Use history length 1 (Schreiber k)
teCalc.initialise(kHistory,1,lHistory,1,1);
teCalc.setProperty('k', sprintf('%d',knn));
teCalc.setObservations(octaveToJavaDoubleMatrix(chestVol(1:timeSteps-1)), ...
octaveToJavaDoubleMatrix(heart(2:timeSteps)), ...
octaveToJavaDoubleMatrix(heart(1:timeSteps-1)));
teCalc.setObservations(octaveToJavaDoubleMatrix(chestVol), ...
octaveToJavaDoubleMatrix(heart));
teBreathToHeart(knnIndex) = teCalc.computeAverageLocalOfObservations();

fprintf('TE(k=%d): heart->breath = %.3f, breath->heart = %.3f\n', knn, teHeartToBreath(knnIndex), teBreathToHeart(knnIndex));
end

endtime = toc;
fprintf('Total runtime was %.1f sec\n', endtime - starttime);
tElapsed = toc(starttime);
fprintf('Total runtime was %.1f sec\n', tElapsed);

plot(knns, teHeartToBreath, 'rx');
hold on;
plot(knns, teBreathToHeart, 'mo');
hold off;
legend(['TE(heart->breath)'; 'TE(breath->heart)']);
end

13 changes: 8 additions & 5 deletions readme-template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,17 @@ Further documentation is provided by the Usage examples below.

Several sets of demonstration code are distributed with the toolkit:

a. demos/octave - basic examples on easily using the Java toolkit from Octave or Matlab environments - see description at http://code.google.com/p/information-dynamics-toolkit/wiki/OctaveMatlabExamples
Note that this also provides useful examples on how to use the Java code in general!
a. demos/java -- basic examples on easily using the Java toolkit -- run these from the shell scripts in this directory -- see description at http://code.google.com/p/information-dynamics-toolkit/wiki/SimpleJavaExamples

b. demos/octave -- basic examples on easily using the Java toolkit from Octave or Matlab environments -- see description at http://code.google.com/p/information-dynamics-toolkit/wiki/OctaveMatlabExamples

b. demos/octave/CellularAutomata - using the Java toolkit to plot local information dynamics profiles in cellular automata; the toolkit is run under Octave or Matlab - see description at http://code.google.com/p/information-dynamics-toolkit/wiki/CellularAutomataDemos
c. demos/python -- basic examples on easily using the Java toolkit from Python -- see description at http://code.google.com/p/information-dynamics-toolkit/wiki/PythonExamples

d. demos/octave/CellularAutomata -- using the Java toolkit to plot local information dynamics profiles in cellular automata; the toolkit is run under Octave or Matlab -- see description at http://code.google.com/p/information-dynamics-toolkit/wiki/CellularAutomataDemos

c. demos/octave/DetectingInteractionLags - brief examples using the transfer entropy to examine source-delay interaction lags. Documentation to come soon; in the interim, see header comments in the .m files.
e. demos/octave/DetectingInteractionLags -- brief examples using the transfer entropy to examine source-delay interaction lags. Documentation to come soon; in the interim, see header comments in the .m files.

d. java/unittests - the JUnit test cases for the Java toolkit are included in the distribution - these case also be browsed to see simple use cases for the toolkit - see description at http://code.google.com/p/information-dynamics-toolkit/wiki/JUnitTestCases
f. java/unittests -- the JUnit test cases for the Java toolkit are included in the distribution -- these case also be browsed to see simple use cases for the various calculators in the toolkit -- see description at http://code.google.com/p/information-dynamics-toolkit/wiki/JUnitTestCases

=============

Expand Down

0 comments on commit 4d1aac4

Please sign in to comment.