Class DblTruncatedSimple

  • All Implemented Interfaces:
    Serializable, Cloneable

    public class DblTruncatedSimple
    extends DblSequence
    Takes a version of a base stream, where minimum and maximum values are fixed. This is done by returning
    1. minValue whenever the baseStream returns a smaller value,
    2. maxValue, if baseStream returns a larger value
    3. otherwise the baseStream's value is returned as is.
    This method is sometimes called cut-off truncation. Technically this creates a new distribution with a (cumulative) distribution function with a value of 0 for all values smaller than minValue, then following the distribution function of baseStream for the interval [ minValue , maxValue], and having the value 1 for all values larger than maxValue.

    See also Wolfgang Bziuk: Generating random variates from truncated distributions (last accessed 2020-10-26).

    Author:
    Torsten Hildebrandt
    See Also:
    Serialized Form
    • Constructor Detail

      • DblTruncatedSimple

        public DblTruncatedSimple()
      • DblTruncatedSimple

        public DblTruncatedSimple​(DblSequence baseStream,
                                  double min,
                                  double max)
    • Method Detail

      • init

        public void init()
        Description copied from class: DblSequence
        Initializes this stream. This method is supposed to be called once before repeated calls to DblSequence.nextDbl() can be made.
        Overrides:
        init in class DblSequence
      • nextDbl

        public double nextDbl()
        Description copied from class: DblSequence
        Returns the next number in this number stream.
        Specified by:
        nextDbl in class DblSequence
      • getValueRange

        public Pair<Double,​Double> getValueRange()
        Description copied from class: DblSequence
        This method computes the minimum and maximum support values (range of possible values) of this stream.
        Overrides:
        getValueRange in class DblSequence
        Returns:
        A Pair containing the minimum and maximum support values.
      • setBaseStream

        public void setBaseStream​(DblSequence baseStream)
        Sets the stream to be truncated.
        Parameters:
        baseStream - The stream to truncate.
      • getMinValue

        public double getMinValue()
      • setMinValue

        public void setMinValue​(double minValue)
        Sets the minimum value.
        Parameters:
        minValue - The lower bound of allowed values.
      • getMaxValue

        public double getMaxValue()
      • setMaxValue

        public void setMaxValue​(double maxValue)
        Sets the maximum allowed value.
        Parameters:
        maxValue - The upper bound of allowed values.
      • valueInRange

        public static double valueInRange​(double baseValue,
                                          double minValue,
                                          double maxValue)
        Static method to generate a truncated value in the range minValue<=baseValue<=maxValue. Assign NaN to minValue or maxValue if you don't want to have a lower / upper bound.
        Parameters:
        baseValue - The value to check for falling in the desired interval.
        minValue -
        maxValue -
        Returns:
        the truncated value.