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

XinT commented on MATH-1559:
----------------------------

It happens quite often – whenever the probability p(2) is added to the sum in 
the first or second place in MathArrays.normalizeArray() line 909. Somehow when 
this happens, the sum won't be 1, it'll be 0.999..., then the output is: p(2) * 
1/0.999... = 0.5/0.999... so it's not exactly 0.5. 

!image-2020-10-28-10-32-34-088.png!

I agree that changing the tolerance is not solving this issue directly, it's 
just making the test always pass. It'll take some deeper knowledge about the 
code and the MathArrays module in particular to solve it. 

> testCreateFromDoubles can fail
> ------------------------------
>
>                 Key: MATH-1559
>                 URL: https://issues.apache.org/jira/browse/MATH-1559
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.6.1
>            Reporter: XinT
>            Priority: Minor
>              Labels: pull-request-available, test
>         Attachments: image-2020-10-28-10-32-34-088.png
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> EnumeratedRealDistributionTest.testCreateFromDoubles() can sometimes fail due 
> to a precision problem. More precisely, sometimes distribution.probability(2) 
> equals to 0.5000000000000001, and the assertion assertEquals(0.5, 
> distribution.probability(2), 0) will fail. 
> The deeper reason why this happens is that the call to 
> MathArrays.normalizeArray() in the constructor of EnumeratedDistribution 
> (line 105) can mess up the probability for value 2 by changing it from 
> exactly 0.5 to 0.5000000000000001. 
> Available PR: https://github.com/apache/commons-math/pull/162
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to