马尔科夫链(Markov chain, Markov model)讲解(一阶和高阶)及其应用(建模数据预测)

本文简要介绍了它的概念(包括一阶链、二阶链和高阶链)及其应用(如何通过建模进行数据预测)。

[En]

This paper briefly explains its concept (including first-order, second-order and higher-order chains) and its application (how to make data prediction through modeling).

概括的来说,马尔科夫链是基于统计的数学模型。

那么,什么是基于统计数据的?列出生活中最常见的场景之一。当我们使用输入法打字时,输入法会自动弹出联想字符。这一点在写一些非常常见的名词时尤其明显,比如名字。例如,某人的名字是Olivier。当我们第一次输入这个名字时,我们需要完整正确地拼写每个单词,否则它就会变成一个像奥利维尔一样的单词。但在多次输入后,Olivier会直接弹出,甚至我们可能只需要输入O,输入法就会自动将完整的术语Olivier关联起来。输入法的内部处理实际上包含了马尔可夫链的处理逻辑:当用户频繁输入一个短语时,该短语被使用的频率更高,所以当用户只输入短语的开头时,他们也很有可能想要输入该短语,并且联想具有更高的优先级。

[En]

So, what is based on statistics? List one of the most common scenes in life. When we use the input method to type, the input method will automatically pop up associative characters. This is especially obvious when writing some very common nouns, such as names. For example, someone’s name is Olivier. When we type this name for the first time, we need to spell every word completely and correctly, otherwise it will become a word like Olivier. But after many times of typing, Olivier will pop up directly, and even we may just need to type O, and the input method will automatically associate the complete term Olivier. The internal processing of the input method actually contains the processing logic of the Markov chain: when the user enters a phrase frequently, the phrase is used more frequently, so when the user only enters the beginning of the phrase, there is also a good chance that they want to enter the phrase, and the association has a higher priority.

这个例子的目的是传达这样一个基本思想,即马尔可夫链的模型是基于历史数据的。那么,如何从历史数据中进行统计,建立马尔可夫模型呢?这需要从马尔可夫链的定义开始。

[En]

The purpose of this example is to convey the basic idea that the model of Markov chain is based on historical data. So, how to make statistics from historical data and establish a Markov model? This needs to start with the definition of Markov chain.

马尔科夫链是反映了对象状态变化的过程的数学模型。

我们还是从一个例子开始吧。我们现在有一些历史数据来记录一个地方近一年(2021年)每天的天气。我们简单地将天气类型定义为多云、晴朗和下雨。历史数据可以显示如下

[En]

Let’s still start with an example. We now have some historical data to record the weather every day in a place for nearly a year (2021). We simply define the type of weather as cloudy, sunny and rainy. Historical data can be displayed as follows

1.1晴,1.2 晴, 1.3 阴, 1.4 雨…12.30 雨,12.31 雨。
这里的天气类型可以看作是物体的状态。例如,阴天为状态1,晴天为状态2,雨天为状态3。

[En]

The type of weather here can be regarded as the state of the object. For example, cloudy days are state 1, sunny days are state 2, and rainy days are state 3.

那么历史数据可以改写为
1.12,1.2 2, 1.3 1, 1.4 3…12.30 3,12.31 3。
可以将其看作一个长度为365的长列表
[2,2,1,3…3,3]
目前我们已经有了2021年的历史数据,现在我们想要做的是,预测2022年某一天的未来的天气。

当然,这个例子本身实用性是很差的,因为使用马尔科夫预测天气效果并不好,这里仅仅是举个现实生活中的例子帮助理解马尔科夫链的建模过程。

现在我们用马尔科夫链来预测明天的天气。在这里,我们有多种选择,比如,我们用今天的天气预报明天的天气,或者我们用昨天和今天的天气预报,甚至我们用近一周的天气预报。直觉上,我们仅根据今天的天气进行预测的准确性低于较长期的天气预报。

[En]

Now we use Markov chain to predict the weather tomorrow. Here we have a variety of choices, for example, we use today’s weather to predict tomorrow’s weather, or we use yesterday’s and today’s weather to predict, or even we use nearly a week’s weather to forecast. Intuitively, the accuracy of our predictions based only on today’s weather is lower than that of longer-term weather forecasts.

这里已经包含了马尔科夫链的阶数的概念。已知今天预测明天,需要建立一阶马尔科夫链;已知两天(昨天,今天)预测明天,需要建立二阶马尔科夫链,以此类推到n阶马尔科夫链。

n阶马尔科夫链描述为,下一个阶段的状态,仅和前n个阶段的状态有关。

下一步是数据统计,我们以一阶马尔可夫链的建立为例。对于一阶链,我们需要从当前状态预测下一状态。这就引出了马尔可夫链的关键工具:概率状态转移矩阵。现在我们需要做以下概率统计:

[En]

The next step is data statistics, we take the establishment of a first-order Markov chain as an example. For the first-order chain, we need to predict the next state from the current state. This leads to the key tool of Markov chain: probabilistic state transition matrix. Now we need to do the following probability statistics:

当前状态为1,下一状态为1的概率(P11)
当前状态为1,下一状态为2的概率(P12)
当前状态为1,下一状态为3的概率(P13)
当前状态为2,下一状态为1的概率(P21)
当前状态为2,下一状态为2的概率(P22)
当前状态为2,下一状态为3的概率(P23)
当前状态为3,下一状态为1的概率(P31)
当前状态为3,下一状态为2的概率(P32)
当前状态为3,下一状态为3的概率(P33)
并把它们放入一个33的矩阵。
例如计算当前状态为1,下一状态为2的概率。我们需要在长列表中中找出为1,2的短列表个数,这样我们得到了频数,就能算出频率并近似看作概率。
所以我们得到了这样一个概率状态转移矩阵。

[En]

So we get such a probabilistic state transition matrix.

P11 P12 P13
P21 P22 P23
P31 P32 P33
它的值可能为
0.1 0.3 0.6
0.2 0.5 0.3
0.4 0.4 0.2
需要注意的是,每一行的总和必须为1,因为它只能转换为受限状态。例如,如果当前状态为2,则下一个状态只能为1/2或3。

[En]

It is important to note that the sum of each line must be 1, because it can only be transferred to a limited state. For example, if the current state is 2, then the next state can only be 1 / 2 or 3.*

从概率状态转移矩阵计算出累计状态转移矩阵

计算过程是将左边的数字相加。根据上述概率状态转移矩阵计算的累积状态转移矩阵为

[En]

The calculation process is the addition of the number on the left. The cumulative state transition matrix calculated from the above probabilistic state transition matrix is

0.1 0.4 1
0.2 0.7 1
0.4 0.8 1
如果概率状态转移矩阵正确,则累积状态转移矩阵的最右侧列必须为1。

[En]

If the probabilistic state transition matrix is correct, the rightmost column of the cumulative state transition matrix must be 1.

状态预测

生成一个0-1的随机值,并作为阈值和第x行数据进行比较,x是当前状态的值。例如当前状态为2,就和第二行数据比较。如果阈值大于等于该行第y列且小于该行第y+1列,则下一状态的值预测为y+1(小于第一列则下一状态为1)。以此类推。

高阶链建模,公式及状态预测详细过程等请阅读Synthetic High-Resolution Wind Data Generation Based on Markov Model

Original: https://blog.csdn.net/onesway2018/article/details/123899800
Author: onesway2018
Title: 马尔科夫链(Markov chain, Markov model)讲解(一阶和高阶)及其应用(建模数据预测)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/527661/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球