Added new unit test for Kraskov MI calculator against MILCA for large 10000 data points of dimension 5 in each x and y; added unit tests for digamma

This commit is contained in:
joseph.lizier 2013-03-07 12:50:03 +00:00
parent 16cc8e3db2
commit bc218e291c
2 changed files with 58 additions and 2 deletions

View File

@ -90,6 +90,7 @@ public class MutualInfoMultiVariateTester
//miCalc.setProperty(MutualInfoCalculatorMultiVariateKraskov.PROP_NORM_TYPE,
// EuclideanUtils.NORM_MAX_NORM_STRING);
miCalc.setObservations(var1, var2);
//miCalc.setDebug(true);
double mi = miCalc.computeAverageLocalOfObservations();
//miCalc.setDebug(false);
@ -302,7 +303,7 @@ public class MutualInfoMultiVariateTester
*/
public void testMultivariateMIforNoisyDependentVariablesFromFile() throws Exception {
// Test set 6:
// Test set 7:
// We'll just take the first two columns from this data set
ArrayFileReader afr = new ArrayFileReader("demos/data/4ColsPairedNoisyDependence-1.txt");
@ -314,11 +315,42 @@ public class MutualInfoMultiVariateTester
double[] expectedFromMILCA_2 = {0.33738970, 0.36251531, 0.34708687,
0.36200563, 0.35766125, 0.35007623, 0.35023664, 0.33728287};
System.out.println("Kraskov comparison 6 - multivariate dependent data 1");
System.out.println("Kraskov comparison 7 - multivariate dependent data 1");
checkMIForGivenData(MatrixUtils.selectColumns(data, new int[] {0, 1}),
MatrixUtils.selectColumns(data, new int[] {2, 3}),
kNNs, expectedFromMILCA_2);
}
/**
* Test the computed multivariate MI against that calculated by Kraskov's own MILCA
* tool on the same data.
*
* To run Kraskov's tool (http://www.klab.caltech.edu/~kraskov/MILCA/) for this
* data, run:
* ./MIxnyn <dataFile> 5 5 10000 <kNearestNeighbours> 0
*
* @throws Exception if file not found
*
*/
public void testMultivariateMIforRandomGaussianVariablesFromFile() throws Exception {
// Test set 8:
// We'll take the columns from this data set
ArrayFileReader afr = new ArrayFileReader("demos/data/10ColsRandomGaussian-1.txt");
double[][] data = afr.getDouble2DMatrix();
// Use various Kraskov k nearest neighbours parameter
int[] kNNs = {1, 2, 4, 10, 15};
// Expected values from Kraskov's MILCA toolkit:
double[] expectedFromMILCA_2 = {0.00815609, 0.00250864, 0.00035825,
0.00172174, 0.00033354};
System.out.println("Kraskov comparison 8 - multivariate uncorrelated Gaussian data 1");
checkMIForGivenData(MatrixUtils.selectColumns(data, new int[] {0, 1, 2, 3, 4}),
MatrixUtils.selectColumns(data, new int[] {5, 6, 7, 8, 9}),
kNNs, expectedFromMILCA_2);
}
}

View File

@ -341,4 +341,28 @@ public class MathsUtilsTest extends TestCase {
0.000001);
}
public void testDigamma() throws Exception {
assertEquals(-0.577216, MathsUtils.digamma(1), 0.000001);
assertEquals(0.42278, MathsUtils.digamma(2), 0.00001);
assertEquals(2.2518, MathsUtils.digamma(10), 0.0001);
assertEquals(4.6002, MathsUtils.digamma(100), 0.0001);
assertEquals(6.9073, MathsUtils.digamma(1000), 0.0001);
// Test calling for values above the range that we cache
assertEquals(9.2103, MathsUtils.digamma(10000), 0.0001);
assertEquals(9.2104, MathsUtils.digamma(10001), 0.0001);
// Test retrieving a cached value
assertEquals(5.2958, MathsUtils.digamma(200), 0.0001);
// And test manually calculated digammas:
assertEquals(-0.577216, MathsUtils.digammaByDefinition(1), 0.000001);
assertEquals(0.42278, MathsUtils.digammaByDefinition(2), 0.00001);
assertEquals(2.2518, MathsUtils.digammaByDefinition(10), 0.0001);
assertEquals(4.6002, MathsUtils.digammaByDefinition(100), 0.0001);
assertEquals(6.9073, MathsUtils.digammaByDefinition(1000), 0.0001);
// Test calling for values above the range that we cache
assertEquals(9.2103, MathsUtils.digammaByDefinition(10000), 0.0001);
assertEquals(9.2104, MathsUtils.digammaByDefinition(10001), 0.0001);
// Test retrieving a cached value
assertEquals(5.2958, MathsUtils.digammaByDefinition(200), 0.0001);
}
}