public class TwoStateMarkovVariate extends RandomVariateBase implements DiscreteRandomVariate
Generates values from a 2-D Markov Chain taking on values {0,1}. The parameters the probabilities that a transition will not be made (i.e. that the next state will be identical to the first). So p[0] = Pr{X1 = 0 | X0 = 0} and p[1] = Pr{X1 = 1 | X0 = 1}. A double[] array should be passed in the Object[] params. An optional second value in params is a Number instance representing the initial state. This should be 0 or 1. The setters check validity of the arguments.
Modifier and Type | Field and Description |
---|---|
protected int |
currentState
The current state of the system
|
private int |
initialState
The state of the system last time it was set.
|
private double[] |
transitionProb
A two element array holding the transition probabilities.
|
rng
Constructor and Description |
---|
TwoStateMarkovVariate()
Makes a new TwoStateMarkovVariate with initialState 0 and no transition probabilities.
|
Modifier and Type | Method and Description |
---|---|
double |
generate()
Generate the next state of the system
|
int |
generateInt()
Generate the next state of the system
|
int |
getInitialState() |
java.lang.Object[] |
getParameters()
Returns a 2 element array with the parameters.
|
double[] |
getTransitionProb()
Returns a 2 element array containing the transition probabilities.
|
void |
setInitialState(int initialState) |
void |
setParameters(java.lang.Object... params)
Sets the transition probabilities and (optionally) the initial state.
|
void |
setTransitionProb(double[] trans)
Sets the transition probabilities.
|
java.lang.String |
toString()
Returns a String containing the name of this RandomVariate, the transition
probabilities and the initial state.
|
getRandomNumber, setRandomNumber
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getRandomNumber, setRandomNumber
private double[] transitionProb
private int initialState
protected int currentState
public TwoStateMarkovVariate()
public double generate()
generate
in interface RandomVariate
public int generateInt()
generateInt
in interface DiscreteRandomVariate
public java.lang.Object[] getParameters()
getParameters
in interface RandomVariate
public void setParameters(java.lang.Object... params)
setParameters
in interface RandomVariate
params
- A 1 or 2 element array. The first element contains a two element
double
array with the probability that the state of the system will
stay 0 given that it is 0 and the probability that the system will stay 1 given that it is 1.
The second (optional) element is the initial state (0 or 1) of the system as a Number.java.lang.IllegalArgumentException
- If the array does not contain 1 or 2 elements,
If the first element is not a 2 element double
array with values
between 0 and 1 inclusive, or if the 2nd (optional) element is not a Number
with a value of 0 or 1.public void setTransitionProb(double[] trans)
trans
- A two element array with the probability that the state of the system will
stay 0 given that it is 0 and the probability that the system will stay 1 given that it is 1.java.lang.IllegalArgumentException
- If the array does not contain 2 elements or either element
is not between 0 and 1 inclusive.public double[] getTransitionProb()
public void setInitialState(int initialState)
initialState
- the initial initialState (0 or 1) of the systemjava.lang.IllegalArgumentException
- If the value is not 0 or 1.public int getInitialState()
public java.lang.String toString()
toString
in class java.lang.Object