Uploaded image for project: 'Commons RNG'
  1. Commons RNG
  2. RNG-102

SharedStateSampler interface

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Minor
    • Resolution: Implemented
    • 1.3
    • 1.3
    • sampling
    • None

    Description

      Nearly all the samplers in the library compute data during construction that is immutable. In most cases the data is small in size but could be large (e.g. a discrete probability sampler with a stored cumulative probability table). To build another sampler with the same parameters will have to re-compute this state. The only difference between the two samplers is the random generator.

      Reusing this state to create a duplicate generator is an advantage for lower construction cost and will save memory. This can be done using a generic interface:

      public interface SharedStateSampler<R> {
         R withUniformRandomProvider(UniformRandomProvider rng);
      }
      

      R is expected to be a sampler of some type, e.g.

      public class CollectionSampler<T>
         implements SharedStateSampler<CollectionSampler<T>> {
         // ...
         public CollectionSampler<T>
                 withUniformRandomProvider(UniformRandomProvider rng) {
             return /* new instance that shares the immutable state */;
         }
      }
      

      An example application would be to create a single sampler to be duplicated across threads for parallel computation using a unique RNG per thread.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 40m
                  40m