mirror of https://github.com/jlizier/jidt
Code edits to mixed calculators to fix compilation after moving them into the "mixed" package. Also needed to make some alternations to some of the continuous calculators to fix usage of protected members which are no longer accessible to the moved classes.
This commit is contained in:
parent
c481377ead
commit
5a6fdb0ea7
|
@ -45,4 +45,5 @@ public interface EntropyCalculatorMultiVariate {
|
|||
|
||||
public void setDebug(boolean debug);
|
||||
|
||||
public int getNumObservations() throws Exception;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,4 +143,8 @@ public class EntropyCalculatorMultiVariateKernel implements EntropyCalculatorMul
|
|||
}
|
||||
}
|
||||
|
||||
public int getNumObservations() throws Exception {
|
||||
return totalObservations;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package infodynamics.measures.continuous;
|
||||
package infodynamics.measures.mixed;
|
||||
|
||||
import infodynamics.utils.EmpiricalMeasurementDistribution;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package infodynamics.measures.continuous;
|
||||
package infodynamics.measures.mixed;
|
||||
|
||||
import infodynamics.utils.EmpiricalMeasurementDistribution;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package infodynamics.measures.continuous;
|
||||
package infodynamics.measures.mixed;
|
||||
|
||||
import infodynamics.utils.EmpiricalMeasurementDistribution;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue