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 RNStreamIfcmyRNStreammyRNStream 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 voidadvanceToNextSubstream()Positions the RNG at the beginning of its next substreamprotected abstract doublegenerate()booleangetAntitheticOption()intgetId()java.lang.StringgetName()doublegetPreviousValue()Gets the previous number from the sequence of valuesRNStreamIfcgetRandomNumberStream()doublegetValue()This method simply returns the value.RVariableIfcnewAntitheticInstance()RVariableIfcnewInstance(boolean newRNG)Makes a new instance.voidresetStartStream()The resetStartStream method will position the RNG at the beginning of its stream.voidresetStartSubstream()Resets the position of the RNG at the start of the current substreamdoublesample()voidsetAntitheticOption(boolean flag)Tells the stream to start producing antithetic variatesvoidsetName(java.lang.String str)Sets the nameprotected voidsetPreviousValue(double value)Sets the last (previous) randomly generated value.voidsetRandomNumberStream(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:GetValueIfcThis method simply returns the value.- Specified by:
getValuein interfaceGetValueIfc- Specified by:
getValuein interfaceRVariableIfc- Returns:
- returns a sampled values
-
getPreviousValue
public final double getPreviousValue()
Description copied from interface:PreviousValueIfcGets the previous number from the sequence of values- Specified by:
getPreviousValuein interfacePreviousValueIfc- Returns:
- a double representing the last value in the sequence
-
getName
public final java.lang.String getName()
- Specified by:
getNamein interfaceGetNameIfc- Returns:
- a string representing the name of the object
-
getId
public final int getId()
- Specified by:
getIdin 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:
newAntitheticInstancein interfaceNewAntitheticInstanceIfc- Returns:
- a new instance with same parameter value, but that has antithetic variates
-
resetStartStream
public final void resetStartStream()
Description copied from interface:RNStreamControlIfcThe 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:
resetStartStreamin interfaceRNStreamControlIfc
-
resetStartSubstream
public final void resetStartSubstream()
Description copied from interface:RNStreamControlIfcResets the position of the RNG at the start of the current substream- Specified by:
resetStartSubstreamin interfaceRNStreamControlIfc
-
advanceToNextSubstream
public final void advanceToNextSubstream()
Description copied from interface:RNStreamControlIfcPositions the RNG at the beginning of its next substream- Specified by:
advanceToNextSubstreamin interfaceRNStreamControlIfc
-
setAntitheticOption
public final void setAntitheticOption(boolean flag)
Description copied from interface:RNStreamControlIfcTells the stream to start producing antithetic variates- Specified by:
setAntitheticOptionin interfaceRNStreamControlIfc- Parameters:
flag- true means that it produces antithetic variates.
-
getAntitheticOption
public final boolean getAntitheticOption()
- Specified by:
getAntitheticOptionin interfaceRNStreamControlIfc- Returns:
- true means on
-
getRandomNumberStream
public final RNStreamIfc getRandomNumberStream()
- Specified by:
getRandomNumberStreamin interfaceGetRandomNumberStreamIfc- Returns:
- the random number stream reference
-
setRandomNumberStream
public final void setRandomNumberStream(RNStreamIfc stream)
Description copied from interface:SetRandomNumberStreamIfcSets the underlying random number stream- Specified by:
setRandomNumberStreamin interfaceSetRandomNumberStreamIfc- Parameters:
stream- the reference to the random number stream, must not be null
-
-