Fixed analytic expressions for transfer entropies in the simple demos for coupled Gaussians (should have computed directly from the empirical correlations all along, but didn't notice because errors were very small)

This commit is contained in:
jlizier 2017-05-22 15:53:42 +10:00
parent 4e54fc6ce4
commit aedefd07bc
12 changed files with 59 additions and 15 deletions

View File

@ -45,6 +45,7 @@
(.setObservations teCalc sourceArray destArray) (.setObservations teCalc sourceArray destArray)
; For copied source, should give something close to expected value for correlated Gaussians: ; For copied source, should give something close to expected value for correlated Gaussians:
; TODO The analytic result quoted here isn't quite right, see e.g. octave demos (can't be bothered fixing here...)
(println "TE result " (.computeAverageLocalOfObservations teCalc) (println "TE result " (.computeAverageLocalOfObservations teCalc)
" expected to be close to " (/ (Math/log (/ 1 (- 1 (* covariance covariance)))) (Math/log 2)) " expected to be close to " (/ (Math/log (/ 1 (- 1 (* covariance covariance)))) (Math/log 2))
" for these correlated Gaussians but biased upward") " for these correlated Gaussians but biased upward")

View File

@ -49,6 +49,7 @@
; data is a set of random variables) - the result will be of the order ; data is a set of random variables) - the result will be of the order
; of what we expect, but not exactly equal to it; in fact, there will ; of what we expect, but not exactly equal to it; in fact, there will
; be a large variance around it. ; be a large variance around it.
; TODO The analytic result quoted here isn't quite right, see e.g. octave demos (can't be bothered fixing here...)
(println "TE result " (.computeAverageLocalOfObservations teCalc) (println "TE result " (.computeAverageLocalOfObservations teCalc)
" nats expected to be close to " (Math/log (/ 1 (- 1 (* covariance covariance)))) " nats expected to be close to " (Math/log (/ 1 (- 1 (* covariance covariance))))
" nats for these correlated Gaussians") " nats for these correlated Gaussians")

View File

