DMarkovChain

open class DMarkovChain(theInitialState: Int = 1, transMatrix: Array<DoubleArray>, streamNumber: Int = 0, streamProvider: RNStreamProviderIfc = KSLRandom.DefaultRNStreamProvider, name: String? = null) : RVariable(source)

Randomly generates the states of a discrete Markov Chain. Assumes that the states are labeled 1, 2, 3, etc. The transition probabilities are supplied as an array of arrays. transMatrix0 holds the array of transition probabilities for transition to each state {p11, p12, p13, .., p1n} for state 1 transMatrix1 holds the array of transition probabilities for transition to each state {p21, p22, p23, .., p2n} for state 2 etc.

Author

rossetti

Parameters

theInitialState

the initial state

transMatrix

the single step transition matrix

streamNumber

the random number stream number, defaults to 0, which means the next stream

streamProvider

the provider of random number streams, defaults to KSLRandom.DefaultRNStreamProvider

name

an optional name

Inheritors

Constructors

Link copied to clipboard
constructor(theInitialState: Int = 1, transMatrix: Array<DoubleArray>, streamNumber: Int = 0, streamProvider: RNStreamProviderIfc = KSLRandom.DefaultRNStreamProvider, name: String? = null)

Properties

Link copied to clipboard

The initial starting state of the chain

Link copied to clipboard
Link copied to clipboard
var state: Int

The current state, with no transition implied. In other words, the last generated state

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun countTransitionsUntil(startState: Int, desiredState: Int, transitionLimit: Int = 10000): Int

Simulates the chain forward starting from the startState until the desired state desiredState is reached for the first time and returns the number of transitions required to reach the desired state for the first time.

Link copied to clipboard
fun firstPassageFrequency(sampleSize: Int, startState: Int, desiredState: Int, transitionLimit: Int = 10000): IntegerFrequency

Estimates the first passage time distribution from the starting state to the desired state as an IntegerFrequency based on the provided sample size sampleSize.

Link copied to clipboard
open override fun instance(streamNum: Int, rnStreamProvider: RNStreamProviderIfc): DMarkovChain
Link copied to clipboard
fun nextState(): Int

Randomly generates the next state from the current state. Same as using value, value(), or sample()

Link copied to clipboard
fun reset()

Sets the state back to the initial state

Link copied to clipboard
open override fun toString(): String