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 2022/10/15 07:56:00 UTC

[jira] [Resolved] (STATISTICS-56) Add stream functions to the Sampler interfaces

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

Alex Herbert resolved STATISTICS-56.
------------------------------------
    Resolution: Implemented

> Add stream functions to the Sampler interfaces
> ----------------------------------------------
>
>                 Key: STATISTICS-56
>                 URL: https://issues.apache.org/jira/browse/STATISTICS-56
>             Project: Commons Statistics
>          Issue Type: New Feature
>          Components: distribution
>    Affects Versions: 1.0
>            Reporter: Alex Herbert
>            Assignee: Alex Herbert
>            Priority: Trivial
>             Fix For: 1.0
>
>
> Add default stream methods to the distribution sampler interfaces, for example:
> {code:java}
> public interface ContinuousDistribution {
>     // ...
>     Sampler createSampler(UniformRandomProvider rng);
>     /**
>      * Sampling functionality.
>      */
>     interface Sampler {
>         double sample();
>         default DoubleStream samples() {
>             return DoubleStream.generate(this::sample).sequential();
>         }
>         default DoubleStream samples(long streamSize) {
>             return samples().limit(streamSize);
>         }
>     }
> }
> {code}
> This allows easy sample generation from a distribution:
> {code:java}
> UniformRandomProvider rng = ...;
> double[] x = NormalDistribution.of(1.23, 4.56)
>                                .createSampler(rng)
>                                .samples(100)
>                                .toArray();
> {code}



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