从过渡矩阵创建Markov链对象

时间:2019-04-05 12:46:16

标签: r random transition markov-chains

我有一个包含4行16列的过渡矩阵,其中包含从一篇Wikipedia文章过渡到另一篇文章的可能性。我的行总数已归一化为等于1。

以下是概述:

dput(head(res,4))
structure(c(0.0269201326869099, 0.221418475097697, 0.0572200491955321, 
0.0234890665263753, 0.0931927078903348, 0.203375737923007, 0.310133473123916, 
0.220087000151008, 0.00266507896005217, 0.0293922008813503, 0.00467760796806323, 
0.0045399854837374, 0.00598225170820221, 0.0235719630830631, 
0.0370176216782935, 0.00138830028204416, 0.0424711519378526, 
0.0206618441839195, 0.0414532844066293, 0.0344054908493962, 0.0334552465198038, 
0.0453978548266401, 0.166498649139078, 0.0243074330084224, 0.391312976666383, 
0.34181425126798, 0.131335940965361, 0.113533735696854, 0.190425562076493, 
0.0283528727030847, 0.00129037461187951, 0.0467297003707005, 
0.0281959683592753, 0.061278789390538, 0, 0.0299483162596755, 
0, 0.0158809345638979, 0.0305254244122747, 0, 0.0255592413030535, 
0, 0.0753659421750877, 0.0176874327161486, 0, 0, 0.0458082987217227, 
0, 0.0268350769754189, 0, 0.0630670591556111, 0.260016464754222, 
0, 0, 0.000846808339045929, 0.00347318631964031, 0.0287771823877973, 
0.00253596075496799, 0.0145570385902657, 0.0108920681777219, 
0.104207422528423, 0.00631911532385466, 0.0202024275172386, 0.209501819404054
), .Dim = c(4L, 16L), .Dimnames = list(c("Selected Disease Article", 
"Selected Food Scandal Article", "Selected General Article", 
"Selected Pathogen Article"), c("Animal health", "Biology", "Environment", 
"Food industry", "General", "Human and animal health", "Human health", 
"Medicine", "Other", "Related to a Food scandal", "Related to Antibiotic resistance", 
"Related to Food poisoning", "Selected Disease Article", "Selected Food Scandal Article", 
"Selected General Article", "Selected Pathogen Article")))

我遵循下面的代码,但是我陷入了马尔可夫链对象的定义

states <- as.character(1:16)

mc <- new(
    "markovchain",
    states = states,
    byrow = TRUE,
    transitionMatrix = res,
    name = "random_walk");

我得到错误:dimnames(x)<-dn中的错误:   'dimnames'[2]的长度不等于数组范围

我的代码有什么问题?创建markov链函数时我做错了什么吗?

1 个答案:

答案 0 :(得分:0)

这更多是您的(过渡)马尔可夫矩阵的一个基本问题,该矩阵是 else if(isset($_POST['btnDelete'])){ $link = makeConnection("database_name"); $sql = "Delete From blog where id = ?"; $stmnt = $link->prepare($sql); $stmnt->bind_param("i",$blogId); if($stmnt->execute()){ echo "success"; } 矩阵,应该是m x n矩阵:

http://www.math.harvard.edu/~knill/teaching/math19b_2011/handouts/lecture33.pdf

这很可能是为什么您收到n x n的原因,因为对象希望dimnames error具有相同的长度,请参见文档的第4页:

https://cran.r-project.org/web/packages/markovchain/markovchain.pdf

马尔可夫链的酷炫视角:

http://setosa.io/ev/markov-chains/