Refactoring non-Java demos for discrete TE calculator to take source as first argument before destination (to match continuous calculators)

This commit is contained in:
joseph.lizier 2014-08-05 13:01:02 +00:00
parent b7526a798a
commit d3bb73bba0
5 changed files with 14 additions and 14 deletions

View File

@ -77,10 +77,10 @@ function transferWithSourceMemory(savePlot)
% Compute TEs
teCalc = javaObject('infodynamics.measures.discrete.TransferEntropyCalculator', 4, 1);
teCalc.initialise();
teCalc.addObservations(y, x);
teCalc.addObservations(x, y);
teXnToYnplus1(deltaIndex) = teCalc.computeAverageLocalOfObservations();
teCalc.initialise();
teCalc.addObservations(y(2:length(y)), x(1:length(x)-1));
teCalc.addObservations(x(1:length(x)-1), y(2:length(y)));
teXnminus1ToYnplus1(deltaIndex) = teCalc.computeAverageLocalOfObservations();
% Compute MITs

View File

@ -15,11 +15,11 @@ sourceArray2=(rand(100,1)>0.5)*1;
teCalc=javaObject('infodynamics.measures.discrete.TransferEntropyCalculator', 2, 1);
teCalc.initialise();
% Since we have simple arrays of ints, we can directly pass these in:
teCalc.addObservations(destArray, sourceArray);
teCalc.addObservations(sourceArray, destArray);
fprintf('For copied source, result should be close to 1 bit : ');
result = teCalc.computeAverageLocalOfObservations()
teCalc.initialise();
teCalc.addObservations(destArray, sourceArray2);
teCalc.addObservations(sourceArray2, destArray);
fprintf('For random source, result should be close to 0 bits: ');
result2 = teCalc.computeAverageLocalOfObservations()

View File

@ -20,13 +20,13 @@ teCalc.initialise();
% We need to construct the joint values of the dest and source before we pass them in,
% and need to use the matrix conversion routine when calling from Matlab/Octave:
mUtils= javaObject('infodynamics.utils.MatrixUtils');
teCalc.addObservations(mUtils.computeCombinedValues(octaveToJavaIntMatrix(destArray), 2), ...
mUtils.computeCombinedValues(octaveToJavaIntMatrix(sourceArray), 2));
teCalc.addObservations(mUtils.computeCombinedValues(octaveToJavaIntMatrix(sourceArray), 2), ...
mUtils.computeCombinedValues(octaveToJavaIntMatrix(destArray), 2));
fprintf('For source which the 2 bits are determined from, result should be close to 2 bits : ');
result = teCalc.computeAverageLocalOfObservations()
teCalc.initialise();
teCalc.addObservations(mUtils.computeCombinedValues(octaveToJavaIntMatrix(destArray), 2), ...
mUtils.computeCombinedValues(octaveToJavaIntMatrix(sourceArray2), 2));
teCalc.addObservations(mUtils.computeCombinedValues(octaveToJavaIntMatrix(sourceArray2), 2), ...
mUtils.computeCombinedValues(octaveToJavaIntMatrix(destArray), 2));
fprintf('For random source, result should be close to 0 bits in theory: ');
result2 = teCalc.computeAverageLocalOfObservations()
fprintf('\nThe result for random source is inflated towards 0.3 due to finite observation length (%d).\nOne can verify that the answer is consistent with that from a\nrandom source by checking: teCalc.computeSignificance(1000); ans.pValue\n', teCalc.getNumObservations());

View File

@ -20,10 +20,10 @@ teCalcClass = JPackage("infodynamics.measures.discrete").TransferEntropyCalculat
teCalc = teCalcClass(2,1)
teCalc.initialise()
# Since we have simple arrays of ints, we can directly pass these in:
teCalc.addObservations(destArray, sourceArray)
teCalc.addObservations(sourceArray, destArray)
print("For copied source, result should be close to 1 bit : %.4f" % teCalc.computeAverageLocalOfObservations())
teCalc.initialise()
teCalc.addObservations(destArray, sourceArray2)
teCalc.addObservations(sourceArray2, destArray)
print("For random source, result should be close to 0 bits: %.4f" % teCalc.computeAverageLocalOfObservations())
shutdownJVM()

View File

@ -28,13 +28,13 @@ teCalc.initialise()
# We need to construct the joint values of the dest and source before we pass them in,
# and need to use the matrix conversion routine when calling from Matlab/Octave:
mUtils= JPackage('infodynamics.utils').MatrixUtils
teCalc.addObservations(mUtils.computeCombinedValues(destArray, 2), \
mUtils.computeCombinedValues(sourceArray, 2))
teCalc.addObservations(mUtils.computeCombinedValues(sourceArray, 2), \
mUtils.computeCombinedValues(destArray, 2))
result = teCalc.computeAverageLocalOfObservations()
print('For source which the 2 bits are determined from, result should be close to 2 bits : %.3f' % result)
teCalc.initialise()
teCalc.addObservations(mUtils.computeCombinedValues(destArray, 2), \
mUtils.computeCombinedValues(sourceArray2, 2))
teCalc.addObservations(mUtils.computeCombinedValues(sourceArray2, 2), \
mUtils.computeCombinedValues(destArray, 2))
result2 = teCalc.computeAverageLocalOfObservations()
print('For random source, result should be close to 0 bits in theory: %.3f' % result2)
print('The result for random source is inflated towards 0.3 due to finite observation length (%d). One can verify that the answer is consistent with that from a random source by checking: teCalc.computeSignificance(1000); ans.pValue\n' % teCalc.getNumObservations())