[
https://issues.apache.org/jira/browse/STATISTICS-84?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17803485#comment-17803485
]
Alex Herbert commented on STATISTICS-84:
----------------------------------------
Test the current performance for creating a mean.
||Method||Description||
|Mean|Current rolling mean implementation|
|SumMean|A simple sum of values divided by length.|
|ExtendedSumMean|Summation using the Sum class for extended precision, divided
by length|
Results (run using JDK 11.0.21, OpenJDK 64-Bit Server VM, 11.0.21+9 on a
MacBook Pro M2).
||length||name||Score||
|1|Mean|7.3|
|1|SumMean|3.8|
|1|ExtendedSumMean|4.3|
|10|Mean|24.2|
|10|SumMean|5.5|
|10|ExtendedSumMean|8.4|
|1000|Mean|5415.1|
|1000|SumMean|785.1|
|1000|ExtendedSumMean|1005.4|
Using the extended Sum is not much slower than a simple sum. It is much faster
than the rolling sum.
Notes:
The extended sum is used to provide the Sum statistic. Thus if this is used to
compute the mean then it can be reused in the aggregate statistics to provide
both the Sum and Mean statistics when building from an array:
{code:java}
double[] data = {1, 2, 3, 4, 5, 6, 7, 8};
DoubleStatistics stats = DoubleStatistics.of(
EnumSet.of(Statistic.SUM, Statistic.MEAN), data);
{code}
A trial implementation shows that using the extended precision sum improves the
precision of the mean on the current data in the test suite.
> Create the Mean from array input using a summation
> --------------------------------------------------
>
> Key: STATISTICS-84
> URL: https://issues.apache.org/jira/browse/STATISTICS-84
> Project: Commons Statistics
> Issue Type: Improvement
> Components: descriptive
> Reporter: Alex Herbert
> Priority: Trivial
>
> The creation of the Mean from an array uses the rolling mean algorithm. This
> requires a divide for each input value. The algorithm is slow when compared
> to a simple sum of the values and a divide of the sum. The advantage is that
> the algorithm is overflow safe and computes the mean in a single pass (useful
> for streams).
> In the majority of use cases a sum will not overflow. Change the array
> construction to attempt a sum to compute the mean, reverting to the rolling
> mean if this fails.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)