For Conditional MI calculators (sontinuous), adding setObservations and addObservations method signatures which take univariate arrays (only work if initialised dimensionalities are univariate) into the interface, and the common base class. This is in preparation for the CMI AutoAnalyser

This commit is contained in:
jlizier 2017-08-22 21:26:44 +10:00
parent 7972e03420
commit 4db008ce33
2 changed files with 74 additions and 0 deletions

View File

@ -114,6 +114,29 @@ public interface ConditionalMutualInfoCalculatorMultiVariate
public void setObservations(double[][] var1, double[][] var2,
double[][] cond) throws Exception;
/**
* Sets a single series from which to compute the PDF.
* Cannot be called in conjunction with
* {@link #startAddObservations()} / {@link #addObservations(double[][], double[][], double[][])} or
* {@link #addObservations(double[][], double[][], double[][], int, int)} /
* {@link #finaliseAddObservations()}.</p>
*
* <p>The supplied series may be (multivariate) time-series or
* simply a set of separate observations without a time interpretation.
*
* <p>This method can only be used where dimensions of all
* variables have been set to 1.</p>
*
* @param var1 univariate observations for variable 1
* @param var2 univariate observations for variable 2
* Length must match <code>var1</code>, and their indices must correspond.
* @param cond univariate observations for the conditional
* Length must match <code>var1</code>, and their indices must correspond.
* @throws Exception
*/
public void setObservations(double[] var1, double[] var2,
double[] cond) throws Exception;
/**
* Sets a single series from which to compute the PDF,
* where all the various observations are valid.
@ -210,6 +233,31 @@ public interface ConditionalMutualInfoCalculatorMultiVariate
public void addObservations(double[][] var1, double[][] var2,
double[][] cond) throws Exception;
/**
* <p>Adds a new set of observations to update the PDFs with - is
* intended to be called multiple times.
* Must be called after {@link #startAddObservations()}; call
* {@link #finaliseAddObservations()} once all observations have
* been supplied.</p>
*
* <p>Note that the arrays must not be over-written by the user
* until after finaliseAddObservations() has been called
* (they are not copied by this method necessarily, but the method
* may simply hold a pointer to them).</p>
*
* <p>This method can only be used where dimensions of all
* variables have been set to 1.</p>
*
* @param var1 univariate observations for variable 1
* @param var2 univariate observations for variable 2
* Length must match <code>var1</code>, and their indices must correspond.
* @param cond univariate observations for the conditional
* Length must match <code>var1</code>, and their indices must correspond.
* @throws Exception
*/
public void addObservations(double[] var1, double[] var2,
double[] cond) throws Exception;
/**
* <p>Adds a new sub-series of observations to update the PDFs with - is
* intended to be called multiple times.

View File

@ -237,6 +237,15 @@ public abstract class ConditionalMutualInfoMultiVariateCommon implements
addedMoreThanOneObservationSet = false;
}
@Override
public void setObservations(double[] var1, double[] var2,
double[] cond) throws Exception {
startAddObservations();
addObservations(var1, var2, cond);
finaliseAddObservations();
addedMoreThanOneObservationSet = false;
}
@Override
public void startAddObservations() {
vectorOfVar1Observations = new Vector<double[][]>();
@ -276,6 +285,23 @@ public abstract class ConditionalMutualInfoMultiVariateCommon implements
}
}
@Override
public void addObservations(double[] var1, double[] var2,
double[] cond) throws Exception {
if ((dimensionsVar1 != 1) || (dimensionsVar2 != 1) ||
(dimensionsCond != 1)) {
throw new Exception("The number of dimensions for each variable (having been initialised to " +
dimensionsVar1 + ", " + dimensionsVar2 + " & " +
dimensionsCond + ") can only be 1 when " +
"the univariate addObservations(double[],double[],double[]) and " +
"setObservations(double[],double[],double[]) methods are called");
}
addObservations(MatrixUtils.reshape(var1, var1.length, 1),
MatrixUtils.reshape(var2, var2.length, 1),
MatrixUtils.reshape(cond, cond.length, 1));
}
@Override
public void addObservations(double[][] var1, double[][] var2,
double[][] cond,