mirror of https://github.com/jlizier/jidt
Merge pull request #67 from pmediano/master
Add new set- and addObservations overloadings in KSG mixed calculator
This commit is contained in:
commit
fa0bc96a6f
|
|
@ -317,6 +317,13 @@ public class MutualInfoCalculatorMultiVariateWithDiscreteKraskov implements Mutu
|
|||
}
|
||||
}
|
||||
|
||||
public void addObservations(double[] continuousObservations,
|
||||
int[] discreteObservations) throws Exception {
|
||||
double[][] observationsMatrix = new double[continuousObservations.length][1];
|
||||
MatrixUtils.copyIntoColumn(observationsMatrix, 0, continuousObservations);
|
||||
addObservations(observationsMatrix, discreteObservations);
|
||||
}
|
||||
|
||||
public void addObservations(double[][] source, double[][] destination, int startTime, int numTimeSteps) throws Exception {
|
||||
throw new RuntimeException("Not implemented yet");
|
||||
}
|
||||
|
|
@ -444,6 +451,14 @@ public class MutualInfoCalculatorMultiVariateWithDiscreteKraskov implements Mutu
|
|||
finaliseAddObservations();
|
||||
}
|
||||
|
||||
public void setObservations(double[] continuousObservations,
|
||||
int[] discreteObservations) throws Exception {
|
||||
double[][] observationsMatrix = new double[continuousObservations.length][1];
|
||||
MatrixUtils.copyIntoColumn(observationsMatrix, 0, continuousObservations);
|
||||
setObservations(observationsMatrix, discreteObservations);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Internal method to ensure that the Kd-tree data structures to represent the
|
||||
* observational data have been constructed (should be called prior to attempting
|
||||
|
|
|
|||
|
|
@ -269,4 +269,46 @@ public class MutualInfoMultiVariateWithDiscreteKraskovTester extends TestCase {
|
|||
// assertTrue(Math.abs(res5 - res1) > 0.001);
|
||||
|
||||
}
|
||||
|
||||
public void testUnivariateOverloadings() throws Exception {
|
||||
MutualInfoCalculatorMultiVariateWithDiscreteKraskov miCalc =
|
||||
new MutualInfoCalculatorMultiVariateWithDiscreteKraskov();
|
||||
|
||||
// Generate data sets
|
||||
RandomGenerator rg = new RandomGenerator();
|
||||
double[][] contDataMatrix = rg.generateRandomData(100, 2);
|
||||
double[] contDataVector = rg.generateRandomData(100);
|
||||
int[] discData = rg.generateRandomInts(100, 2);
|
||||
|
||||
// Check that no exception is thrown for ok data:
|
||||
boolean caughtException = false;
|
||||
try {
|
||||
miCalc.initialise(1, 2);
|
||||
miCalc.setObservations(contDataVector, discData);
|
||||
} catch (Exception e) {
|
||||
caughtException = true;
|
||||
}
|
||||
assertFalse(caughtException);
|
||||
|
||||
// Check that exception is thrown when dimensions do not match
|
||||
caughtException = false;
|
||||
try {
|
||||
miCalc.initialise(1, 2);
|
||||
miCalc.setObservations(contDataMatrix, discData);
|
||||
} catch (Exception e) {
|
||||
caughtException = true;
|
||||
}
|
||||
assertTrue(caughtException);
|
||||
|
||||
caughtException = false;
|
||||
try {
|
||||
miCalc.initialise(2, 2);
|
||||
miCalc.setObservations(contDataVector, discData);
|
||||
} catch (Exception e) {
|
||||
caughtException = true;
|
||||
}
|
||||
assertTrue(caughtException);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue