[ 
https://issues.apache.org/jira/browse/MATH-1684?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18004744#comment-18004744
 ] 

Gilles Sadowski commented on MATH-1684:
---------------------------------------

AFAICT, the {{WeightedProduct}} class is not used within "Commons Math".
This makes it a candidate for removal.
At the minimum, this functionality could be transferred to ["Commons 
Numbers"|https://commons.apache.org/proper/commons-numbers/commons-numbers-arrays/javadocs/api-1.2/org/apache/commons/numbers/arrays/package-summary.html],
 where we could perhaps define an API that operates on multiple streams (?), 
which this weighted product would be a particular case.

Please raise this issue on the "dev" ML.

> WeightedProduct should handle all-zero weights according to mathematical 
> definition
> -----------------------------------------------------------------------------------
>
>                 Key: MATH-1684
>                 URL: https://issues.apache.org/jira/browse/MATH-1684
>             Project: Commons Math
>          Issue Type: Improvement
>          Components: legacy
>    Affects Versions: 4.0-beta1
>            Reporter: Ruiqi Dong
>            Priority: Minor
>   Original Estimate: 0.5h
>  Remaining Estimate: 0.5h
>
> The {{WeightedProduct}} class currently throws a 
> {{MathIllegalArgumentException}} when all weights are zero, but 
> mathematically this should return 1.0 as the result.  When calling 
> {{WeightedProduct.evaluate()}} with a weights array containing all zeros, the 
> method throws MathIllegalArgumentException. According to the mathematical 
> definition of weighted product: {{∏ values[i]^weights[i]. }}When all weights 
> are 0, this becomes: {{∏ values[i]^0 = ∏ 1 = 1.}}
> {{}}
> *Root Cause:* The issue occurs because {{WeightedProduct.evaluate()}} calls 
> {{MathArrays.verifyValues(values, weights, begin, length, true)}} where the 
> last parameter requires at least one non-zero weight. This validation is 
> appropriate for some weighted operations (like weighted mean) but is 
> unnecessarily restrictive for weighted product.{{{}{}}}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to