java.lang.Object
org.bzdev.math.rv.RandomVariable<T>
- All Implemented Interfaces:
Cloneable
,RandomVariableOps<T>
- Direct Known Subclasses:
BooleanRandomVariable
,DoubleRandomVariable
,IntegerRandomVariable
,LongRandomVariable
,RandomVariableRV
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()
protected int
Spliterator characteristics.Get the upper bound on the values that can be generated.Determine if a random variable's upper bound can be generated.Get the lower bound on the values that can be generated.Determine if a random variable's lower bound can be generated.abstract T
next()
Get the next value for a random variable.void
setMaximum
(T max, boolean closed) Set the maximum value for a random variable.void
setMinimum
(T min, boolean closed) Set the minimum value for a random variable.protected void
setRequiredMaximum
(T max, boolean closed) Set the required maximum value for a random variable.protected void
setRequiredMinimum
(T min, boolean closed) Set a required minimum value for a random variable.Get a spliterator for an infinite number of values.spliterator
(long size) Get a spliterator for a specified number of values.void
tightenMaximum
(T max, boolean closed) Tighten the maximum value for a random variable.abstract void
tightenMaximumS
(String max, boolean closed) Tighten the maximum value for a random variable given a string.void
tightenMinimum
(T min, boolean closed) Tighten the minimum value for a random variable.abstract void
tightenMinimumS
(String min, boolean closed) Tighten the minimum value for a random variable given a string.
-
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 interfaceRandomVariableOps<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 reasonsIllegalArgumentException
- 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 reasonsIllegalArgumentException
- 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 interfaceRandomVariableOps<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 reasonsIllegalArgumentException
- 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 interfaceRandomVariableOps<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 reasonsIllegalArgumentException
- 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 interfaceRandomVariableOps<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 reasonsIllegalArgumentException
- 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 reasonsIllegalArgumentException
- 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 interfaceRandomVariableOps<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 reasonsIllegalArgumentException
- 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 interfaceRandomVariableOps<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 reasonsIllegalArgumentException
- an argument is out of range
-
next
Get the next value for a random variable. In general, each value will be independent of the last.- Specified by:
next
in interfaceRandomVariableOps<T>
- Returns:
- the next value
- Throws:
RandomVariableException
- if the next value could not be generated
-
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 interfaceRandomVariableOps<T>
- Returns:
- the lower bound; null if there is none
-
getMinimumClosed
Determine if a random variable's lower bound can be generated.- Specified by:
getMinimumClosed
in interfaceRandomVariableOps<T>
- Returns:
- true if it can be generated; false if it cannot be generated; null if this cannot be determined
-
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 interfaceRandomVariableOps<T>
- Returns:
- the upper bound; null if there is none
-
getMaximumClosed
Determine if a random variable's upper bound can be generated.- Specified by:
getMaximumClosed
in interfaceRandomVariableOps<T>
- Returns:
- true if it can be generated; false if it cannot be generated; null if this cannot be determined
-
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-
getCharacteristics
protected int getCharacteristics()Spliterator characteristics. The characteristics returned should not includeSpliterator.SIZED
orSpliterator.SUBSIZED
. The default value isSpliterator.IMMUTABLE
|Spliterator.NONNULL
. If the characteristics includeSpliterator.ORDERED
,Spliterator.trySplit()
will return null. The characteristics includeSpliterator.ORDERED
for the random variables in this package that return a deterministic sequence of values.- Returns:
- the characteristics
-
spliterator
Get a spliterator for a specified number of values.- Parameters:
size
- the number of random values to provide- Returns:
- the spliterator
-
spliterator
Get a spliterator for an infinite number of values.- Returns:
- the spliterator
-