Uploaded image for project: 'Commons Statistics'
  1. Commons Statistics
  2. STATISTICS-56

Add stream functions to the Sampler interfaces

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Trivial
    • Resolution: Implemented
    • 1.0
    • 1.0
    • distribution
    • 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();
      

      Attachments

        Activity

          People

            aherbert Alex Herbert
            aherbert Alex Herbert
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: