I would prefer not to make that method static, since that means it cannot be overridden and it is used internally in this class as well as Spearman's. If we want to provide a convenience method with static signature, we should add it to StatUtils or create a CorrelationUtils class to bundle static methods such as this and similar for Covariance, Spearman's etc.
Phil On 3/27/11 3:06 PM, er...@apache.org wrote: > Author: erans > Date: Sun Mar 27 22:06:18 2011 > New Revision: 1086057 > > URL: http://svn.apache.org/viewvc?rev=1086057&view=rev > Log: > MATH-549 > Method can be "static". > > Modified: > > commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java > > commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/correlation/PearsonsCorrelationTest.java > > Modified: > commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java > URL: > http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java?rev=1086057&r1=1086056&r2=1086057&view=diff > ============================================================================== > --- > commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java > (original) > +++ > commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java > Sun Mar 27 22:06:18 2011 > @@ -225,7 +225,8 @@ public class PearsonsCorrelation { > * @throws IllegalArgumentException if the arrays lengths do not match > or > * there is insufficient data > */ > - public double correlation(final double[] xArray, final double[] yArray) > throws IllegalArgumentException { > + public static double correlation(final double[] xArray, final double[] > yArray) > + throws IllegalArgumentException { > SimpleRegression regression = new SimpleRegression(); > if (xArray.length != yArray.length) { > throw new DimensionMismatchException(xArray.length, > yArray.length); > > Modified: > commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/correlation/PearsonsCorrelationTest.java > URL: > http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/correlation/PearsonsCorrelationTest.java?rev=1086057&r1=1086056&r2=1086057&view=diff > ============================================================================== > --- > commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/correlation/PearsonsCorrelationTest.java > (original) > +++ > commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/correlation/PearsonsCorrelationTest.java > Sun Mar 27 22:06:18 2011 > @@ -194,7 +194,7 @@ public class PearsonsCorrelationTest { > public void testConstant() { > double[] noVariance = new double[] {1, 1, 1, 1}; > double[] values = new double[] {1, 2, 3, 4}; > - Assert.assertTrue(Double.isNaN(new > PearsonsCorrelation().correlation(noVariance, values))); > + > Assert.assertTrue(Double.isNaN(PearsonsCorrelation.correlation(noVariance, > values))); > } > > > @@ -207,7 +207,7 @@ public class PearsonsCorrelationTest { > double[] one = new double[] {1}; > double[] two = new double[] {2}; > try { > - new PearsonsCorrelation().correlation(one, two); > + PearsonsCorrelation.correlation(one, two); > Assert.fail("Expecting IllegalArgumentException"); > } catch (IllegalArgumentException ex) { > // Expected > @@ -277,7 +277,7 @@ public class PearsonsCorrelationTest { > double[][] data = matrix.getData(); > double[] x = matrix.getColumn(0); > double[] y = matrix.getColumn(1); > - Assert.assertEquals(new PearsonsCorrelation().correlation(x, y), > + Assert.assertEquals(PearsonsCorrelation.correlation(x, y), > corrInstance.getCorrelationMatrix().getEntry(0, 1), > Double.MIN_VALUE); > TestUtils.assertEquals("Correlation matrix", > corrInstance.getCorrelationMatrix(), > new PearsonsCorrelation().computeCorrelationMatrix(data), > Double.MIN_VALUE); > > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org