Package jsl.utilities.random.sp
Class TwoStateMarkovChain
- java.lang.Object
-
- jsl.utilities.random.sp.TwoStateMarkovChain
-
- All Implemented Interfaces:
ControllableIfc
,GetNameIfc
,GetValueIfc
,IdentityIfc
,NewInstanceIfc<TwoStateMarkovChain>
,ParametersIfc
,RandomIfc
,GetRandomNumberStreamIfc
,RNStreamControlIfc
,SetRandomNumberStreamIfc
,SampleIfc
,TwoStateMarkovChainIfc
public class TwoStateMarkovChain extends java.lang.Object implements TwoStateMarkovChainIfc, ControllableIfc, ParametersIfc, NewInstanceIfc<TwoStateMarkovChain>, RandomIfc
Represents a two state Markov chain States = {0,1} User supplies P{X(i) = 1| X(i-1) = 1} Probability of success after success P{X(i) = 1| X(i-1) = 0} Probability of success after failure
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
TwoStateMarkovChain.RandomControls
-
Constructor Summary
Constructors Constructor Description TwoStateMarkovChain()
TwoStateMarkovChain(double[] parameters)
TwoStateMarkovChain(double p11, double p01)
TwoStateMarkovChain(int initialState, double p11, double p01)
TwoStateMarkovChain(int initialState, double p11, double p01, RNStreamIfc rng)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
advanceToNextSubstream()
Positions the RNG at the beginning of its next substreamboolean
getAntitheticOption()
Controls
getControls()
Returns a valid instance of Controls that can be used with this ControllableIfc or nullint
getId()
int
getInitialState()
java.lang.String
getName()
double
getP0()
double
getP01()
double
getP1()
double
getP11()
double[]
getParameters()
The array consists of: p[0] = p11 p[1] = p01 p[2] = initial stateRNStreamIfc
getRandomNumberStream()
int
getState()
double
getValue()
This method simply returns the value.static void
main(java.lang.String[] args)
TwoStateMarkovChain
newInstance()
The instance is initialized at getInitialState()TwoStateMarkovChain
newInstance(RNStreamIfc rng)
The instance is initialized at getInitialState()void
reset()
Sets the state back to the initial statevoid
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
setControls(Controls controls)
Takes in a valid instance of Controls for this class If controls is null or if it was not created by this class this method should throw an IllegalArgumentExceptionvoid
setInitialState(int initialState)
void
setName(java.lang.String str)
Sets the namevoid
setParameters(double[] parameters)
Supply an array with: p[0] = p11 p[1] = p01 p[2] = initial statevoid
setProbabilities(double p11, double p01)
void
setProbabilities(double p11, double p01, RNStreamIfc stream)
void
setRandomNumberStream(RNStreamIfc stream)
Sets the underlying random number streamvoid
setState(int state)
-
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.SetRandomNumberStreamIfc
setRandomNumberStream
-
-
-
-
Constructor Detail
-
TwoStateMarkovChain
public TwoStateMarkovChain()
-
TwoStateMarkovChain
public TwoStateMarkovChain(double p11, double p01)
-
TwoStateMarkovChain
public TwoStateMarkovChain(double[] parameters)
-
TwoStateMarkovChain
public TwoStateMarkovChain(int initialState, double p11, double p01)
-
TwoStateMarkovChain
public TwoStateMarkovChain(int initialState, double p11, double p01, RNStreamIfc rng)
-
-
Method Detail
-
getId
public final int getId()
- Specified by:
getId
in interfaceIdentityIfc
- Returns:
- an int representing the id of the object
-
getName
public final java.lang.String getName()
- Specified by:
getName
in interfaceGetNameIfc
- Returns:
- a string representing the name of the object
-
setName
public final void setName(java.lang.String str)
Sets the name- Parameters:
str
- The name as a string.
-
setInitialState
public void setInitialState(int initialState)
- Specified by:
setInitialState
in interfaceTwoStateMarkovChainIfc
-
getInitialState
public int getInitialState()
- Specified by:
getInitialState
in interfaceTwoStateMarkovChainIfc
-
setState
public void setState(int state)
- Specified by:
setState
in interfaceTwoStateMarkovChainIfc
-
getState
public int getState()
- Specified by:
getState
in interfaceTwoStateMarkovChainIfc
-
setProbabilities
public void setProbabilities(double p11, double p01)
- Specified by:
setProbabilities
in interfaceTwoStateMarkovChainIfc
-
setProbabilities
public void setProbabilities(double p11, double p01, RNStreamIfc stream)
-
reset
public void reset()
Sets the state back to the initial state- Specified by:
reset
in interfaceTwoStateMarkovChainIfc
-
getValue
public double getValue()
Description copied from interface:GetValueIfc
This method simply returns the value.- Specified by:
getValue
in interfaceGetValueIfc
- Returns:
- The value.
-
sample
public final double sample()
-
getP0
public double getP0()
- Specified by:
getP0
in interfaceTwoStateMarkovChainIfc
-
getP1
public double getP1()
- Specified by:
getP1
in interfaceTwoStateMarkovChainIfc
-
getP01
public double getP01()
- Specified by:
getP01
in interfaceTwoStateMarkovChainIfc
-
getP11
public double getP11()
- Specified by:
getP11
in interfaceTwoStateMarkovChainIfc
-
getParameters
public double[] getParameters()
The array consists of: p[0] = p11 p[1] = p01 p[2] = initial state- Specified by:
getParameters
in interfaceParametersIfc
- Returns:
- the array of parameters
-
setParameters
public void setParameters(double[] parameters)
Supply an array with: p[0] = p11 p[1] = p01 p[2] = initial state- Specified by:
setParameters
in interfaceParametersIfc
- Parameters:
parameters
- the parameters of the Markov chain
-
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
-
advanceToNextSubstream
public void advanceToNextSubstream()
Description copied from interface:RNStreamControlIfc
Positions the RNG at the beginning of its next substream- Specified by:
advanceToNextSubstream
in interfaceRNStreamControlIfc
-
resetStartStream
public 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 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 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
-
newInstance
public TwoStateMarkovChain newInstance()
The instance is initialized at getInitialState()- Specified by:
newInstance
in interfaceNewInstanceIfc<TwoStateMarkovChain>
- Returns:
- the instance is initialized at getInitialState()
-
newInstance
public TwoStateMarkovChain newInstance(RNStreamIfc rng)
The instance is initialized at getInitialState()- Returns:
- the instance is initialized at getInitialState()
-
main
public static void main(java.lang.String[] args)
-
getControls
public Controls getControls()
Description copied from interface:ControllableIfc
Returns a valid instance of Controls that can be used with this ControllableIfc or null- Specified by:
getControls
in interfaceControllableIfc
- Returns:
-
setControls
public void setControls(Controls controls)
Description copied from interface:ControllableIfc
Takes in a valid instance of Controls for this class If controls is null or if it was not created by this class this method should throw an IllegalArgumentException- Specified by:
setControls
in interfaceControllableIfc
-
-