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/13 21:19:00 UTC
[jira] [Commented] (STATISTICS-56) Add stream functions to the Sampler interfaces
[ https://issues.apache.org/jira/browse/STATISTICS-56?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17617303#comment-17617303 ]
Alex Herbert commented on STATISTICS-56:
----------------------------------------
Added in commit:
256f14bf3ec4aa552dcc654f3ac6a9f6650162b8
> 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)