从 R 中的图形重建马尔可夫链
Reconstructing Markov chain from figure in R
我正在尝试根据香农的论文“通信的数学理论”重建马尔可夫过程。我的问题涉及第 8 页的图 3 和第 5 页(B)部分的马尔可夫链的相应序列(消息)。我只是想检查我是否将正确的马尔可夫链编码到香农论文中的这个数字:
这是我的尝试:
install.packages("markovchain")
library(markovchain)
MessageABCDE = c("A", "B", "C", "D", "E")
MessageTransitionMatrix = matrix(c(.4,.1,.2,.2,.1,
.4,.1,.2,.2,.1,
.4,.1,.2,.2,.1,
.4,.1,.2,.2,.1,
.4,.1,.2,.2,.1),
nrow = 5,
byrow = TRUE,
dimname = list(MessageABCDE, MessageABCDE))
MCmessage = new("markovchain", states = MessageABCDE,
byrow = TRUE,
transitionMatrix = MessageTransitionMatrix,
name = "WritingMessage")
steadyStates(MCmessage)
markovchainSequence(n = 20, markovchain = MCmessage, t0 = "A")
我的目标也是从该链创建一个序列(消息)。我主要不确定转换矩阵,其中推断的概率必须在每一行中都相同。我对 markovchainSequence
的输出很满意,但我不能 100% 确定我是否做对了。
这是我的 markovchainSequence 控制台输出:
> markovchainSequence(n = 20, markovchain = MCmessage, t0 = "A")
[1] "D" "E" "A" "D" "A" "A" "B" "D" "E" "C" "A" "A" "E" "C" "C" "D" "D" "D"
[19] "A" "C"
看起来不错。这可能很奇怪,因为有了像这样的完全独立的状态,就不需要马尔可夫链了。同样可以使用
tokens <- c("A", "B", "C", "D", "E")
probs <- c(0.4, 0.1, 0.2, 0.2, 0.1)
sample(tokens, size=20, replace=TRUE, prob=probs)
## [1] "A" "B" "A" "B" "D" "B" "C" "D" "A" "D" "C" "E" "A" "A" "C" "E" "C" "D" "C" "C"
一旦有各种条件概率,可能会更有意义。
我正在尝试根据香农的论文“通信的数学理论”重建马尔可夫过程。我的问题涉及第 8 页的图 3 和第 5 页(B)部分的马尔可夫链的相应序列(消息)。我只是想检查我是否将正确的马尔可夫链编码到香农论文中的这个数字:
这是我的尝试:
install.packages("markovchain")
library(markovchain)
MessageABCDE = c("A", "B", "C", "D", "E")
MessageTransitionMatrix = matrix(c(.4,.1,.2,.2,.1,
.4,.1,.2,.2,.1,
.4,.1,.2,.2,.1,
.4,.1,.2,.2,.1,
.4,.1,.2,.2,.1),
nrow = 5,
byrow = TRUE,
dimname = list(MessageABCDE, MessageABCDE))
MCmessage = new("markovchain", states = MessageABCDE,
byrow = TRUE,
transitionMatrix = MessageTransitionMatrix,
name = "WritingMessage")
steadyStates(MCmessage)
markovchainSequence(n = 20, markovchain = MCmessage, t0 = "A")
我的目标也是从该链创建一个序列(消息)。我主要不确定转换矩阵,其中推断的概率必须在每一行中都相同。我对 markovchainSequence
的输出很满意,但我不能 100% 确定我是否做对了。
这是我的 markovchainSequence 控制台输出:
> markovchainSequence(n = 20, markovchain = MCmessage, t0 = "A")
[1] "D" "E" "A" "D" "A" "A" "B" "D" "E" "C" "A" "A" "E" "C" "C" "D" "D" "D"
[19] "A" "C"
看起来不错。这可能很奇怪,因为有了像这样的完全独立的状态,就不需要马尔可夫链了。同样可以使用
tokens <- c("A", "B", "C", "D", "E")
probs <- c(0.4, 0.1, 0.2, 0.2, 0.1)
sample(tokens, size=20, replace=TRUE, prob=probs)
## [1] "A" "B" "A" "B" "D" "B" "C" "D" "A" "D" "C" "E" "A" "A" "C" "E" "C" "D" "C" "C"
一旦有各种条件概率,可能会更有意义。