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 20:43:00 UTC
[jira] [Created] (STATISTICS-56) Add stream functions to the Sampler interfaces
Alex Herbert created STATISTICS-56:
--------------------------------------
Summary: 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
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)