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 classTwoStateMarkovChain.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 voidadvanceToNextSubstream()Positions the RNG at the beginning of its next substreambooleangetAntitheticOption()ControlsgetControls()Returns a valid instance of Controls that can be used with this ControllableIfc or nullintgetId()intgetInitialState()java.lang.StringgetName()doublegetP0()doublegetP01()doublegetP1()doublegetP11()double[]getParameters()The array consists of: p[0] = p11 p[1] = p01 p[2] = initial stateRNStreamIfcgetRandomNumberStream()intgetState()doublegetValue()This method simply returns the value.static voidmain(java.lang.String[] args)TwoStateMarkovChainnewInstance()The instance is initialized at getInitialState()TwoStateMarkovChainnewInstance(RNStreamIfc rng)The instance is initialized at getInitialState()voidreset()Sets the state back to the initial statevoidresetStartStream()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 variatesvoidsetControls(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 IllegalArgumentExceptionvoidsetInitialState(int initialState)voidsetName(java.lang.String str)Sets the namevoidsetParameters(double[] parameters)Supply an array with: p[0] = p11 p[1] = p01 p[2] = initial statevoidsetProbabilities(double p11, double p01)voidsetProbabilities(double p11, double p01, RNStreamIfc stream)voidsetRandomNumberStream(RNStreamIfc stream)Sets the underlying random number streamvoidsetState(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:
getIdin interfaceIdentityIfc- Returns:
- an int representing the id of the object
-
getName
public final java.lang.String getName()
- Specified by:
getNamein 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:
setInitialStatein interfaceTwoStateMarkovChainIfc
-
getInitialState
public int getInitialState()
- Specified by:
getInitialStatein interfaceTwoStateMarkovChainIfc
-
setState
public void setState(int state)
- Specified by:
setStatein interfaceTwoStateMarkovChainIfc
-
getState
public int getState()
- Specified by:
getStatein interfaceTwoStateMarkovChainIfc
-
setProbabilities
public void setProbabilities(double p11, double p01)- Specified by:
setProbabilitiesin 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:
resetin interfaceTwoStateMarkovChainIfc
-
getValue
public double getValue()
Description copied from interface:GetValueIfcThis method simply returns the value.- Specified by:
getValuein interfaceGetValueIfc- Returns:
- The value.
-
sample
public final double sample()
-
getP0
public double getP0()
- Specified by:
getP0in interfaceTwoStateMarkovChainIfc
-
getP1
public double getP1()
- Specified by:
getP1in interfaceTwoStateMarkovChainIfc
-
getP01
public double getP01()
- Specified by:
getP01in interfaceTwoStateMarkovChainIfc
-
getP11
public double getP11()
- Specified by:
getP11in interfaceTwoStateMarkovChainIfc
-
getParameters
public double[] getParameters()
The array consists of: p[0] = p11 p[1] = p01 p[2] = initial state- Specified by:
getParametersin 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:
setParametersin interfaceParametersIfc- Parameters:
parameters- the parameters of the Markov chain
-
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
-
advanceToNextSubstream
public void advanceToNextSubstream()
Description copied from interface:RNStreamControlIfcPositions the RNG at the beginning of its next substream- Specified by:
advanceToNextSubstreamin interfaceRNStreamControlIfc
-
resetStartStream
public 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 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 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
-
newInstance
public TwoStateMarkovChain newInstance()
The instance is initialized at getInitialState()- Specified by:
newInstancein 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:ControllableIfcReturns a valid instance of Controls that can be used with this ControllableIfc or null- Specified by:
getControlsin interfaceControllableIfc- Returns:
-
setControls
public void setControls(Controls controls)
Description copied from interface:ControllableIfcTakes 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:
setControlsin interfaceControllableIfc
-
-