[ https://issues.apache.org/jira/browse/MATH-1684?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Ruiqi Dong updated MATH-1684: ----------------------------- Priority: Minor (was: Major) > 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)