| toDictionary | R Documentation |
Converts a markovchain object to a plain, self-describing R list:
the same information toFile writes to disk, kept in memory.
fromDictionary reverses the conversion.
toDictionary(object)
## S4 method for signature 'markovchain'
toDictionary(object)
fromDictionary(d)
object |
A |
d |
A list as returned by |
Unlike PyDTMC's own to_dictionary()/from_dictionary(),
which represent a chain as a flat mapping from every
(from_state, to_state) pair to its probability – n^2
entries with no state grouping – this nests the representation by
source state, which is both more compact to read and directly
round-trips through R's own list-of-lists idiom without any special
tuple-key handling.
A named list with four elements:
nameThe chain's name, as a single string
(possibly empty).
statesA character vector of state names, in order.
byrowAlways TRUE: the list always stores the
chain row-stochastically, regardless of object's own
storage convention, so that the representation is unambiguous
without also having to interpret this flag.
transitionMatrixA named list of named lists:
transitionMatrix[[i]][[j]] is the probability of moving
from state i to state j. This is deliberately not a
plain matrix, so that the structure serializes to JSON or YAML
(via toFile) as a self-describing object keyed by
state name, rather than a bare array whose meaning depends on
remembering a row/column order.
fromDictionary returns a markovchain object.
toFile, fromFile
statesNames <- c("a", "b")
mc <- new("markovchain", states = statesNames,
transitionMatrix = matrix(c(0.7, 0.3, 0.4, 0.6), byrow = TRUE,
nrow = 2, dimnames = list(statesNames, statesNames)))
d <- toDictionary(mc)
d$transitionMatrix$a$b # 0.3: probability of moving from "a" to "b"
identical(fromDictionary(d)@transitionMatrix, mc@transitionMatrix)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.