Class RandomVariable<T>

java.lang.Object
org.bzdev.math.rv.RandomVariable<T>
All Implemented Interfaces:
Cloneable, RandomVariableOps<T>
Direct Known Subclasses:
BooleanRandomVariable, DoubleRandomVariable, IntegerRandomVariable, LongRandomVariable, RandomVariableRV

public abstract class RandomVariable<T> extends Object implements RandomVariableOps<T>, Cloneable
Random Variable base class. The type parameter T indicates the type of the values that the random number generator generates. Methods allow one to set minimum and maximum values when there is an ordering for the type T. This is useful in cases where one might (for example) compute the square root of a number returned by the random number generator. If a minimum or maximum value is set, values will be generated repeatedly until a value that matches the constraints is obtained.

The interface RandomVariableOps is part of a parallel hierarchy provided so for classes that implement a random variable but that cannot be subclasses of RandomVariable.

  • Constructor Details

    • RandomVariable

      public RandomVariable()
  • Method Details

    • setMinimum

      public void setMinimum(T min, boolean closed) throws UnsupportedOperationException, IllegalArgumentException
      Set the minimum value for a random variable.
      Specified by:
      setMinimum in interface RandomVariableOps<T>
      Parameters:
      min - minimum value.
      closed - true if the minimum value is part of the range; false if it is a lower bound on the range
      Throws:
      UnsupportedOperationException - the random variable's type does not have an order imposed on it or the operation is not supported for implementation reasons
      IllegalArgumentException - an argument is out of range
    • setRequiredMinimum

      protected void setRequiredMinimum(T min, boolean closed) throws UnsupportedOperationException, IllegalArgumentException
      Set a required minimum value for a random variable. Normally this is called by a constructor to prevent a random variable from having values outside a range that makes sense.
      Parameters:
      min - minimum value.
      closed - true if the minimum value is part of the range; false if it is a lower bound on the range
      Throws:
      UnsupportedOperationException - the random variable's type does not have an order imposed on it or the operation is not supported for implementation reasons
      IllegalArgumentException - an argument is out of range
    • tightenMinimum

      public void tightenMinimum(T min, boolean closed) throws UnsupportedOperationException, IllegalArgumentException
      Tighten the minimum value for a random variable. If there is no minimum value, it will be set. Otherwise the minimum of the allowed range will not decrease.
      Specified by:
      tightenMinimum in interface RandomVariableOps<T>
      Parameters:
      min - minimum value.
      closed - true if the minimum value is part of the range; false if it is a lower bound on the range
      Throws:
      UnsupportedOperationException - the random variable's type does not have an order imposed on it or the operation is not supported for implementation reasons
      IllegalArgumentException - an argument is out of range
    • tightenMinimumS

      public abstract void tightenMinimumS(String min, boolean closed) throws UnsupportedOperationException, IllegalArgumentException
      Tighten the minimum value for a random variable given a string. If there is no minimum value, it will be set. Otherwise the minimum of the allowed range will not decrease. The string argument is a number in a format acceptable to the constructors for Integer, Long, or Double as appropriate.
      Specified by:
      tightenMinimumS in interface RandomVariableOps<T>
      Parameters:
      min - minimum value.
      closed - true if the minimum value is part of the range; false if it is a lower bound on the range
      Throws:
      UnsupportedOperationException - the random variable's type does not have an order imposed on it or the operation is not supported for implementation reasons
      IllegalArgumentException - an argument is out of range
    • setMaximum

      public void setMaximum(T max, boolean closed) throws UnsupportedOperationException, IllegalArgumentException
      Set the maximum value for a random variable.
      Specified by:
      setMaximum in interface RandomVariableOps<T>
      Parameters:
      max - maximum value.
      closed - true if the minimum value is part of the range; false if it is a lower bound on the range
      Throws:
      UnsupportedOperationException - the random variable's type does not have an order imposed on it or the operation is not supported for implementation reasons
      IllegalArgumentException - an argument is out of range
    • setRequiredMaximum

      protected void setRequiredMaximum(T max, boolean closed) throws UnsupportedOperationException, IllegalArgumentException
      Set the required maximum value for a random variable. Normally this is called by a constructor to prevent a random variable from having values outside a range that makes sense.
      Parameters:
      max - maximum value.
      closed - true if the minimum value is part of the range; false if it is a lower bound on the range
      Throws:
      UnsupportedOperationException - the random variable's type does not have an order imposed on it or the operation is not supported for implementation reasons
      IllegalArgumentException - an argument is out of range
    • tightenMaximum

      public void tightenMaximum(T max, boolean closed) throws UnsupportedOperationException, IllegalArgumentException
      Tighten the maximum value for a random variable. If there is no maximum value, it will be set. Otherwise the maximum of the allowed range will not increase.
      Specified by:
      tightenMaximum in interface RandomVariableOps<T>
      Parameters:
      max - maximum value.
      closed - true if the minimum value is part of the range; false if it is a lower bound on the range
      Throws:
      UnsupportedOperationException - the random variable's type does not have an order imposed on it or the operation is not supported for implementation reasons
      IllegalArgumentException - an argument is out of range
    • tightenMaximumS

      public abstract void tightenMaximumS(String max, boolean closed) throws UnsupportedOperationException, IllegalArgumentException
      Tighten the maximum value for a random variable given a string. If there is no maximum value, it will be set. Otherwise the maximum of the allowed range will not increase. The string argument is a number in a format acceptable to the constructors for Integer, Long, or Double as appropriate.
      Specified by:
      tightenMaximumS in interface RandomVariableOps<T>
      Parameters:
      max - maximum value.
      closed - true if the minimum value is part of the range; false if it is a lower bound on the range
      Throws:
      UnsupportedOperationException - the random variable's type does not have an order imposed on it or the operation is not supported for implementation reasons
      IllegalArgumentException - an argument is out of range
    • next

      public abstract T next() throws RandomVariableException
      Get the next value for a random variable. In general, each value will be independent of the last.
      Specified by:
      next in interface RandomVariableOps<T>
      Returns:
      the next value
      Throws:
      RandomVariableException - if the next value could not be generated
    • getMinimum

      public T getMinimum()
      Get the lower bound on the values that can be generated. Some random numbers do not have an ordering, so that null will always be returned in that case.
      Specified by:
      getMinimum in interface RandomVariableOps<T>
      Returns:
      the lower bound; null if there is none
    • getMinimumClosed

      public Boolean getMinimumClosed()
      Determine if a random variable's lower bound can be generated.
      Specified by:
      getMinimumClosed in interface RandomVariableOps<T>
      Returns:
      true if it can be generated; false if it cannot be generated; null if this cannot be determined
    • getMaximum

      public T getMaximum()
      Get the upper bound on the values that can be generated. Some random numbers do not have an ordering, so that null will always be returned in that case.
      Specified by:
      getMaximum in interface RandomVariableOps<T>
      Returns:
      the upper bound; null if there is none
    • getMaximumClosed

      public Boolean getMaximumClosed()
      Determine if a random variable's upper bound can be generated.
      Specified by:
      getMaximumClosed in interface RandomVariableOps<T>
      Returns:
      true if it can be generated; false if it cannot be generated; null if this cannot be determined
    • clone

      public Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • getCharacteristics

      protected int getCharacteristics()
      Spliterator characteristics. The characteristics returned should not include Spliterator.SIZED or Spliterator.SUBSIZED. The default value is Spliterator.IMMUTABLE | Spliterator.NONNULL. If the characteristics include Spliterator.ORDERED, Spliterator.trySplit() will return null. The characteristics include Spliterator.ORDERED for the random variables in this package that return a deterministic sequence of values.
      Returns:
      the characteristics
    • spliterator

      public Spliterator<T> spliterator(long size)
      Get a spliterator for a specified number of values.
      Parameters:
      size - the number of random values to provide
      Returns:
      the spliterator
    • spliterator

      public Spliterator<T> spliterator()
      Get a spliterator for an infinite number of values.
      Returns:
      the spliterator