| randomMarkovChain | R Documentation |
Generates a Markov chain whose transition probabilities are drawn at random, optionally with a given number of zero probabilities and with some probabilities fixed in advance.
randomMarkovChain(
n,
states = NULL,
zeros = 0L,
mask = NULL,
byrow = TRUE,
seed = NULL,
name = "Random Markov chain"
)
n |
The number of states. It can be omitted when |
states |
An optional character vector of |
zeros |
The number of transition probabilities, among those not
fixed by |
mask |
An optional |
byrow |
Whether the transition matrix of the result is stored by rows (the default) or by columns. |
seed |
An optional whole number. When given, the chain is generated
after |
name |
The |
The algorithm follows MarkovChain.random() of PyDTMC. In each row
not completely fixed by mask, one free entry, chosen at random, is
reserved to be positive. The zeros zero entries are then chosen at
random among the remaining free entries of the whole matrix, the other
free entries are drawn from a uniform distribution on (0, 1), and
the free entries of each row are rescaled so that, together with the
fixed ones, they sum to one. The rows are normalised uniforms, which is
not the uniform distribution on the simplex; use
dirichletChain or draw the rows yourself if that matters.
A markovchain object with n states.
dirichletChain, identityChain
randomMarkovChain(4, seed = 1)
# 6 of the 16 transition probabilities are zero
sum(randomMarkovChain(4, zeros = 6, seed = 1)@transitionMatrix == 0)
# state "b" moves to "a" with probability 0.5; the rest is random
m <- matrix(NA, 3, 3)
m[2, 1] <- 0.5
randomMarkovChain(states = c("a", "b", "c"), mask = m, seed = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.