diff --git a/java/source/infodynamics/measures/continuous/EntropyCalculatorMultiVariate.java b/java/source/infodynamics/measures/continuous/EntropyCalculatorMultiVariate.java index 8fef120..0982bbd 100755 --- a/java/source/infodynamics/measures/continuous/EntropyCalculatorMultiVariate.java +++ b/java/source/infodynamics/measures/continuous/EntropyCalculatorMultiVariate.java @@ -45,4 +45,5 @@ public interface EntropyCalculatorMultiVariate { public void setDebug(boolean debug); + public int getNumObservations() throws Exception; } diff --git a/java/source/infodynamics/measures/continuous/gaussian/EntropyCalculatorMultiVariateGaussian.java b/java/source/infodynamics/measures/continuous/gaussian/EntropyCalculatorMultiVariateGaussian.java index 2137f17..6e17539 100755 --- a/java/source/infodynamics/measures/continuous/gaussian/EntropyCalculatorMultiVariateGaussian.java +++ b/java/source/infodynamics/measures/continuous/gaussian/EntropyCalculatorMultiVariateGaussian.java @@ -260,6 +260,19 @@ public class EntropyCalculatorMultiVariateGaussian return computeLocalUsingPreviousObservations(observations); } + /** + * @return the number of previously supplied observations for which + * the mutual information will be / was computed. + */ + public int getNumObservations() throws Exception { + if (observations == null) { + throw new Exception("Cannot return number of observations because either " + + "this calculator has not had observations supplied or " + + "the user supplied the covariance matrix instead of observations"); + } + return observations.length; + } + /** * Provide an implementation of the clone() method. * This does not deeply copy all of the underlying data, just providing @@ -271,7 +284,7 @@ public class EntropyCalculatorMultiVariateGaussian * @see java.lang.Object#clone() */ @Override - protected Object clone() throws CloneNotSupportedException { + public Object clone() throws CloneNotSupportedException { return super.clone(); } } diff --git a/java/source/infodynamics/measures/continuous/kernel/EntropyCalculatorMultiVariateKernel.java b/java/source/infodynamics/measures/continuous/kernel/EntropyCalculatorMultiVariateKernel.java index e7de123..11b617c 100755 --- a/java/source/infodynamics/measures/continuous/kernel/EntropyCalculatorMultiVariateKernel.java +++ b/java/source/infodynamics/measures/continuous/kernel/EntropyCalculatorMultiVariateKernel.java @@ -143,4 +143,8 @@ public class EntropyCalculatorMultiVariateKernel implements EntropyCalculatorMul } } + public int getNumObservations() throws Exception { + return totalObservations; + } + } diff --git a/java/source/infodynamics/measures/continuous/kernel/KernelEstimatorMultiVariate.java b/java/source/infodynamics/measures/continuous/kernel/KernelEstimatorMultiVariate.java index ba1356d..6d894dd 100755 --- a/java/source/infodynamics/measures/continuous/kernel/KernelEstimatorMultiVariate.java +++ b/java/source/infodynamics/measures/continuous/kernel/KernelEstimatorMultiVariate.java @@ -930,6 +930,16 @@ public class KernelEstimatorMultiVariate implements Cloneable { return 1; } + /** + * Return the kernel widths that are actually in use in the + * calculator (i.e. those after any normalisation is applied) + * + * @return the kernelWidthsInUse + */ + public double[] getKernelWidthsInUse() { + return kernelWidthsInUse; + } + public void setNormalise(boolean normalise) { this.normalise = normalise; } diff --git a/java/source/infodynamics/measures/mixed/ConditionalMutualInfoCalculatorMultiVariateWithDiscrete.java b/java/source/infodynamics/measures/mixed/ConditionalMutualInfoCalculatorMultiVariateWithDiscrete.java index febe6fe..a01e91b 100755 --- a/java/source/infodynamics/measures/mixed/ConditionalMutualInfoCalculatorMultiVariateWithDiscrete.java +++ b/java/source/infodynamics/measures/mixed/ConditionalMutualInfoCalculatorMultiVariateWithDiscrete.java @@ -1,4 +1,4 @@ -package infodynamics.measures.continuous; +package infodynamics.measures.mixed; import infodynamics.utils.EmpiricalMeasurementDistribution; diff --git a/java/source/infodynamics/measures/mixed/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSource.java b/java/source/infodynamics/measures/mixed/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSource.java index 38f1546..5814bca 100755 --- a/java/source/infodynamics/measures/mixed/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSource.java +++ b/java/source/infodynamics/measures/mixed/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSource.java @@ -1,4 +1,4 @@ -package infodynamics.measures.continuous; +package infodynamics.measures.mixed; import infodynamics.utils.EmpiricalMeasurementDistribution; diff --git a/java/source/infodynamics/measures/mixed/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSourceCommon.java b/java/source/infodynamics/measures/mixed/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSourceCommon.java index dbf6327..2a54258 100755 --- a/java/source/infodynamics/measures/mixed/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSourceCommon.java +++ b/java/source/infodynamics/measures/mixed/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSourceCommon.java @@ -1,6 +1,6 @@ -package infodynamics.measures.continuous; +package infodynamics.measures.mixed; -import infodynamics.measures.continuous.ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSource; +import infodynamics.measures.mixed.ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSource; import infodynamics.utils.MatrixUtils; import infodynamics.utils.EmpiricalMeasurementDistribution; import infodynamics.utils.RandomGenerator; diff --git a/java/source/infodynamics/measures/mixed/MutualInfoCalculatorMultiVariateWithDiscrete.java b/java/source/infodynamics/measures/mixed/MutualInfoCalculatorMultiVariateWithDiscrete.java index 08d85bc..a76f925 100755 --- a/java/source/infodynamics/measures/mixed/MutualInfoCalculatorMultiVariateWithDiscrete.java +++ b/java/source/infodynamics/measures/mixed/MutualInfoCalculatorMultiVariateWithDiscrete.java @@ -1,4 +1,4 @@ -package infodynamics.measures.continuous; +package infodynamics.measures.mixed; import infodynamics.utils.EmpiricalMeasurementDistribution; diff --git a/java/source/infodynamics/measures/mixed/gaussian/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSourceGaussian.java b/java/source/infodynamics/measures/mixed/gaussian/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSourceGaussian.java index ba11b08..669f08f 100755 --- a/java/source/infodynamics/measures/mixed/gaussian/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSourceGaussian.java +++ b/java/source/infodynamics/measures/mixed/gaussian/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSourceGaussian.java @@ -1,7 +1,8 @@ -package infodynamics.measures.continuous.gaussian; +package infodynamics.measures.mixed.gaussian; -import infodynamics.measures.continuous.ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSourceCommon; +import infodynamics.measures.mixed.ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSourceCommon; import infodynamics.measures.continuous.ConditionalMutualInfoMultiVariateCommon; +import infodynamics.measures.continuous.gaussian.EntropyCalculatorMultiVariateGaussian; import infodynamics.utils.MatrixUtils; /** diff --git a/java/source/infodynamics/measures/mixed/gaussian/MutualInfoCalculatorMultiVariateWithDiscreteGaussian.java b/java/source/infodynamics/measures/mixed/gaussian/MutualInfoCalculatorMultiVariateWithDiscreteGaussian.java index 486db03..87cd9be 100755 --- a/java/source/infodynamics/measures/mixed/gaussian/MutualInfoCalculatorMultiVariateWithDiscreteGaussian.java +++ b/java/source/infodynamics/measures/mixed/gaussian/MutualInfoCalculatorMultiVariateWithDiscreteGaussian.java @@ -1,6 +1,7 @@ -package infodynamics.measures.continuous.gaussian; +package infodynamics.measures.mixed.gaussian; -import infodynamics.measures.continuous.MutualInfoCalculatorMultiVariateWithDiscrete; +import infodynamics.measures.continuous.gaussian.EntropyCalculatorMultiVariateGaussian; +import infodynamics.measures.mixed.MutualInfoCalculatorMultiVariateWithDiscrete; import infodynamics.utils.EmpiricalMeasurementDistribution; import infodynamics.utils.MatrixUtils; import infodynamics.utils.RandomGenerator; @@ -61,11 +62,16 @@ public class MutualInfoCalculatorMultiVariateWithDiscreteGaussian implements /** * Keep a copy of the discrete observations, to enable us to compute the - * statistical significance later. We don't need to keep a copy of - * the continuous observations, since they're kept intact by entCalc. + * statistical significance later. */ protected int[] discreteObservations; + /** + * Keep a copy of the continuous observations, to enable us to compute the + * statistical significance later. + */ + protected double[][] continuousObservations; + /** * Number of supplied observations */ @@ -127,6 +133,7 @@ public class MutualInfoCalculatorMultiVariateWithDiscreteGaussian implements // (this will pick up any errors in the dimensions of the continuous // observations) entCalc.setObservations(continuousObservations); + this.continuousObservations = continuousObservations; // Set the observations corresponding to each discrete value: setDiscreteData(continuousObservations, discreteObservations); totalObservations = continuousObservations.length; @@ -176,11 +183,12 @@ public class MutualInfoCalculatorMultiVariateWithDiscreteGaussian implements * the discrete data (averaged over all discrete values) * * @return average conditional entropy + * @throws Exception */ - protected double computeAverageLocalConditionalEntropyOfObservations() { + protected double computeAverageLocalConditionalEntropyOfObservations() throws Exception { double meanConditionalEntropy = 0; for (int b = 0; b < base; b++) { - double pOfB = (double) entCalcForEachDiscrete[b].observations.length / + double pOfB = (double) entCalcForEachDiscrete[b].getNumObservations() / (double) totalObservations; meanConditionalEntropy += pOfB * entCalcForEachDiscrete[b].computeAverageLocalOfObservations(); @@ -288,7 +296,7 @@ public class MutualInfoCalculatorMultiVariateWithDiscreteGaussian implements // inside this calculator, and avoid recomputing covariances etc // on the continuous data set) miSurrogateCalculator.setDiscreteData( - entCalc.observations, shuffledDiscreteData); + continuousObservations, shuffledDiscreteData); // Compute the MI: surrogateMeasurements[i] = miSurrogateCalculator.entCalc.computeAverageLocalOfObservations() - miSurrogateCalculator.computeAverageLocalConditionalEntropyOfObservations(); diff --git a/java/source/infodynamics/measures/mixed/kernel/MutualInfoCalculatorMultiVariateWithDiscreteKernel.java b/java/source/infodynamics/measures/mixed/kernel/MutualInfoCalculatorMultiVariateWithDiscreteKernel.java index 9bc6214..e197322 100755 --- a/java/source/infodynamics/measures/mixed/kernel/MutualInfoCalculatorMultiVariateWithDiscreteKernel.java +++ b/java/source/infodynamics/measures/mixed/kernel/MutualInfoCalculatorMultiVariateWithDiscreteKernel.java @@ -1,8 +1,9 @@ -package infodynamics.measures.continuous.kernel; +package infodynamics.measures.mixed.kernel; import java.util.Arrays; -import infodynamics.measures.continuous.MutualInfoCalculatorMultiVariateWithDiscrete; +import infodynamics.measures.continuous.kernel.KernelEstimatorMultiVariate; +import infodynamics.measures.mixed.MutualInfoCalculatorMultiVariateWithDiscrete; import infodynamics.utils.MatrixUtils; import infodynamics.utils.EmpiricalMeasurementDistribution; import infodynamics.utils.RandomGenerator; @@ -143,7 +144,7 @@ public class MutualInfoCalculatorMultiVariateWithDiscreteKernel implements double[][] obsForThisDiscValue = MatrixUtils.extractSelectedPointsMatchingCondition( continuousObservations, discreteObservations, i, discCounts[i]); // Set the kernel width for the relevant kernel estimator: - mvkeForEachDiscrete[i].initialise(mvke.kernelWidthsInUse); + mvkeForEachDiscrete[i].initialise(mvke.getKernelWidthsInUse()); // Set these observations for the relevant kernel estimator: mvkeForEachDiscrete[i].setObservations(obsForThisDiscValue); } @@ -577,6 +578,6 @@ public class MutualInfoCalculatorMultiVariateWithDiscreteKernel implements */ public double[] getKernelWidthsInUse() { // Return a copy so that the user can't mess with it - return Arrays.copyOf(mvke.kernelWidthsInUse, mvke.kernelWidthsInUse.length); + return Arrays.copyOf(mvke.getKernelWidthsInUse(), mvke.getKernelWidthsInUse().length); } } diff --git a/java/source/infodynamics/measures/mixed/kraskov/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteKraskov.java b/java/source/infodynamics/measures/mixed/kraskov/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteKraskov.java index 8717b22..8cdde5d 100755 --- a/java/source/infodynamics/measures/mixed/kraskov/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteKraskov.java +++ b/java/source/infodynamics/measures/mixed/kraskov/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteKraskov.java @@ -1,6 +1,6 @@ -package infodynamics.measures.continuous.kraskov; +package infodynamics.measures.mixed.kraskov; -import infodynamics.measures.continuous.ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSourceCommon; +import infodynamics.measures.mixed.ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSourceCommon; import infodynamics.utils.EuclideanUtils; import infodynamics.utils.MathsUtils; import infodynamics.utils.MatrixUtils; diff --git a/java/source/infodynamics/measures/mixed/kraskov/MutualInfoCalculatorMultiVariateWithDiscreteKraskov.java b/java/source/infodynamics/measures/mixed/kraskov/MutualInfoCalculatorMultiVariateWithDiscreteKraskov.java index 9a0ecc9..235eaa7 100755 --- a/java/source/infodynamics/measures/mixed/kraskov/MutualInfoCalculatorMultiVariateWithDiscreteKraskov.java +++ b/java/source/infodynamics/measures/mixed/kraskov/MutualInfoCalculatorMultiVariateWithDiscreteKraskov.java @@ -1,6 +1,6 @@ -package infodynamics.measures.continuous.kraskov; +package infodynamics.measures.mixed.kraskov; -import infodynamics.measures.continuous.MutualInfoCalculatorMultiVariateWithDiscrete; +import infodynamics.measures.mixed.MutualInfoCalculatorMultiVariateWithDiscrete; import infodynamics.utils.EuclideanUtils; import infodynamics.utils.MathsUtils; import infodynamics.utils.MatrixUtils; diff --git a/java/source/infodynamics/measures/mixed/symbolic/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSymbolic.java b/java/source/infodynamics/measures/mixed/symbolic/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSymbolic.java index 87d1b4f..b0486ba 100755 --- a/java/source/infodynamics/measures/mixed/symbolic/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSymbolic.java +++ b/java/source/infodynamics/measures/mixed/symbolic/ConditionalMutualInfoCalculatorMultiVariateWithDiscreteSymbolic.java @@ -1,6 +1,6 @@ -package infodynamics.measures.continuous.symbolic; +package infodynamics.measures.mixed.symbolic; -import infodynamics.measures.continuous.ConditionalMutualInfoCalculatorMultiVariateWithDiscrete; +import infodynamics.measures.mixed.ConditionalMutualInfoCalculatorMultiVariateWithDiscrete; import infodynamics.measures.discrete.ConditionalMutualInformationCalculator; import infodynamics.utils.FirstIndexComparatorDouble; import infodynamics.utils.MathsUtils; diff --git a/java/source/infodynamics/measures/mixed/symbolic/MutualInfoCalculatorMultiVariateWithDiscreteSymbolic.java b/java/source/infodynamics/measures/mixed/symbolic/MutualInfoCalculatorMultiVariateWithDiscreteSymbolic.java index 082e749..29b5cdc 100755 --- a/java/source/infodynamics/measures/mixed/symbolic/MutualInfoCalculatorMultiVariateWithDiscreteSymbolic.java +++ b/java/source/infodynamics/measures/mixed/symbolic/MutualInfoCalculatorMultiVariateWithDiscreteSymbolic.java @@ -1,6 +1,6 @@ -package infodynamics.measures.continuous.symbolic; +package infodynamics.measures.mixed.symbolic; -import infodynamics.measures.continuous.MutualInfoCalculatorMultiVariateWithDiscrete; +import infodynamics.measures.mixed.MutualInfoCalculatorMultiVariateWithDiscrete; import infodynamics.measures.discrete.MutualInformationCalculator; import infodynamics.utils.FirstIndexComparatorDouble; import infodynamics.utils.MathsUtils;