问题标签 [markov-models]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
102 浏览

python - 使用python扩展Raftery Markov链函数最小化

我正在研究扩展的 Raftery 模型,它是一个更通用的高阶马尔可夫链模型,因为我需要解决以下具有某些约束的线性规划模型。

以下是需要最小化的(链接)线性规划函数:

受制于:

其中向量“W”和“λ”将在方程中求解。

Q 和 X 分别是 i 步转移概率矩阵和稳态概率。

以下是我正在使用的示例:

结果是 (λ1,λ2,w1,w2,w3) = (1,0,0.051,0.027,0.14) 而不是 (1,0,0.028,0.0071,0.0214),这是不正确的。

你能告诉我我哪里错了吗?

0 投票
1 回答
702 浏览

r - 直接来自数据的马尔可夫模型图(makovchain 还是 deemod 包?)

我想读取一堆因子数据并从中创建一个可以很好地可视化的转换矩阵。我发现了一个非常可爱的包,称为“heemod”,它与“diagram”一起做得不错。

对于我的第一个快速而简单的方法,运行一段 Python 代码来获取矩阵,然后使用这个 R 代码片段来绘制图形。请注意,转换概率来自未公开且不太重要的 Python 代码,但您也可以假设我是在纸上计算的。

但是,我想将所有内容集成到 R 中,并在 R 中直接从序列数据中生成转换矩阵和图形。

这是我到目前为止所拥有的:

问题:如何传输 dimMatrix 以便 define_transition 可以处理它?

有任何想法吗?有更好/更简单的解决方案吗?

0 投票
0 回答
443 浏览

go - Is there an elegant and efficient way to implement weighted random choices in golang? Details on current implementation and issues inside

tl;dr: I'm looking for methods to implement a weighted random choice based on the relative magnitude of values (or functions of values) in an array in golang. Are there standard algorithms or recommendable packages for this? Is so how do they scale?

Goals

I'm trying to write 2D and 3D markov process programs in golang. A simple 2D example of such is the following: Imagine one has a lattice, and on each site labeled by index (i,j) there are n(i,j) particles. At each time step, the program chooses a site and moves one particle from this site to a random adjacent site. The probability that a site is chosen is proportional to its population n(i,j) at that time.

Current Implementation

My current algorithm, e.g. for the 2D case on an L x L lattice, is the following:

  • Convert the starting array into a slice of length L^2 by concatenating rows in order, e.g. cdfpop[i L +j]=initialpopulation[i][j].
  • Convert the 1D slice into a cdf by running a for loop over cdfpop[i]+=cdfpop[i-1].
  • Generate a two random numbers, Rsite whose range is from 1 to the largest value in the cdf (this is just the last value, cdfpop[L^2-1]), and Rhop whose range is between 1 and 4. The first random number chooses a weighted random site, and the second number a random direction to hop in
  • Use a binary search to find the leftmost index indexhop of cdfpop that is greater than Rsite. The index being hopped to is either indexhop +-1 for x direction hops or indexhop +- L for y direction hops.
  • Finally, directly change the values of cdfpop to reflect the hop process. This means subtracting one from (adding one to) all values in cdfpop between the index being hopped from (to) and the index being hopped to (from) depending on order.
  • Rinse and repeat in for loop. At the end reverse the cdf to determine the final population.

Edit: Requested Pseudocode looks like:

This process works really well for simple problems. For this particular problem, I can run about 1 trillion steps on a 1000x 1000 lattice in about 2 minutes on average with my current set up, and I can compile population data to gifs every 10000 or so steps by spinning a go routine without a huge slowdown.

Where efficiency breaks down

The trouble comes when I want to add different processes, with real-valued coefficients, whose rates are not proportional to site population. So say I now have a hopping rate at k_hop *n(i,j) and a death rate (where I simply remove a particle) at k_death *(n(i,j))^2. There are two slow-downs in this case:

  • My cdf will be double the size (not that big of a deal). It will be real valued and created by cdfpop[i*L+j]= 4 *k_hop * pop[i][j] for i*L+j<L*L and cdfpop[i*L+j]= k_death*math. Power(pop[i][j],2) for L*L<=i*L+j<2*L*L, followed by cdfpop[i]+=cdfpop[i-1]. I would then select a random real in the range of the cdf.
  • Because of the squared n, I will have to dynamically recalculate the part of the cdf associated with the death process weights at each step. This is a MAJOR slow down, as expected. Timing for this is about 3 microseconds compared with the original algorithm which took less than a nanosecond.

This problem only gets worse if I have rates calculated as a function of populations on neighboring sites -- e.g. spontaneous particle creation depends on the product of populations on neighboring sites. While I hope to work out a way to just modify the cdf without recalculation by thinking really hard, as I try to simulate problems of increasing complexity, I can't help but wonder if there is a universal solution with reasonable efficiency I'm missing that doesn't require specialized code for each random process.