@ -58,11 +58,16 @@ public class Example3TeContinuousDataKernel {
teCalc.setProperty("NORMALISE", "true"); // Normalise the individual variables (default) teCalc.setProperty("NORMALISE", "true"); // Normalise the individual variables (default)
teCalc.initialise(1, 0.5); // Use history length 1 (Schreiber k=1), kernel width of 0.5 normalised units teCalc.initialise(1, 0.5); // Use history length 1 (Schreiber k=1), kernel width of 0.5 normalised units
teCalc.setObservations(sourceArray, destArray); teCalc.setObservations(sourceArray, destArray);
// For copied source, should give something close to expected value for correlated Gaussians:
double result = teCalc.computeAverageLocalOfObservations(); double result = teCalc.computeAverageLocalOfObservations();
// For copied source, should give something close to expected value for correlated Gaussians:.
// Expected correlation is expected covariance / product of expected standard deviations:
// (where square of destArray standard dev is sum of squares of std devs of
// underlying distributions)
double corr_expected = covariance /
(1.0 * Math.sqrt(Math.pow(covariance,2) + Math.pow(1-covariance,2)));
System.out.printf("TE result %.4f bits; expected to be close to " + System.out.printf("TE result %.4f bits; expected to be close to " +
"%.4f bits for these correlated Gaussians but biased upwards\n", "%.4f bits for these correlated Gaussians but biased upwards\n",
result, Math.log(1.0/(1-Math.pow(covariance,2)))/Math.log(2)); result, -0.5 * Math.log(1-Math.pow(corr_expected,2))/Math.log(2));
teCalc.initialise(); // Initialise leaving the parameters the same teCalc.initialise(); // Initialise leaving the parameters the same
teCalc.setObservations(sourceArray2, destArray); teCalc.setObservations(sourceArray2, destArray);

View File

@ -65,9 +65,14 @@ public class Example4TeContinuousDataKraskov {
// data is a set of random variables) - the result will be of the order // data is a set of random variables) - the result will be of the order
// of what we expect, but not exactly equal to it; in fact, there will // of what we expect, but not exactly equal to it; in fact, there will
// be a large variance around it. // be a large variance around it.
// Expected correlation is expected covariance / product of expected standard deviations:
// (where square of destArray standard dev is sum of squares of std devs of
// underlying distributions)
double corr_expected = covariance /
(1.0 * Math.sqrt(Math.pow(covariance,2) + Math.pow(1-covariance,2)));
System.out.printf("TE result %.4f nats; expected to be close to " + System.out.printf("TE result %.4f nats; expected to be close to " +
"%.4f nats for these correlated Gaussians\n", "%.4f nats for these correlated Gaussians\n",
result, Math.log(1.0/(1-Math.pow(covariance,2)))); result, -0.5 * Math.log(1-Math.pow(corr_expected,2)));
// Perform calculation with uncorrelated source: // Perform calculation with uncorrelated source:
teCalc.initialise(); // Initialise leaving the parameters the same teCalc.initialise(); // Initialise leaving the parameters the same

View File

@ -42,9 +42,13 @@ jcall(teCalc, "setProperty", Void, (JString, JString), "NORMALISE", "true"); # N
jcall(teCalc, "initialise", Void, (jint, jdouble), 1, 0.5); # Use history length 1 (Schreiber k=1), kernel width of 0.5 normalised units jcall(teCalc, "initialise", Void, (jint, jdouble), 1, 0.5); # Use history length 1 (Schreiber k=1), kernel width of 0.5 normalised units
jcall(teCalc, "setObservations", Void, (Array{jdouble,1}, Array{jdouble,1}), jcall(teCalc, "setObservations", Void, (Array{jdouble,1}, Array{jdouble,1}),
sourceArray, destArray); sourceArray, destArray);
# For copied source, should give something close to expected value for correlated Gaussians:
result = jcall(teCalc, "computeAverageLocalOfObservations", jdouble, ()); result = jcall(teCalc, "computeAverageLocalOfObservations", jdouble, ());
@printf("TE result %.4f bits; expected to be close to %.4f bits for these correlated Gaussians but biased upwards\n", result, log(1/(1-covariance^2))/log(2)); # For copied source, should give something close to expected value for correlated Gaussians:
# Expected correlation is expected covariance / product of expected standard deviations:
# (where square of destArray standard dev is sum of squares of std devs of
# underlying distributions)
corr_expected = covariance / (1 * sqrt(covariance^2 + (1-covariance)^2));
@printf("TE result %.4f bits; expected to be close to %.4f bits for these correlated Gaussians but biased upwards\n", result, -0.5*log(1-corr_expected^2)/log(2));
jcall(teCalc, "initialise", Void, ()); # Initialise leaving the parameters the same jcall(teCalc, "initialise", Void, ()); # Initialise leaving the parameters the same
jcall(teCalc, "setObservations", Void, (Array{jdouble,1}, Array{jdouble,1}), jcall(teCalc, "setObservations", Void, (Array{jdouble,1}, Array{jdouble,1}),

View File

@ -49,8 +49,12 @@ result = jcall(teCalc, "computeAverageLocalOfObservations", jdouble, ());
# data is a set of random variables) - the result will be of the order # data is a set of random variables) - the result will be of the order
# of what we expect, but not exactly equal to it; in fact, there will # of what we expect, but not exactly equal to it; in fact, there will
# be a large variance around it. # be a large variance around it.
# Expected correlation is expected covariance / product of expected standard deviations:
# (where square of destArray standard dev is sum of squares of std devs of
# underlying distributions)
corr_expected = covariance / (1 * sqrt(covariance^2 + (1-covariance)^2));
@printf("TE result %.4f nats; expected to be close to %.4f nats for these correlated Gaussians\n", @printf("TE result %.4f nats; expected to be close to %.4f nats for these correlated Gaussians\n",
result, log(1/(1-covariance^2))); result, -0.5*log(1-corr_expected^2));
# Perform calculation with uncorrelated source: # Perform calculation with uncorrelated source:
jcall(teCalc, "initialise", Void, ()); # Initialise leaving the parameters the same jcall(teCalc, "initialise", Void, ()); # Initialise leaving the parameters the same

View File

@ -34,10 +34,14 @@ teCalc=javaObject('infodynamics.measures.continuous.kernel.TransferEntropyCalcul
teCalc.setProperty('NORMALISE', 'true'); % Normalise the individual variables teCalc.setProperty('NORMALISE', 'true'); % Normalise the individual variables
teCalc.initialise(1, 0.5); % Use history length 1 (Schreiber k=1), kernel width of 0.5 normalised units teCalc.initialise(1, 0.5); % Use history length 1 (Schreiber k=1), kernel width of 0.5 normalised units
teCalc.setObservations(sourceArray, destArray); teCalc.setObservations(sourceArray, destArray);
% For copied source, should give something close to expected value for correlated Gaussians:
result = teCalc.computeAverageLocalOfObservations(); result = teCalc.computeAverageLocalOfObservations();
% For copied source, should give something close to expected value for correlated Gaussians.
% Expected correlation is expected covariance / product of expected standard deviations:
% (where square of destArray standard dev is sum of squares of std devs of
% underlying distributions)
corr_expected = covariance ./ (1 * sqrt(covariance^2 + (1-covariance)^2));
fprintf('TE result %.4f bits; expected to be close to %.4f bits for these correlated Gaussians but biased upwards\n', ... fprintf('TE result %.4f bits; expected to be close to %.4f bits for these correlated Gaussians but biased upwards\n', ...
result, log(1/(1-covariance^2))/log(2)); result, -0.5*log(1-corr_expected^2)/log(2));
teCalc.initialise(); % Initialise leaving the parameters the same teCalc.initialise(); % Initialise leaving the parameters the same
teCalc.setObservations(sourceArray2, destArray); teCalc.setObservations(sourceArray2, destArray);
% For random source, it should give something close to 0 bits % For random source, it should give something close to 0 bits

View File

@ -40,8 +40,12 @@ result = teCalc.computeAverageLocalOfObservations();
% data is a set of random variables) - the result will be of the order % data is a set of random variables) - the result will be of the order
% of what we expect, but not exactly equal to it; in fact, there will % of what we expect, but not exactly equal to it; in fact, there will
% be a large variance around it. % be a large variance around it.
% Expected correlation is expected covariance / product of expected standard deviations:
% (where square of destArray standard dev is sum of squares of std devs of
% underlying distributions)
corr_expected = covariance ./ (1 * sqrt(covariance^2 + (1-covariance)^2));
fprintf('TE result %.4f nats; expected to be close to %.4f nats for these correlated Gaussians\n', ... fprintf('TE result %.4f nats; expected to be close to %.4f nats for these correlated Gaussians\n', ...
result, log(1/(1-covariance^2))); result, - 0.5 * log(1-corr_expected^2));
% Perform calculation with uncorrelated source: % Perform calculation with uncorrelated source:
teCalc.initialise(); % Initialise leaving the parameters the same teCalc.initialise(); % Initialise leaving the parameters the same
teCalc.setObservations(sourceArray2, destArray); teCalc.setObservations(sourceArray2, destArray);

View File

@ -45,10 +45,14 @@ teCalc = teCalcClass()
teCalc.setProperty("NORMALISE", "true") # Normalise the individual variables teCalc.setProperty("NORMALISE", "true") # Normalise the individual variables
teCalc.initialise(1, 0.5) # Use history length 1 (Schreiber k=1), kernel width of 0.5 normalised units teCalc.initialise(1, 0.5) # Use history length 1 (Schreiber k=1), kernel width of 0.5 normalised units
teCalc.setObservations(JArray(JDouble, 1)(sourceArray), JArray(JDouble, 1)(destArray)) teCalc.setObservations(JArray(JDouble, 1)(sourceArray), JArray(JDouble, 1)(destArray))
# For copied source, should give something close to 1 bit:
result = teCalc.computeAverageLocalOfObservations() result = teCalc.computeAverageLocalOfObservations()
# For copied source, should give something close to 1 bit:
# Expected correlation is expected covariance / product of expected standard deviations:
# (where square of destArray standard dev is sum of squares of std devs of
# underlying distributions)
corr_expected = covariance / (1 * math.sqrt(covariance**2 + (1-covariance)**2));
print("TE result %.4f bits; expected to be close to %.4f bits for these correlated Gaussians but biased upwards" % \ print("TE result %.4f bits; expected to be close to %.4f bits for these correlated Gaussians but biased upwards" % \
(result, math.log(1/(1-math.pow(covariance,2)))/math.log(2))) (result, -0.5*math.log(1-math.pow(corr_expected,2))/math.log(2)))
teCalc.initialise() # Initialise leaving the parameters the same teCalc.initialise() # Initialise leaving the parameters the same
teCalc.setObservations(JArray(JDouble, 1)(sourceArray2), JArray(JDouble, 1)(destArray)) teCalc.setObservations(JArray(JDouble, 1)(sourceArray2), JArray(JDouble, 1)(destArray))
# For random source, it should give something close to 0 bits # For random source, it should give something close to 0 bits

View File

@ -52,8 +52,12 @@ result = teCalc.computeAverageLocalOfObservations()
# data is a set of random variables) - the result will be of the order # data is a set of random variables) - the result will be of the order
# of what we expect, but not exactly equal to it; in fact, there will # of what we expect, but not exactly equal to it; in fact, there will
# be a large variance around it. # be a large variance around it.
# Expected correlation is expected covariance / product of expected standard deviations:
# (where square of destArray standard dev is sum of squares of std devs of
# underlying distributions)
corr_expected = covariance / (1 * math.sqrt(covariance**2 + (1-covariance)**2));
print("TE result %.4f nats; expected to be close to %.4f nats for these correlated Gaussians" % \ print("TE result %.4f nats; expected to be close to %.4f nats for these correlated Gaussians" % \
(result, math.log(1/(1-math.pow(covariance,2))))) (result, -0.5 * math.log(1-corr_expected**2)))
# Perform calculation with uncorrelated source: # Perform calculation with uncorrelated source:
teCalc.initialise() # Initialise leaving the parameters the same teCalc.initialise() # Initialise leaving the parameters the same
teCalc.setObservations(JArray(JDouble, 1)(sourceArray2), JArray(JDouble, 1)(destArray)) teCalc.setObservations(JArray(JDouble, 1)(sourceArray2), JArray(JDouble, 1)(destArray))

View File

@ -41,9 +41,13 @@ teCalc<-.jnew("infodynamics/measures/continuous/kernel/TransferEntropyCalculator
.jcall(teCalc,"V","setProperty", "NORMALISE", "true") # Normalise the individual variables .jcall(teCalc,"V","setProperty", "NORMALISE", "true") # Normalise the individual variables
.jcall(teCalc,"V","initialise", 1L, 0.5) # Use history length 1 (Schreiber k=1), kernel width of 0.5 normalised units .jcall(teCalc,"V","initialise", 1L, 0.5) # Use history length 1 (Schreiber k=1), kernel width of 0.5 normalised units
.jcall(teCalc,"V","setObservations", sourceArray, destArray) .jcall(teCalc,"V","setObservations", sourceArray, destArray)
# For copied source, should give something close to expected value for correlated Gaussians:
result <- .jcall(teCalc,"D","computeAverageLocalOfObservations") result <- .jcall(teCalc,"D","computeAverageLocalOfObservations")
cat("TE result ", result, "bits; expected to be close to ", log(1/(1-covariance^2))/log(2), " bits for these correlated Gaussians but biased upwards\n") # For copied source, should give something close to expected value for correlated Gaussians.
# Expected correlation is expected covariance / product of expected standard deviations:
# (where square of destArray standard dev is sum of squares of std devs of
# underlying distributions)
corr_expected <- covariance / (1 * sqrt(covariance^2 + (1-covariance)^2));
cat("TE result ", result, "bits; expected to be close to ", -0.5*log(1-corr_expected^2)/log(2), " bits for these correlated Gaussians but biased upwards\n")
.jcall(teCalc,"V","initialise") # Initialise leaving the parameters the same .jcall(teCalc,"V","initialise") # Initialise leaving the parameters the same
.jcall(teCalc,"V","setObservations", sourceArray2, destArray) .jcall(teCalc,"V","setObservations", sourceArray2, destArray)

View File

@ -48,7 +48,11 @@ result <- .jcall(teCalc,"D","computeAverageLocalOfObservations")
# data is a set of random variables) - the result will be of the order # data is a set of random variables) - the result will be of the order
# of what we expect, but not exactly equal to it; in fact, there will # of what we expect, but not exactly equal to it; in fact, there will
# be a large variance around it. # be a large variance around it.
cat("TE result ", result, "nats; expected to be close to ", log(1/(1-covariance^2)), " nats for these correlated Gaussians\n") # Expected correlation is expected covariance / product of expected standard deviations:
# (where square of destArray standard dev is sum of squares of std devs of
# underlying distributions)
corr_expected <- covariance / (1 * sqrt(covariance^2 + (1-covariance)^2));
cat("TE result ", result, "nats; expected to be close to ", -0.5*log(1-corr_expected^2), " nats for these correlated Gaussians\n")
# Perform calculation with uncorrelated source: # Perform calculation with uncorrelated source:
.jcall(teCalc,"V","initialise") # Initialise leaving the parameters the same .jcall(teCalc,"V","initialise") # Initialise leaving the parameters the same