Covariance { public RealMatrix getCovarianceMatrix() { return covarianceMatrix; } Covariance();  Covariance(double[][] data, boolean biasCorrected);  Covariance(double[][] data);  Covariance(RealMatrix matrix, boolean biasCorrected);  Covariance(RealMatrix matrix); RealMatrix getCovarianceMatrix(); int getN(); double covariance(final double[] xArray, final double[] yArray, boolean biasCorrected); double covariance(final double[] xArray, final double[] yArray);  }
@Test public void testLongly() { RealMatrix matrix = createRealMatrix(longleyData, 16, 7); RealMatrix covarianceMatrix = new Covariance(matrix).getCovarianceMatrix(); double[] rData = new double[] { 12333921.73333333246, 3.679666000000000e+04, 343330206.333333313, 1649102.666666666744, 1117681.066666666651, 23461965.733333334, 16240.93333333333248, 36796.66000000000, 1.164576250000000e+02, 1063604.115416667, 6258.666250000000, 3490.253750000000, 73503.000000000, 50.92333333333334, 343330206.33333331347, 1.063604115416667e+06, 9879353659.329166412, 56124369.854166664183, 30880428.345833335072, 685240944.600000024, 470977.90000000002328, 1649102.66666666674, 6.258666250000000e+03, 56124369.854166664, 873223.429166666698, -115378.762499999997, 4462741.533333333, 2973.03333333333330, 1117681.06666666665, 3.490253750000000e+03, 30880428.345833335, -115378.762499999997, 484304.095833333326, 1764098.133333333, 1382.43333333333339, 23461965.73333333433, 7.350300000000000e+04, 685240944.600000024, 4462741.533333333209, 1764098.133333333302, 48387348.933333330, 32917.40000000000146, 16240.93333333333, 5.092333333333334e+01, 470977.900000000, 2973.033333333333, 1382.433333333333, 32917.40000000, 22.66666666666667 }; TestUtils.assertEquals("covariance matrix", createRealMatrix(rData, 7, 7), covarianceMatrix, 10E-9); }
@Test public void testSwissFertility() { RealMatrix matrix = createRealMatrix(swissData, 47, 5); RealMatrix covarianceMatrix = new Covariance(matrix).getCovarianceMatrix(); double[] rData = new double[] { 156.0424976873265, 100.1691489361702, -64.36692876965772, -79.7295097132285, 241.5632030527289, 100.169148936170251, 515.7994172062905, -124.39283071230344, -139.6574005550416, 379.9043755781684, -64.3669287696577, -124.3928307123034, 63.64662349676226, 53.5758556891767, -190.5606105457909, -79.7295097132285, -139.6574005550416, 53.57585568917669, 92.4560592044403, -61.6988297872340, 241.5632030527289, 379.9043755781684, -190.56061054579092, -61.6988297872340, 1739.2945371877890 }; TestUtils.assertEquals("covariance matrix", createRealMatrix(rData, 5, 5), covarianceMatrix, 10E-13); }
@Test public void testOneColumn() { RealMatrix cov = new Covariance(new double[][] {{1}, {2}}, false).getCovarianceMatrix(); Assert.assertEquals(1, cov.getRowDimension()); Assert.assertEquals(1, cov.getColumnDimension()); Assert.assertEquals(0.25, cov.getEntry(0, 0), 1.0e-15); }