Package jsl.utilities.random.rvariable
Class AbstractRVariable
- java.lang.Object
-
- jsl.utilities.random.rvariable.AbstractRVariable
-
- All Implemented Interfaces:
java.util.function.DoubleSupplier
,GetNameIfc
,GetValueIfc
,IdentityIfc
,PreviousValueIfc
,RandomIfc
,GetRandomNumberStreamIfc
,RNStreamControlIfc
,SetRandomNumberStreamIfc
,NewAntitheticInstanceIfc
,RVariableIfc
,SampleIfc
- Direct Known Subclasses:
AR1NormalRV
,BernoulliRV
,BetaRV
,BinomialRV
,ChiSquaredRV
,DEmpiricalRV
,DUniformRV
,EmpiricalRV
,ExponentialRV
,GammaRV
,GeneralizedBetaRV
,GeometricRV
,Hyper2ExponentialRV
,InverseCDFRV
,JohnsonBRV
,LaplaceRV
,LogLogisticRV
,LognormalRV
,MixtureRV
,NegativeBinomialRV
,NormalRV
,PearsonType5RV
,PearsonType6RV
,PoissonRV
,ShiftedGeometricRV
,ShiftedRV
,StudentTRV
,TriangularRV
,TruncatedRV
,UniformRV
,WeibullRV
public abstract class AbstractRVariable extends java.lang.Object implements RVariableIfc, IdentityIfc
An abstract base class for building random variables. Implement the random generation procedure in the method generate().
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jsl.utilities.random.rvariable.RVariableIfc
RVariableIfc.RVType
-
-
Field Summary
Fields Modifier and Type Field Description protected RNStreamIfc
myRNStream
myRNStream provides a reference to the underlying stream of random numbers
-
Constructor Summary
Constructors Constructor Description AbstractRVariable(RNStreamIfc stream)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
advanceToNextSubstream()
Positions the RNG at the beginning of its next substreamprotected abstract double
generate()
boolean
getAntitheticOption()
int
getId()
java.lang.String
getName()
double
getPreviousValue()
Gets the previous number from the sequence of valuesRNStreamIfc
getRandomNumberStream()
double
getValue()
This method simply returns the value.RVariableIfc
newAntitheticInstance()
RVariableIfc
newInstance(boolean newRNG)
Makes a new instance.void
resetStartStream()
The resetStartStream method will position the RNG at the beginning of its stream.void
resetStartSubstream()
Resets the position of the RNG at the start of the current substreamdouble
sample()
void
setAntitheticOption(boolean flag)
Tells the stream to start producing antithetic variatesvoid
setName(java.lang.String str)
Sets the nameprotected void
setPreviousValue(double value)
Sets the last (previous) randomly generated value.void
setRandomNumberStream(RNStreamIfc stream)
Sets the underlying random number stream-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsl.utilities.random.rng.GetRandomNumberStreamIfc
getStreamNumber
-
Methods inherited from interface jsl.utilities.random.rvariable.RVariableIfc
asDoubleStream, getAsDouble, getSumOfValues, newInstance, newInstance
-
Methods inherited from interface jsl.utilities.random.rng.SetRandomNumberStreamIfc
setRandomNumberStream
-
-
-
-
Field Detail
-
myRNStream
protected RNStreamIfc myRNStream
myRNStream provides a reference to the underlying stream of random numbers
-
-
Constructor Detail
-
AbstractRVariable
public AbstractRVariable(RNStreamIfc stream)
- Parameters:
stream
- the source of the randomness- Throws:
java.lang.NullPointerException
- if rng is null
-
-
Method Detail
-
newInstance
public final RVariableIfc newInstance(boolean newRNG)
Makes a new instance. False allows the new instance to keep using the same underlying source of random numbers.- Parameters:
newRNG
- true means use new stream. This is same as newInstance(). False means clone uses same underlying source of randomness- Returns:
- a new instance configured based on current instance
-
generate
protected abstract double generate()
- Returns:
- the randomly generated variate
-
setPreviousValue
protected final void setPreviousValue(double value)
Sets the last (previous) randomly generated value. Used within sample()- Parameters:
value
- the value to assign
-
sample
public final double sample()
-
getValue
public final double getValue()
Description copied from interface:GetValueIfc
This method simply returns the value.- Specified by:
getValue
in interfaceGetValueIfc
- Specified by:
getValue
in interfaceRVariableIfc
- Returns:
- returns a sampled values
-
getPreviousValue
public final double getPreviousValue()
Description copied from interface:PreviousValueIfc
Gets the previous number from the sequence of values- Specified by:
getPreviousValue
in interfacePreviousValueIfc
- Returns:
- a double representing the last value in the sequence
-
getName
public final java.lang.String getName()
- Specified by:
getName
in interfaceGetNameIfc
- Returns:
- a string representing the name of the object
-
getId
public final int getId()
- Specified by:
getId
in interfaceIdentityIfc
- Returns:
- an int representing the id of the object
-
setName
public final void setName(java.lang.String str)
Sets the name- Parameters:
str
- The name as a string.
-
newAntitheticInstance
public final RVariableIfc newAntitheticInstance()
- Specified by:
newAntitheticInstance
in interfaceNewAntitheticInstanceIfc
- Returns:
- a new instance with same parameter value, but that has antithetic variates
-
resetStartStream
public final void resetStartStream()
Description copied from interface:RNStreamControlIfc
The resetStartStream method will position the RNG at the beginning of its stream. This is the same location in the stream as assigned when the RNG was created and initialized.- Specified by:
resetStartStream
in interfaceRNStreamControlIfc
-
resetStartSubstream
public final void resetStartSubstream()
Description copied from interface:RNStreamControlIfc
Resets the position of the RNG at the start of the current substream- Specified by:
resetStartSubstream
in interfaceRNStreamControlIfc
-
advanceToNextSubstream
public final void advanceToNextSubstream()
Description copied from interface:RNStreamControlIfc
Positions the RNG at the beginning of its next substream- Specified by:
advanceToNextSubstream
in interfaceRNStreamControlIfc
-
setAntitheticOption
public final void setAntitheticOption(boolean flag)
Description copied from interface:RNStreamControlIfc
Tells the stream to start producing antithetic variates- Specified by:
setAntitheticOption
in interfaceRNStreamControlIfc
- Parameters:
flag
- true means that it produces antithetic variates.
-
getAntitheticOption
public final boolean getAntitheticOption()
- Specified by:
getAntitheticOption
in interfaceRNStreamControlIfc
- Returns:
- true means on
-
getRandomNumberStream
public final RNStreamIfc getRandomNumberStream()
- Specified by:
getRandomNumberStream
in interfaceGetRandomNumberStreamIfc
- Returns:
- the random number stream reference
-
setRandomNumberStream
public final void setRandomNumberStream(RNStreamIfc stream)
Description copied from interface:SetRandomNumberStreamIfc
Sets the underlying random number stream- Specified by:
setRandomNumberStream
in interfaceSetRandomNumberStreamIfc
- Parameters:
stream
- the reference to the random number stream, must not be null
-
-