You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2011/03/28 00:06:19 UTC
svn commit: r1086057 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java
test/java/org/apache/commons/math/stat/correlation/PearsonsCorrelationTest.java
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);
Re: svn commit: r1086057 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java
test/java/org/apache/commons/math/stat/correlation/PearsonsCorrelationTest.java
Posted by Luc Maisonobe <Lu...@free.fr>.
Le 29/03/2011 17:16, sebb a écrit :
> On 29 March 2011 16:01, Gilles Sadowski <gi...@harfang.homelinux.org> wrote:
>>>>>> 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);
>>>> As is, it is not clear (from a design point-of-view) that it would make
>>>> sense to override the method (hence the legitimate request to make it
>>>> static). If polymorphism is really the intention, I think that it would
>>>> be worth adding an interface ("Correlation" maybe?).
>>>
>>> We have been talking about moving away from interfaces as the
>>> preferred way to support people plugging in alternative
>>> implementations because they have in several places gotten "behind"
>>> due to the fact that adding anything to them breaks compatibility.
>>> We should probably continue that discussion in a different thread.
>>
>> OK, comments kept for a separate thread...
>>
>>>
>>> The method above is the core of the implementation
>>
>> One is left wondering why the "core" does not need anything else from the
>> class (no fields, no methods); it is self-sufficient (hence the legitimate
>> request for making it static).
Even without field or method, it may be interesting to have instances to
distinguish classes. The added benefit is that when we add methods, we
can do so in upward compatible ways.
>>
>>> and making it
>>> static means that you can't extend this class using a different
>>> implementation.
>>
>> Is that a problem (other than the practical one you invoke just below).
>>
>>> It also breaks all existing code using the class.
>>> There are lots of other examples in [math] - throughout Commons
>>> actually - where methods *could* be static, but are not because we
>>> want to preserve the ability for ourselves or users to extend the
>>> classes and override the methods.
>>
>> The issue which I'm raising is whether it is functionally clearer (as in
>> "How the class is _supposed_ to be used") to have (or not) a static method.
>> If the common case is inheritance (of which there is no example in CM) then
>> there must be an interface to single out the "core" functionality.
>
> Insisting on an interface means updates are binary incompatible unless
> the interface is for internal use only.
>
> AFAICT, the only way to ensure bin.com. is to provide a base class
> (probably abstract) which users can subclass.
>
> Or, one has to add an new interface for each new API, and one would
> probably still need a base class.
>
> It's very difficult getting an interface right the first time.
Yes, the 2.X fiasco clearly shows that. We failed miserably on some
interfaces.
>
>> If instead, we focus on the specificity of the implementation, a user can
>> always "extend" the functionality by composition (i.e. his new class will
>> wrap a call to the static "PearsonsCorrelation.correlation" method).
We often want the inheritance to be visible and public, not hidden and
wrapped.
Luc
>>
>>> All of the evaluate() methods,
>>> for example, in the individual descriptive statistics, for example,
>>> could be static. Convenience methods are provided in StatUtils to
>>> support static invocation. I think a CorrelationUtils class for
>>> this, Covariance and Spearman's - which all have core implementation
>>> methods that "could" be static - is a better approach if we feel
>>> that we need to provide support for the procedural API style here.
>>
>> That's not only an issue of providing procedural style API.
>>
>>
>> Gilles
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1086057 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java test/java/org/apache/commons/math/stat/correlation/PearsonsCorrelationTest.java
Posted by sebb <se...@gmail.com>.
On 29 March 2011 16:01, Gilles Sadowski <gi...@harfang.homelinux.org> wrote:
>> >>> 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);
>> > As is, it is not clear (from a design point-of-view) that it would make
>> > sense to override the method (hence the legitimate request to make it
>> > static). If polymorphism is really the intention, I think that it would
>> > be worth adding an interface ("Correlation" maybe?).
>>
>> We have been talking about moving away from interfaces as the
>> preferred way to support people plugging in alternative
>> implementations because they have in several places gotten "behind"
>> due to the fact that adding anything to them breaks compatibility.
>> We should probably continue that discussion in a different thread.
>
> OK, comments kept for a separate thread...
>
>>
>> The method above is the core of the implementation
>
> One is left wondering why the "core" does not need anything else from the
> class (no fields, no methods); it is self-sufficient (hence the legitimate
> request for making it static).
>
>> and making it
>> static means that you can't extend this class using a different
>> implementation.
>
> Is that a problem (other than the practical one you invoke just below).
>
>> It also breaks all existing code using the class.
>> There are lots of other examples in [math] - throughout Commons
>> actually - where methods *could* be static, but are not because we
>> want to preserve the ability for ourselves or users to extend the
>> classes and override the methods.
>
> The issue which I'm raising is whether it is functionally clearer (as in
> "How the class is _supposed_ to be used") to have (or not) a static method.
> If the common case is inheritance (of which there is no example in CM) then
> there must be an interface to single out the "core" functionality.
Insisting on an interface means updates are binary incompatible unless
the interface is for internal use only.
AFAICT, the only way to ensure bin.com. is to provide a base class
(probably abstract) which users can subclass.
Or, one has to add an new interface for each new API, and one would
probably still need a base class.
It's very difficult getting an interface right the first time.
> If instead, we focus on the specificity of the implementation, a user can
> always "extend" the functionality by composition (i.e. his new class will
> wrap a call to the static "PearsonsCorrelation.correlation" method).
>
>> All of the evaluate() methods,
>> for example, in the individual descriptive statistics, for example,
>> could be static. Convenience methods are provided in StatUtils to
>> support static invocation. I think a CorrelationUtils class for
>> this, Covariance and Spearman's - which all have core implementation
>> methods that "could" be static - is a better approach if we feel
>> that we need to provide support for the procedural API style here.
>
> That's not only an issue of providing procedural style API.
>
>
> Gilles
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1086057 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java
test/java/org/apache/commons/math/stat/correlation/PearsonsCorrelationTest.java
Posted by Phil Steitz <ph...@gmail.com>.
On 3/29/11 8:01 AM, Gilles Sadowski wrote:
>>>>> 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);
>>> As is, it is not clear (from a design point-of-view) that it would make
>>> sense to override the method (hence the legitimate request to make it
>>> static). If polymorphism is really the intention, I think that it would
>>> be worth adding an interface ("Correlation" maybe?).
>> We have been talking about moving away from interfaces as the
>> preferred way to support people plugging in alternative
>> implementations because they have in several places gotten "behind"
>> due to the fact that adding anything to them breaks compatibility.
>> We should probably continue that discussion in a different thread.
> OK, comments kept for a separate thread...
>
>> The method above is the core of the implementation
> One is left wondering why the "core" does not need anything else from the
> class (no fields, no methods); it is self-sufficient (hence the legitimate
> request for making it static).
It *is* the core method. It does not require instance data. This
is very common in [math]. What it encapsulates is the core
algorithm. Eliminating the possibility of overriding that is a bad
idea, IMO, since it effectively makes the class a dead end. Looked
at in another way, I would not make that method final or the class
final, since I can imagine scenarios where users might want to swap
out the implementation of the core method while maintaining the rest
of the functionality of the class. There is no need to put this
restriction on users or to break all of the existing users, so I do
not think it is a good idea to make the method static.
Phil
>> and making it
>> static means that you can't extend this class using a different
>> implementation.
> Is that a problem (other than the practical one you invoke just below).
Yes, it is generally considered bad design, since it makes it
impossible for users to override the behavior in subclasses.
>> It also breaks all existing code using the class.
>> There are lots of other examples in [math] - throughout Commons
>> actually - where methods *could* be static, but are not because we
>> want to preserve the ability for ourselves or users to extend the
>> classes and override the methods.
> The issue which I'm raising is whether it is functionally clearer (as in
> "How the class is _supposed_ to be used") to have (or not) a static method.
> If the common case is inheritance (of which there is no example in CM) then
> there must be an interface to single out the "core" functionality.
> If instead, we focus on the specificity of the implementation, a user can
> always "extend" the functionality by composition (i.e. his new class will
> wrap a call to the static "PearsonsCorrelation.correlation" method).
>
Or just add a utils class to bundle the static methods if we really
think we need them. This is consistent with design elsewhere in [math].
Phil
>> All of the evaluate() methods,
>> for example, in the individual descriptive statistics, for example,
>> could be static. Convenience methods are provided in StatUtils to
>> support static invocation. I think a CorrelationUtils class for
>> this, Covariance and Spearman's - which all have core implementation
>> methods that "could" be static - is a better approach if we feel
>> that we need to provide support for the procedural API style here.
> That's not only an issue of providing procedural style API.
>
>
> Gilles
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1086057 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java
test/java/org/apache/commons/math/stat/correlation/PearsonsCorrelationTest.java
Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
> >>> 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);
> > As is, it is not clear (from a design point-of-view) that it would make
> > sense to override the method (hence the legitimate request to make it
> > static). If polymorphism is really the intention, I think that it would
> > be worth adding an interface ("Correlation" maybe?).
>
> We have been talking about moving away from interfaces as the
> preferred way to support people plugging in alternative
> implementations because they have in several places gotten "behind"
> due to the fact that adding anything to them breaks compatibility.
> We should probably continue that discussion in a different thread.
OK, comments kept for a separate thread...
>
> The method above is the core of the implementation
One is left wondering why the "core" does not need anything else from the
class (no fields, no methods); it is self-sufficient (hence the legitimate
request for making it static).
> and making it
> static means that you can't extend this class using a different
> implementation.
Is that a problem (other than the practical one you invoke just below).
> It also breaks all existing code using the class.
> There are lots of other examples in [math] - throughout Commons
> actually - where methods *could* be static, but are not because we
> want to preserve the ability for ourselves or users to extend the
> classes and override the methods.
The issue which I'm raising is whether it is functionally clearer (as in
"How the class is _supposed_ to be used") to have (or not) a static method.
If the common case is inheritance (of which there is no example in CM) then
there must be an interface to single out the "core" functionality.
If instead, we focus on the specificity of the implementation, a user can
always "extend" the functionality by composition (i.e. his new class will
wrap a call to the static "PearsonsCorrelation.correlation" method).
> All of the evaluate() methods,
> for example, in the individual descriptive statistics, for example,
> could be static. Convenience methods are provided in StatUtils to
> support static invocation. I think a CorrelationUtils class for
> this, Covariance and Spearman's - which all have core implementation
> methods that "could" be static - is a better approach if we feel
> that we need to provide support for the procedural API style here.
That's not only an issue of providing procedural style API.
Gilles
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1086057 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java
test/java/org/apache/commons/math/stat/correlation/PearsonsCorrelationTest.java
Posted by Phil Steitz <ph...@gmail.com>.
On 3/29/11 4:43 AM, Gilles Sadowski wrote:
> On Sun, Mar 27, 2011 at 05:25:59PM -0700, Phil Steitz wrote:
>> 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, erans@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);
> As is, it is not clear (from a design point-of-view) that it would make
> sense to override the method (hence the legitimate request to make it
> static). If polymorphism is really the intention, I think that it would
> be worth adding an interface ("Correlation" maybe?).
We have been talking about moving away from interfaces as the
preferred way to support people plugging in alternative
implementations because they have in several places gotten "behind"
due to the fact that adding anything to them breaks compatibility.
We should probably continue that discussion in a different thread.
The method above is the core of the implementation and making it
static means that you can't extend this class using a different
implementation. It also breaks all existing code using the class.
There are lots of other examples in [math] - throughout Commons
actually - where methods *could* be static, but are not because we
want to preserve the ability for ourselves or users to extend the
classes and override the methods. All of the evaluate() methods,
for example, in the individual descriptive statistics, for example,
could be static. Convenience methods are provided in StatUtils to
support static invocation. I think a CorrelationUtils class for
this, Covariance and Spearman's - which all have core implementation
methods that "could" be static - is a better approach if we feel
that we need to provide support for the procedural API style here.
Phil
>
> Gilles
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1086057 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java
test/java/org/apache/commons/math/stat/correlation/PearsonsCorrelationTest.java
Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
On Sun, Mar 27, 2011 at 05:25:59PM -0700, Phil Steitz wrote:
> 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, erans@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);
As is, it is not clear (from a design point-of-view) that it would make
sense to override the method (hence the legitimate request to make it
static). If polymorphism is really the intention, I think that it would
be worth adding an interface ("Correlation" maybe?).
Gilles
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1086057 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java
test/java/org/apache/commons/math/stat/correlation/PearsonsCorrelationTest.java
Posted by Phil Steitz <ph...@gmail.com>.
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, erans@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-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org