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 void
advanceToNextSubstream()
Positions the RNG at the beginning of its next substreamboolean
getAntitheticOption()
double
getAntitheticValue()
Returns the antithetic value of the previous valuedouble
getLag1Correlation()
double
getPrevU01()
The previous U(0,1) generated (returned) by randU01()RNStreamIfc
getRandomNumberStream()
RNStreamIfc
newAntitheticInstance()
RNStreamIfc
newAntitheticInstance(java.lang.String name)
RNStreamIfc
newInstance()
Returns a copy of the stream with exactly the same stateRNStreamIfc
newInstance(java.lang.String name)
Returns a copy of the stream that has exactly the same stateint
randInt(int i, int j)
Returns a (pseudo)random number from the discrete uniform distribution over the integers {i, i + 1, .double
randU01()
Returns a pseudo-random uniformly distributed numbervoid
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 substreamvoid
setAntitheticOption(boolean flag)
Tells the stream to start producing antithetic variatesvoid
setLag1Correlation(double correlation)
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.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:RandU01Ifc
Returns a pseudo-random uniformly distributed number- Specified by:
randU01
in interfaceRandU01Ifc
- Returns:
- the random number
-
getRandomNumberStream
public final RNStreamIfc getRandomNumberStream()
- Specified by:
getRandomNumberStream
in interfaceGetRandomNumberStreamIfc
- Returns:
- the random number stream reference
-
setRandomNumberStream
public 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
-
randInt
public final int randInt(int i, int j)
Description copied from interface:RNStreamIfc
Returns a (pseudo)random number from the discrete uniform distribution over the integers {i, i + 1, . . . , j }, using this stream. Calls randU01 once.- Specified by:
randInt
in interfaceRNStreamIfc
- Parameters:
i
- start of rangej
- end of range- Returns:
- The integer pseudo random number
-
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
-
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
-
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 boolean getAntitheticOption()
- Specified by:
getAntitheticOption
in 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:RandU01Ifc
The previous U(0,1) generated (returned) by randU01()- Specified by:
getPrevU01
in interfaceRandU01Ifc
- Returns:
- previous U(0,1) generated (returned) by randU01()
-
getAntitheticValue
public final double getAntitheticValue()
Description copied from interface:GetAntitheticValueIfc
Returns the antithetic value of the previous value- Specified by:
getAntitheticValue
in interfaceGetAntitheticValueIfc
- Returns:
- the antithetic value of the previous value
-
newInstance
public RNStreamIfc newInstance()
Description copied from interface:RNStreamNewInstanceIfc
Returns a copy of the stream with exactly the same state- Specified by:
newInstance
in 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:RNStreamNewInstanceIfc
Returns a copy of the stream that has exactly the same state- Specified by:
newInstance
in 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:
newAntitheticInstance
in 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:
newAntitheticInstance
in interfaceGetAntitheticStreamIfc
- Returns:
- a copy of the stream that produces antithetic value
-
-