[ https://issues.apache.org/jira/browse/MATH1205?page=com.atlassian.jira.plugin.system.issuetabpanels:commenttabpanel&focusedCommentId=14330465#comment14330465
]
Thomas Neidhart commented on MATH1205:

I am working on a patch, but there are at least two other odd things that I have seen wrt
storeless statistics:
a) default implementation of equals / hashCode that compares solely on getResult() and getN():
I fail to see a usecase for this and it means that two different types of storeless statistics
are considered to be equal if their current state is equal:
{code}
Mean m = new Mean();
Variance v = new Variance();
System.out.println(m.equals(v)); // outputs true
{code}
I find this very strange, especially as a default.
b) evaluate(double[], ...): the default implementation in AbstractStorelessUnivariateStatistic
does the following:
* clear the internal result
* call increment for all input values in the array
* return the result
thus the method alters the internal state, which is different for nonstoreless statistics.
Some storeless statistics override this method, e.g. Mean to do something else: calculate
the result using an intermediate object and then return the result without altering state.
This is quite confusing imho.
> AbstractStorelessUnivariateStatistic should not extend AbstractUnivariateStatistic
> 
>
> Key: MATH1205
> URL: https://issues.apache.org/jira/browse/MATH1205
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 3.4.1
> Reporter: Thomas Neidhart
>
> For a storeless statistic it is wrong to extend AbstractUnivariateStatistic as various
fields and methods are inherited that do not make sense in case of a storeless statistic.
> This means a user can accidentially use a storeless statistic in a wrong way:
> {code}
> Mean mean = new Mean();
>
> mean.increment(1);
> mean.increment(2);
>
> mean.setData(new double[] { 1, 2, 3});
>
> System.out.println(mean.getResult());
> System.out.println(mean.evaluate());
> {code}
> will output
> {noformat}
> 1.5
> 2.0
> {noformat}

This message was sent by Atlassian JIRA
(v6.3.4#6332)
