RankCounter { public static int[][] rank(final double[][] data) { final int n = data.length; final int m = data[0].length; final int count[][] = new int[n][n]; for (int i = 0; i < m; ++i) { double x[] = new double[n]; for (int j = 0; j < n; ++j) { x[j] = data[j][i]; } int ranks[] = rank(x); for (int j = 0; j < n; ++j) { count[j][ranks[j] - 1] += 1; } } return count; }  static int[][] rank(final double[][] data); static int[] rank(double[] data);  }
@Test public void testSingleRanking() { double[] data = new double[] { 1.0, 0.0, 2.0, 0.5, -3.0 }; int[] rank = new int[] { 4, 2, 5, 3, 1 }; assertArrayEquals(rank, RankCounter.rank(data)); }
@Test public void testRepeatedRanking() { double[][] data = new double[][] { {1.0, 2, 1}, {2.0, 1, 3} }; int[][] rank = new int[][] { {2, 1}, {1, 2} }; assertArrayEquals(rank, RankCounter.rank(data)); }