You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Alex Herbert (Jira)" <ji...@apache.org> on 2026/03/16 17:47:00 UTC

[jira] [Resolved] (STATISTICS-92) TruncatedNormalDistribution rejection-sampler uses incorrect bounds for mirroring check

     [ https://issues.apache.org/jira/browse/STATISTICS-92?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alex Herbert resolved STATISTICS-92.
------------------------------------
    Fix Version/s: 1.3
       Resolution: Fixed

Added in commit:

3c2edbc8365056361328a5e8bdeea36a557466ed

> TruncatedNormalDistribution rejection-sampler uses incorrect bounds for mirroring check
> ---------------------------------------------------------------------------------------
>
>                 Key: STATISTICS-92
>                 URL: https://issues.apache.org/jira/browse/STATISTICS-92
>             Project: Commons Statistics
>          Issue Type: Bug
>          Components: distribution
>    Affects Versions: 1.0
>            Reporter: Kevin Milner
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.3
>
>         Attachments: test.truncatednormal.10.properties, test.truncatednormal.11.properties
>
>
> The rejection sampler implementation of TruncatedNormalDistribution incorrectly uses the original upper and lower bounds rather than the standard normal bounds for the mirroring check; this leads to inaccurate sampling if the original bounds are fully-positive or fully-negative, as well as infinite loops if the bounds are positive but fully below the mean value or are negative but fully above the mean value.
> For example, this will only return samples >1 (even though they should be in the range [0.7, 1.3]:
> {code:java}
> ContinuousDistribution dist = TruncatedNormalDistribution.of(1, 0.1, 0.7, 1.3).createSampler(RandomSource.XO_RO_SHI_RO_128_PP.create(123456l));{code}
> ...and this will get stuck in an infinite loop on the first sampling attempt:
> {code:java}
> ContinuousDistribution dist = TruncatedNormalDistribution.of(1, 0.1, 0.7, 0.99).createSampler(RandomSource.XO_RO_SHI_RO_128_PP.create(123456l));{code}
> Similarly, this will only return samples <1:
> {code:java}
> ContinuousDistribution dist = TruncatedNormalDistribution.of(-1, 0.1, -1.3, -0.7).createSampler(RandomSource.XO_RO_SHI_RO_128_PP.create(123456l));{code}
> ...and this will get stuck in an infinite loop on the first sampling attempt:
> {code:java}
> ContinuousDistribution dist = TruncatedNormalDistribution.of(-1, 0.1, -0.99, -0.7).createSampler(RandomSource.XO_RO_SHI_RO_128_PP.create(123456l));{code}
> The bug seems to have been present since v1.0. It's a simple fix and I will submit a PR imminently.



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