Details
-
New Feature
-
Status: Closed
-
Trivial
-
Resolution: Implemented
-
1.0
-
None
-
Easy
Description
Add default stream methods to the distribution sampler interfaces, for example:
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); } } }
This allows easy sample generation from a distribution:
UniformRandomProvider rng = ...;
double[] x = NormalDistribution.of(1.23, 4.56)
.createSampler(rng)
.samples(100)
.toArray();