Thanks for reading!

0 投票
0 回答
15 浏览

regression - 用于评估治疗改变后疾病恶化/改善的模型

我在回归分析、cox 模型等方面有一些经验,但我想问一下哪种模型最适合评估与不同药物变化相关的慢性病症状控制。

假设您有几个患者的时间序列数据,其中有一个分类变量表示一种药物(药物 A、B、C、D),以及从一种药物转换为另一种药物的结果,该结果在四个级别上进行评估:(0:症状增加 >50%;1:症状不变;2:症状减轻 >50%;3:症状消失)

您将应用哪种分析来最好地评估哪种药物与最佳症状控制相关(也要考虑症状控制的持续时间)?并且可能过滤诸如性别、年龄等协变量。

我知道这可能是一个困难的问题,但我真的很喜欢这种生物统计模型的任何帮助或经验

非常感谢提前

0 投票
1 回答
104 浏览

matlab - 如何求解马尔可夫转移率矩阵?

我有一些变量要查找,例如 x= [1x16 (x1,x2,x3,....x16 变量)],条件是 x1+x2+x3+....x16=1。我也有 16x16 矩阵 Q= [16x16 (real values)]。

我需要解方程 'x*Q=x' ,如此处所示。如何在 Matlab 或任何其他语言中轻松解决它?

0 投票
0 回答
189 浏览

r - R使用高阶马尔可夫链生成随机样本

有没有办法从高阶马尔可夫链生成随机样本?我使用包点击流来估计一个二阶马尔可夫链,我现在正试图从中生成一个样本。我了解如何从带有 randomClickstreams 函数的转换矩阵执行此操作,但这仅适用于一阶马尔可夫链。

这是一个可重现的示例,我们从转换矩阵生成样本,然后在样本上拟合二阶马尔可夫链:

这由 2 个转换矩阵和 2 个 lambda 参数组成:

二阶马尔可夫链参数

然后我如何使用这些元素创建一个随机样本,比如 10000 次旅程?

0 投票
1 回答
27 浏览

markov-models - TML(Tractable Markov Logic)是一个很棒的模型!为什么我没有看到它被用于人工智能的广泛应用场景?

我一直在阅读有关马尔可夫模型的论文,突然出现了一个像 TML(Tractable Markov Logic)这样的伟大扩展。

它是马尔可夫逻辑的一个子集,并使用概率类和部分层次结构来控制复杂性。

该模型既有复杂的逻辑结构,也有不确定性。
它可以表示对象、类和对象之间的关系,但受到一定的限制,确保可以有效地查询任何用 TML 构建的模型中的推理。

我只是想知道为什么这么好的想法没有在活动分析等应用场景领域广泛传播?

更多信息

0 投票
1 回答
43 浏览

r - 在列表中汇总结果

我想知道如何创建所有状态的列及其相应的时间(每个列表对应一个 id)。Qmatrix 并不重要,因为它保持不变。

我希望它采用这种形式:

在此处输入图像描述

0 投票
0 回答
321 浏览

python - 在 Python 中构建时间非均匀马尔可夫链

使用搜索功能并没有帮助我找到解决问题的方法,这就是我创建这篇文章的原因。

首先,我对 Python 还很陌生,因此我的知识有限。

我正在分析一个基于时间使用日记的数据集。因此,列代表时间步长(tb1_1 - tb1_144),而行代表填写日志的各个个人(超过 6 万次观察)。此外,每个单元格中的值表示每个时间步执行的活动。(例如,1 = 睡眠等)数据集如下所示:

数据集

对于我的分析,我想根据日记条目提供的信息创建活动配置文件,方法是使用时间不均匀的马尔可夫链,图形上看起来像这样:

活动简介

我已经看过很多关于如何在 Python 中计算马尔可夫链的例子。但是,这些示例都没有考虑到,对于每个时间步 t,都需要从初始数据集中导出新的转换矩阵。

如果有人可以帮助我,我会很高兴。

谢谢,菲利克斯

- - -更新 - - - - -

经过几次尝试,我终于弄清楚了如何构建动态矩阵。请在下面找到代码。如果有人知道如何进一步缩短它,请随时发表评论:)

0 投票
2 回答
486 浏览

python - 政权转换多元garch

我有一个包含 4 个自变量和一个因变量的回归。我想实现一个政权切换 GARCH 模型,但一直无法在 R、Python 或 Matlab 中找到一个包。R 中可用的 MSGARCH 包适用于单变量系列系列,除此之外我还没有遇到任何可用的包。有没有可用的包?