Class SyncedEnumeratedDistro<T>

  • Type Parameters:
    T - The type to be returned when sampling from the distribiution.
    All Implemented Interfaces:
    java.io.Serializable

    public class SyncedEnumeratedDistro<T>
    extends org.apache.commons.math3.distribution.EnumeratedDistribution
    Class that wraps EnumeratedDistribution for thread safe use in Synthea. In several places in Synthea, EnumeratedDistributions are used following a singleton pattern. One distribution is used in a particular aspect of simulation. To support reproducibility of simulations, its source of randomness is reseeded for each individual. Since multiple threads may be accessing the distribution at the same time, it would be possible to reseed the distribution in one thread but sample on that seed in another thread. This class offers a synchronized method to prevent that with the handy side benefit that it takes the well-known and loved Synthea Person as a source of randomness.
    See Also:
    Serialized Form
    • Field Summary

      • Fields inherited from class org.apache.commons.math3.distribution.EnumeratedDistribution

        random
    • Constructor Summary

      Constructors 
      Constructor Description
      SyncedEnumeratedDistro​(java.util.List<org.apache.commons.math3.util.Pair<T,​java.lang.Double>> pmf)
      Just calls super.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T syncedReseededSample​(Person person)
      Sample from the distribution after it has been reseeded using the Person provided as a source of randomness.
      • Methods inherited from class org.apache.commons.math3.distribution.EnumeratedDistribution

        getPmf, reseedRandomGenerator, sample, sample, sample
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SyncedEnumeratedDistro

        public SyncedEnumeratedDistro​(java.util.List<org.apache.commons.math3.util.Pair<T,​java.lang.Double>> pmf)
                               throws org.apache.commons.math3.exception.NotPositiveException,
                                      org.apache.commons.math3.exception.MathArithmeticException,
                                      org.apache.commons.math3.exception.NotFiniteNumberException,
                                      org.apache.commons.math3.exception.NotANumberException
        Just calls super. Look at the docs for EnumeratedDistributed for more details.
        Parameters:
        pmf - List of pairs of values and their weight in the distribution.
        Throws:
        org.apache.commons.math3.exception.NotPositiveException
        org.apache.commons.math3.exception.MathArithmeticException
        org.apache.commons.math3.exception.NotFiniteNumberException
        org.apache.commons.math3.exception.NotANumberException
    • Method Detail

      • syncedReseededSample

        public T syncedReseededSample​(Person person)
        Sample from the distribution after it has been reseeded using the Person provided as a source of randomness.
        Parameters:
        person - Where the randomness comes from
        Returns:
        a value from the distribution based on a weighted, random selection