KendallsCorrelation { public RealMatrix computeCorrelationMatrix(final RealMatrix matrix) { int nVars = matrix.getColumnDimension(); RealMatrix outMatrix = new BlockRealMatrix(nVars, nVars); for (int i = 0; i < nVars; i++) { for (int j = 0; j < i; j++) { double corr = correlation(matrix.getColumn(i), matrix.getColumn(j)); outMatrix.setEntry(i, j, corr); outMatrix.setEntry(j, i, corr); } outMatrix.setEntry(i, i, 1d); } return outMatrix; } KendallsCorrelation();  KendallsCorrelation(double[][] data);  KendallsCorrelation(RealMatrix matrix); RealMatrix getCorrelationMatrix(); RealMatrix computeCorrelationMatrix(final RealMatrix matrix); RealMatrix computeCorrelationMatrix(final double[][] matrix); double correlation(final double[] xArray, final double[] yArray);  }
@Test public void test2dDoubleArray() { final double[][] input = new double[][] { new double[] {2.0, 1.0, 2.0}, new double[] {1.0, 2.0, 1.0}, new double[] {0.0, 0.0, 0.0} }; final double[][] expected = new double[][] { new double[] {1.0, 1.0 / 3.0, 1.0}, new double[] {1.0 / 3.0, 1.0, 1.0 / 3.0}, new double[] {1.0, 1.0 / 3.0, 1.0}}; Assert.assertEquals(correlation.computeCorrelationMatrix(input), new BlockRealMatrix(expected)); }
@Test public void testBlockMatrix() { final double[][] input = new double[][] { new double[] {2.0, 1.0, 2.0}, new double[] {1.0, 2.0, 1.0}, new double[] {0.0, 0.0, 0.0} }; final double[][] expected = new double[][] { new double[] {1.0, 1.0 / 3.0, 1.0}, new double[] {1.0 / 3.0, 1.0, 1.0 / 3.0}, new double[] {1.0, 1.0 / 3.0, 1.0}}; Assert.assertEquals( correlation.computeCorrelationMatrix(new BlockRealMatrix(input)), new BlockRealMatrix(expected)); }