Package jsl.utilities.random.rng
Class AR1CorrelatedRNStream
- java.lang.Object
-
- jsl.utilities.random.rng.AR1CorrelatedRNStream
-
- All Implemented Interfaces:
java.util.function.DoubleSupplier,GetAntitheticStreamIfc,GetAntitheticValueIfc,GetRandomNumberStreamIfc,RandU01Ifc,RNStreamControlIfc,RNStreamIfc,RNStreamNewInstanceIfc,SetRandomNumberStreamIfc
public class AR1CorrelatedRNStream extends java.lang.Object implements RNStreamIfc, SetRandomNumberStreamIfc, GetRandomNumberStreamIfc
Uses the auto-regressive to anything algorithm to generate correlated uniform variates. The user supplies the correlation of the underlying AR(1) process. The resulting correlation in the u's may not necessarily meet this correlation, due to the correlation matching problem.
-
-
Constructor Summary
Constructors Constructor Description AR1CorrelatedRNStream()AR1CorrelatedRNStream(double correlation)AR1CorrelatedRNStream(double correlation, RNStreamIfc rng)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadvanceToNextSubstream()Positions the RNG at the beginning of its next substreambooleangetAntitheticOption()doublegetAntitheticValue()Returns the antithetic value of the previous valuedoublegetLag1Correlation()doublegetPrevU01()The previous U(0,1) generated (returned) by randU01()RNStreamIfcgetRandomNumberStream()RNStreamIfcnewAntitheticInstance()RNStreamIfcnewAntitheticInstance(java.lang.String name)RNStreamIfcnewInstance()Returns a copy of the stream with exactly the same stateRNStreamIfcnewInstance(java.lang.String name)Returns a copy of the stream that has exactly the same stateintrandInt(int i, int j)Returns a (pseudo)random number from the discrete uniform distribution over the integers {i, i + 1, .doublerandU01()Returns a pseudo-random uniformly distributed numbervoidresetStartStream()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 substreamvoidsetAntitheticOption(boolean flag)Tells the stream to start producing antithetic variatesvoidsetLag1Correlation(double correlation)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.rng.RandU01Ifc
asDoubleStream, getAsDouble
-
Methods inherited from interface jsl.utilities.random.rng.SetRandomNumberStreamIfc
setRandomNumberStream
-
-
-
-
Constructor Detail
-
AR1CorrelatedRNStream
public AR1CorrelatedRNStream()
-
AR1CorrelatedRNStream
public AR1CorrelatedRNStream(double correlation)
- Parameters:
correlation- the correlation, must be within [-1,1]
-
AR1CorrelatedRNStream
public AR1CorrelatedRNStream(double correlation, RNStreamIfc rng)- Parameters:
correlation- the correlation, must be within [-1,1]rng- the underlying source of randomness
-
-
Method Detail
-
randU01
public double randU01()
Description copied from interface:RandU01IfcReturns a pseudo-random uniformly distributed number- Specified by:
randU01in interfaceRandU01Ifc- Returns:
- the random number
-
getRandomNumberStream
public final RNStreamIfc getRandomNumberStream()
- Specified by:
getRandomNumberStreamin interfaceGetRandomNumberStreamIfc- Returns:
- the random number stream reference
-
setRandomNumberStream
public 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
-
randInt
public final int randInt(int i, int j)Description copied from interface:RNStreamIfcReturns a (pseudo)random number from the discrete uniform distribution over the integers {i, i + 1, . . . , j }, using this stream. Calls randU01 once.- Specified by:
randIntin interfaceRNStreamIfc- Parameters:
i- start of rangej- end of range- Returns:
- The integer pseudo random number
-
advanceToNextSubstream
public final void advanceToNextSubstream()
Description copied from interface:RNStreamControlIfcPositions the RNG at the beginning of its next substream- Specified by:
advanceToNextSubstreamin interfaceRNStreamControlIfc
-
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
-
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 boolean getAntitheticOption()
- Specified by:
getAntitheticOptionin interfaceRNStreamControlIfc- Returns:
- true means on
-
getLag1Correlation
public final double getLag1Correlation()
- Returns:
- the lag 1 correlation
-
setLag1Correlation
public final void setLag1Correlation(double correlation)
- Parameters:
correlation- the correlation, must be within [-1,1]
-
getPrevU01
public final double getPrevU01()
Description copied from interface:RandU01IfcThe previous U(0,1) generated (returned) by randU01()- Specified by:
getPrevU01in interfaceRandU01Ifc- Returns:
- previous U(0,1) generated (returned) by randU01()
-
getAntitheticValue
public final double getAntitheticValue()
Description copied from interface:GetAntitheticValueIfcReturns the antithetic value of the previous value- Specified by:
getAntitheticValuein interfaceGetAntitheticValueIfc- Returns:
- the antithetic value of the previous value
-
newInstance
public RNStreamIfc newInstance()
Description copied from interface:RNStreamNewInstanceIfcReturns a copy of the stream with exactly the same state- Specified by:
newInstancein interfaceRNStreamNewInstanceIfc- Returns:
- Returns a copy of the stream with exactly the same state
-
newInstance
public RNStreamIfc newInstance(java.lang.String name)
Description copied from interface:RNStreamNewInstanceIfcReturns a copy of the stream that has exactly the same state- Specified by:
newInstancein interfaceRNStreamNewInstanceIfc- Parameters:
name- the name of the new instance- Returns:
- Returns a copy of the stream with exactly the same state
-
newAntitheticInstance
public RNStreamIfc newAntitheticInstance(java.lang.String name)
- Specified by:
newAntitheticInstancein interfaceGetAntitheticStreamIfc- Parameters:
name- the name of the antithetic instance- Returns:
- a copy of the stream that produces antithetic value
-
newAntitheticInstance
public RNStreamIfc newAntitheticInstance()
- Specified by:
newAntitheticInstancein interfaceGetAntitheticStreamIfc- Returns:
- a copy of the stream that produces antithetic value
-
-