版本比较
Computer Simulations and Analyses on Parrondos's Paradox
正文
增加 66 行删除 66 行
36 行未改动3738394041414243444512 行未改动5859606162626364656641 行未改动10810911011111211211311411511611711811912011912012112212312415 行未改动14014114214314414514414514614714814919 行未改动1691701711721731731741751761771771781791801811821821831841851869 行未改动1961971981992002002012022032042052052062072082092102102112122132143 行未改动2182192202212222222232242252262272272282292302312322322332342352362372382382392402402412422432445 行未改动2502512522532542542552562572582592602612622632642642652662672682692702702712722732748 行未改动2832842852862872872882892902912912922932942957 行未改动30330430530630730730830931031131131231331331431531631731831932032132232232332432532632732732832933033113 行未改动34534634734834934935035135235335435435535635735835935936036136236317 行未改动3813823833843853853863873883893 行未改动3933943953963973973983994004012 行未改动40440540640740840840941041141141241341441541641741741841942042142242342442542642642742842942943043143243343443443543643743843943944044144144244344444544544644744844937 行未改动48748848949049149149249349449548 行未改动54454554654754854854955055155240 行未改动59359459559659759859759859960060160215 行未改动6186196206216226226236246246256266276285 行未改动63463563663763863863964064164264364464564664764764864965065111 行未改动66366466566666766766866967067167267367367467567667714 行未改动69269369469569669669769869969869970070170270332 行未改动73673773873974074074174274374486 行未改动83183283383483583583683783883984025 行未改动86686786886987087087187287387387487587687711 行未改动88989089189289389389489589589689789889922 行未改动92292392492592692692792892993056 行未改动98798898999099199199299399499545 行未改动104110421043104410451045104610471048104933 行未改动108310841085108610871087108810891090109181 行未改动11731174117511761177117711781179118011816 行未改动36 行未改动#### 1.1.2 Game B
##### 1.1.2.1 Game B Definition
游戏 B :如果当前资金是 $M$ 的倍数,则赢得该游戏赚取一块钱的概率为 $p_1$,如果不是,则赢得该游戏赚取一块钱概率为 $p_2$. 游戏 B :如果当前资金是 $M$ 的倍数,则赢得该游戏赚取一块钱的概率为 $p_1$,如果不是,则赢得该游戏赚取一块钱概率为 $p_2$.
例如 $M = 3,p_1 = 1/10-\varepsilon,p_2 = 3/4 - \varepsilon$:$$\begin{aligned}12 行未改动- $10^7$ 次模拟,接近线性
<img src="https://cdn.jsdelivr.net/gh/KINGLRL/ImageHost/imgs/Parrondos0.png" alt="image-20221113220005230" style="zoom: 67%;" />
FIG. 1. FIG. 1.
- $10^5$ 次模拟,线性程度减弱
<img src="https://cdn.jsdelivr.net/gh/KINGLRL/ImageHost/imgs/Parrondos1.png" alt="image-20221113220035860" style="zoom: 67%;" />41 行未改动 0.745B_i + 0.905C_i = C_{i+1} \\ \end{cases}\tag{1} $$
由于 $\lim_{i \to \infty} \{A_i\}=A$ 由于 $\lim_{i \to \infty} \{A_i\}=A$
- $$ \begin{cases} -A + 0.255B + 0.745C = 0 \\ 0.095A - B + 0.255C = 0 \\ 0.905A + 0.745B - C = 0 \\ \end{cases}\tag{2} \implies \end{cases}\tag{2} \implies \begin{bmatrix} -1 &0.255 &0.745\\ 0.095 &-1 &0.255\\ 0.905 &0.745 &-1\\15 行未改动 \begin{cases} -A + 0.255B + 0.745C = 0 \\ 0.095A - B + 0.255C = 0 \\ A + B + C = 1 \\ \end{cases}\tag{3} \implies \end{cases}\tag{3} \implies \begin{bmatrix} -1 &0.255 &0.745\\ 0.095 &-1 &0.255\\ 1 &1 &1\\19 行未改动 \end{bmatrix} = \begin{bmatrix} 1 \\ 0 \\ 0\\ \end{bmatrix}$ \end{bmatrix}$
- 根据方程 $(1)$ 构造迭代方程 $(4)$: $$ \mathbf y^{(k+1)} = \mathbf y^{(k+1)} = \begin{bmatrix} 0 &0.255 &0.745\\ 0.095 &0 &0.255\\ 0.905 &0.745 &0\\ \end{bmatrix} \cdot \mathbf y^{(k)} = \mathbf P \cdot y^{(k)} \end{bmatrix} \cdot \mathbf y^{(k)} = \mathbf P \cdot y^{(k)} \tag{4} $$
- 根据附录的迭代法收敛定理,对 **任意** $\mathbf x^{(0)}$ 序列 $\{\mathbf x^{(k)}\}$ 收敛的 ***充要条件*** 迭代矩阵的谱半径小于一:9 行未改动 0.095 &0 &0.255\\ 0.905 &0.745 &0\\ \end{bmatrix} = \mathbf X \mathbf \Lambda \mathbf X^{-1} \\\\ &= &= \begin{bmatrix} 0.3816 &0.3970 &-0.3970\\ 0.1543 &0.1030 &0.5000\\ 0.4621 &-0.5000 &-0.1030\\ \end{bmatrix} \cdot \end{bmatrix} \cdot \begin{bmatrix} 1.0000 &0 &0\\ 0 &-0.8721 &0\\ 0 &0 &-0.1279\\ \end{bmatrix} \cdot \end{bmatrix} \cdot \begin{bmatrix} 1.0000 &1.0000 &1.0000\\ 1.0315 &0.6014 &-1.0571\\ -0.5009 &1.5676 &-0.0909\\3 行未改动 则迭代 $n$ 次后可表示为 $\mathbf P^n \cdot \mathbf y$ $$ \begin{aligned} \mathbf P^n &= \mathbf X \mathbf \Lambda ^n \mathbf X^{-1}\\ &= &= \begin{bmatrix} & &\\ \mathbf x_1 &\mathbf x_2 &\mathbf x_3\\ & &\\ \end{bmatrix} \cdot \end{bmatrix} \cdot \begin{bmatrix} 1 & & \\ &\lambda_2^n &\\ & &\lambda_3^n\\ \end{bmatrix} \cdot \end{bmatrix} \cdot \begin{bmatrix} & &\\ &\mathbf X^{-1} &\\ & &\\ \end{bmatrix} \\
\lim_{n\to\infty} \mathbf P^n &=
\begin{bmatrix} & &\\ \mathbf x_1 &\mathbf x_1 &\mathbf x_1\\ & &\\5 行未改动
- 则当进行无穷次迭代后,由于初始状态 $A_0+B_0+C_0=1$,则 $(4)$ 式可写为 $$ \lim_{n\to\infty} \mathbf P^n \cdot \mathbf y_0=
\begin{bmatrix} & &\\ \mathbf x_1 &\mathbf x_1 &\mathbf x_1\\ & &\\ \end{bmatrix} \cdot \begin{bmatrix} A_0\\ B_0\\ C_0\\ C_0\\ \end{bmatrix} = \begin{bmatrix} \\ \mathbf x_1\\ \\ \\ \end{bmatrix} $$
- 则说明最后概率一定收敛于矩阵 $\mathbf P$ 特征值为 $1$ 对应的特征向量,只要初始状态概率和为 $1$,则最终结果初始状态无关。8 行未改动### 1.2 Markov Chains
#### 1.2.1 Markov Martrix
对于不同的参数 $M$, $\varepsilon$,问题 $B$ 及后面的 $A,B$ 混合问题均可转化为一个有向图上的概率转移模型,因此有必要分析关于 Markov Chains 的一些性质。[3] 对于不同的参数 $M$, $\varepsilon$,问题 $B$ 及后面的 $A,B$ 混合问题均可转化为一个有向图上的概率转移模型,因此有必要分析关于 Markov Chains 的一些性质。[3]
考虑问题 $B$ 构造的状态转移矩阵,满足:
- 转移矩阵中的元素 $p_{ij}$ 代表在 $n$ 时刻位于点 $j$,$n+1$ 时刻走向点 $i$ 的概率。且 $p_{ij}$ 与 $n$ 无关。即下一个概率状态 $\mathbf y_{n+1}$ 只与 $n$ 时刻状态 $\mathbf y_{n}$ 有关,与历史状态无关; - 转移矩阵中的元素 $p_{ij}$ 代表在 $n$ 时刻位于点 $j$,$n+1$ 时刻走向点 $i$ 的概率。且 $p_{ij}$ 与 $n$ 无关。即下一个概率状态 $\mathbf y_{n+1}$ 只与 $n$ 时刻状态 $\mathbf y_{n}$ 有关,与历史状态无关;
- 所有的 $p_{ij}>0$ 且 $\mathbf P$ 的每一列之和为一,即所有的概率为正数且每个点的概率出度为一。那么 $\mathbf 1^\top \mathbf P = \mathbf 1^\top$,即 $p_{1j}+p_{2j}+\cdots+p_{Nj}=1$.
- 状态转移矩阵有最大特征值 $\lambda_1=1$ 且其对应的特征向量 $\mathbf x_1 >0$ (为正) ;7 行未改动 FIG. 7.
形式化地讲,转移方程 $\mathbf y_{n+1} = \mathbf P \cdot \mathbf y_{n}$$$\mathbf y_{n+1} = \mathbf y_{n+1} =\begin{bmatrix}\text{Prob } \{x(n+1)=1\} \\\vdots \\\text{Prob } \{x(n+1)=N\} \text{Prob } \{x(n+1)=N\}\end{bmatrix}= =\begin{bmatrix}p_{11} &\cdots &p_{1N}\\\vdots &\ddots &\vdots\\p_{N1} &\cdots &p_{NN}\\\end{bmatrix}\begin{bmatrix}\text{Prob } \{x(n)=1\} \\\vdots \\\text{Prob } \{x(n)=N\} \text{Prob } \{x(n)=N\}\end{bmatrix} \tag{5}$$转移方程 $\mathbf y_{n+1} = \mathbf P \cdot \mathbf y_{n}$,这些向量 $\mathbf y_{i}$ 包含时刻 $i$ 的信息。所以在所有时刻,$\mathbf y_{n}$ 的元素和应为一,且 $\mathbf P^n$ 的每一列之和也应为 $1$.$$\mathbf 1^\top \mathbf y_{n+1} = \mathbf 1^\top (\mathbf P\cdot\mathbf y_{n}) = \mathbf (1^\top \mathbf P)\cdot\mathbf y_{n} = \mathbf 1^\top \cdot\mathbf y_{n} = 1 \mathbf 1^\top \mathbf y_{n+1} = \mathbf 1^\top (\mathbf P\cdot\mathbf y_{n}) = \mathbf (1^\top \mathbf P)\cdot\mathbf y_{n} = \mathbf 1^\top \cdot\mathbf y_{n} = 1\tag{6}$$既然所有的 $ \mathbf y_{n}$ 都满足概率分布,那么 $ \mathbf y_{n} = \mathbf P^n \mathbf y_{0}$ 当 $n\to \infty$ 时极限 $ \mathbf y_{\infty}$ 是否存在?如果极限存在,则此极限可以告诉我们最终状态下在每个概率点的期望频率。
13 行未改动对所有元素严格为正的矩阵 $\mathbf P_1$ 且假定其有 $n$ 个独立特征向量,由 Perron-Frobenius Theorem,有满足最大的特征值 $\lambda_1>0$ 且对应的特征向量 $\mathbf x_1 >0$。而矩阵每一列之和为一保证 $\mathbf P^\top \mathbf 1 = \mathbf 1$ , $\lambda _1 = 1$。由于特征向量线性无关,则可对角化,且其它特征值均有 $|\lambda|<1$ ,所以对角矩阵 $\Lambda^n$ 最终会变为只有左上角为 $1$ 的矩阵。所以,最终概率转移矩阵 $\mathbf P^{(\infty)}$ 是特征向量 $\mathbf x_1$ 的倍数:$$\begin{aligned}\mathbf P^n &= \mathbf X \mathbf \Lambda ^n \mathbf X^{-1}\\&= &=\begin{bmatrix} & &\\\mathbf x_1 &\mathbf x_2 &\cdots &\mathbf x_3\\ & &\\\end{bmatrix} \cdot \end{bmatrix} \cdot\begin{bmatrix}1 & & \\ &\lambda_2^n &\\ & &\ddots\end{bmatrix} \cdot \end{bmatrix} \cdot\begin{bmatrix} & &\\&\mathbf X^{-1} &\\& &\\17 行未改动\mathbf P^n \to \mathbf P^\infty = [\mathbf v_1\; \mathbf v_1\cdots \mathbf v_1], \textrm{ whenever } |\lambda_2| <1$$考虑将特征值小于一的部分单独分解出来,构造 $\mathbf X,\mathbf A$ 满足:$$\mathbf X^{-1}\mathbf P\mathbf X = \mathbf X^{-1}\mathbf P\mathbf X =\begin{bmatrix}1 &\mathbf 0\\\mathbf 0 &\mathbf A\end{bmatrix} , \textrm {the eigenvalues of }\mathbf A \textrm{ have } |\lambda_2| < 1,\ldots, |\lambda_n|<13 行未改动\mathbf P^n = \mathbf X(\mathbf X^{-1}\mathbf P\mathbf X)^n \mathbf X^{-1} =\mathbf X\begin{bmatrix}1 &\mathbf 0\\\mathbf 0 &\mathbf A^n\end{bmatrix} \mathbf X ^{-1}, \end{bmatrix} \mathbf X ^{-1},\textrm{ converges to } \mathbf v_1\mathbf 1^\top \textrm{ and }\mathbf A^n \to \mathbf 0$$
- $\mathbf A$ 的所有特征值 $|\lambda|<1$,所以 $\lim_{n\to \infty}\mathbf A^n = \mathbf 0$2 行未改动2. 那么 $\mathbf A^n = (\mathbf M\mathbf S\mathbf M^{-1})^n = \mathbf M \mathbf S^n\mathbf M^{-1}$,有 $||\mathbf A^n|| \le ||\mathbf M||||\mathbf S||^n||\mathbf M^{-1}||\to0$
由于 $\mathbf S = \mathbf M^{-1} \mathbf A\mathbf M$,即相似于 $\mathbf A$。而 $\mathbf S$ 的特征值又在其主对角线上:$$\mathbf S = \mathbf S =\begin{bmatrix}\lambda_2 &a &b\\0 &\lambda_3 &c\\ 0 &\lambda_3 &c\\0 &0 &\lambda_4\end{bmatrix}\textrm{ has } || \mathbf S|| <1 \textrm{ if }a,b,c \textrm{ are very small}$$
- 最大的特征值并不是矩阵范数,如果 $a,b,c$ 很大 $\mathbf S^2,\mathbf S^3$ 仍然会增长,直至 $n$ 较大时特征值将 $\mathbf S^n$ 拉回零矩阵。如果要一开始即保证不增长需要 $||\mathbf S||<1$. - 最大的特征值并不是矩阵范数,如果 $a,b,c$ 很大 $\mathbf S^2,\mathbf S^3$ 仍然会增长,直至 $n$ 较大时特征值将 $\mathbf S^n$ 拉回零矩阵。如果要一开始即保证不增长需要 $||\mathbf S||<1$.- 我们已经有 $|\lambda_i| <1$,如果 $a,b,c$ 非常小,则 $\mathbf S$ 的范数仍然小于一
$$||\mathbf S|| \le ||\textrm{diagonal part}|| + ||\textrm{off-diagonal part}|| < 1$$
由 Schur's Theorem, 任意矩阵 $\mathbf A$ 均相似于某个上三角矩阵 $\mathbf T = \mathbf Q^{-1}\mathbf A\mathbf Q$,则可构造$$\mathbf D^{-1}\mathbf T \mathbf D = \mathbf D^{-1}\mathbf T \mathbf D =\begin{bmatrix}1& &\\&1/d &\\ &1/d &\\& &1/d^2\end{bmatrix}\begin{bmatrix}\lambda_2 &A &B\\0 &\lambda_3 &C\\ 0 &\lambda_3 &C\\0 &0 &\lambda_4\end{bmatrix}\begin{bmatrix}1& &\\&d &\\ &d &\\& &d^2\end{bmatrix} \end{bmatrix}=\begin{bmatrix}\lambda_2 &dA &d^2B\\0 &\lambda_3 &dC\\ 0 &\lambda_3 &dC\\0 &0 &\lambda_4\end{bmatrix}= \mathbf S$$37 行未改动 \begin{aligned} \mathbf G &= \mathbf J + \mathbf P \cdot\mathbf F - \mathbf F \\ \pi\mathbf G &= \pi\mathbf J + \pi\mathbf P \cdot\mathbf F - \pi\mathbf F \\ \pi\mathbf G &= \pi\mathbf J \\
\end{aligned} $$ 所以有 $$48 行未改动
问题(2) 为 $ABBABB\cdots$,单局期望收益有极大值,$5.714\times10^{-2}$
```expectation[b, a] = expectation[b, a] = a = 1, 6 a = 2, 7 a = 3, 8 a = 4, 9 a = 5, 10[b = 1 [-6.77011e-03 8.87010e-03 6.24250e-03 3.27970e-03 1.61430e-03 -2.98100e-04 -1.68310e-03 -2.80670e-03 -3.20330e-03 -3.40810e-03] b = 2 [*5.71431e-02* 1.46251e-02 2.00657e-02 1.01691e-02 9.72610e-0340 行未改动0 &0&0 &0.095 &0 & 0.255\\0 &0&0 &0.905 &0.745 &0 \\0 &0.505 &0.495 &0 &0 &0 \\0.495&0 &0.505 &0 &0 &0 \\0.505&0.495 &0&0 &0 &0 \end{bmatrix} \cdot 0.505&0.495 &0&0 &0 &0\end{bmatrix} \cdot\begin{bmatrix}A_0^{(n)}\\A_1^{(n)}\\A_2^{(n)}\\15 行未改动 0 0 0 .905 .745 0; 0 .505 .495 0 0 0; .495 0 .505 0 0 0; .505 .495 0 0 0 0]
[V, D] = eig(A)
V = normalize(V, 'norm', 1).*2 ```
- 特征矩阵 $\mathbf V$5 行未改动 <img src="赌局.assets/image-20221204212518470.png" alt="image-20221204212518470" style="zoom:50%;" />
- 其中,得到保留的特征向量 $\mathbf v_1,\mathbf v_3$ 应具有特殊的性质 ($\lambda_1 = -1, \lambda_3 = 1$) $$ \mathbf v_1 = \mathbf v_1 = \begin{bmatrix} 0.2347\\ 0.0759\\ 0.6895\\ -0.3796\\ -0.4643\\ -0.1561 \end{bmatrix}, \mathbf v_3 = \mathbf v_3 = \begin{bmatrix} 0.2347\\ 0.0759\\ 0.6895\\11 行未改动 $$ \begin{aligned} \mathbf y_{n+1} &= \mathbf P\cdot \mathbf y_{n} = -c_1\cdot \mathbf v_1 + c_3\cdot \mathbf v_3 \\ \mathbf y_{n+2} &= \mathbf P\cdot \mathbf y_{n+1} = c_1\cdot \mathbf v_1 + c_3\cdot \mathbf v_3 \\
\end{aligned} \tag{12} $$ 考虑 $\mathbf 1^\top \mathbf y_{n} = \mathbf 1^\top \mathbf y_{n+1}=1$, 带入 $(12)$ 有 $c_3=1/2$,带入 $(11)$ 有 : $$ \hat y= \hat y= c_1\cdot \begin{bmatrix} 0.2347\\ 0.0759\\14 行未改动 考虑两个状态下分别前三个元素和后三个元素为零,则有 $c_1=1/2$
所以对于任意初始向量,当前特征值 $\mathbf v_1,\mathbf v_3$ 的***组合系数均为二分之一***。
- 即 - 即 $$ \lim_{n\to\infty} \mathbf y_n&= \lim_{n\to\infty} \mathbf y_n&=
\frac 1 2(-1)^n\begin{bmatrix} 0.2347\\ 0.0759\\ 0.6895\\32 行未改动 0\\ 0\\ 0 \end{bmatrix},
\textrm{Game B : } \mathbf x_B= \begin{bmatrix} A_0\\86 行未改动 else: return -1 else: if (x <= 7450): return 1 # 如果不是三的倍数 else: return -1
for i in range(1, 10000000): n = n + play(n) y.append(n) x.append(i)25 行未改动def play2(): x = random.randint(1, 1000) if (x <= 495): return 1 else: return -1
times = 10000
def simulate(a = 0, b = 0): def simulate(a = 0, b = 0): y = [] n = 0 roundcnt = a + b if (a != 0 and b != 0):11 行未改动x = list(range(1, times))
params = [(1, 1), (1, 2), (0, 0), (2, 2)]
d2l.plot(x, [simulate(a, b) for a, b in params], xlabel='times of gambling',ylabel='gain', figsize=(9, 5), d2l.plot(x, [simulate(a, b) for a, b in params], xlabel='times of gambling',ylabel='gain', figsize=(9, 5), legend=[f'[a={a}, b={b}]' for a, b in params])d2l.plot(x, [simulate(a, b) for a, b in params], xlabel='times of gambling',ylabel='gain', figsize=(9, 5), d2l.plot(x, [simulate(a, b) for a, b in params], xlabel='times of gambling',ylabel='gain', figsize=(9, 5), legend=[f'[a={a}, b={b}]' for a, b in params])```
### iii. 3D image of $[A_{0.005}^aB_{0.005}^b]$22 行未改动def play2(): x = random.randint(1, 1000) if (x <= 495): return 1 else: return -1
times = 10000000
def simulate(a = 0, b = 0): # 模拟游戏 y = []56 行未改动
ax.plot_surface(X, Y, Z,cmap='plasma', edgecolor='white', alpha=1)
ax.plot_surface(XX, YY, Z2,cmap='plasma',alpha=0.3) ax.plot_surface(XX, YY, Z2,cmap='plasma',alpha=0.3)
ax.set_title('Simulations')ax.set_xlabel('times of A')ax.set_ylabel('times of B')45 行未改动1. 非负性
2. 齐次性 $$ || c \cdot \mathbf A|| = |c| \cdot||\mathbf A|| || c \cdot \mathbf A|| = |c| \cdot||\mathbf A|| $$
3. 三角不等式 Triangle Inequality $$33 行未改动
- $$ \begin{aligned} \max_{\mathbf x \ne 0} \frac{\mathbf x^\top \mathbf A^\top \mathbf A \mathbf x}{\mathbf x^\top \mathbf x} &= \frac{(c_1\mathbf q_1 + \cdots + c_n \mathbf q_n)^\top (c_1\lambda_1\mathbf q_1 + \cdots + c_n \lambda_n \mathbf q_n)}{(c_1\mathbf q_1 + \cdots + c_n \mathbf q_n)^\top (c_1\mathbf q_1 + \cdots + c_n \mathbf q_n)} \\ &= \frac{c_1^2 \lambda_1 + \cdots + c_n^2 \lambda_n}{c_1^2 + \cdots + c_n^2} \le \lambda_{\max} &= \frac{c_1^2 \lambda_1 + \cdots + c_n^2 \lambda_n}{c_1^2 + \cdots + c_n^2} \le \lambda_{\max} \end{aligned} $$
- 补充:$|| \mathbf A||$ equals the *largest singular value* $\sigma_{\max}$ of $\mathbf A$81 行未改动
- 若矩阵 $\mathbf A_{n\times n}$ 满足对所有的行 $i$,有 $|a_{i,i}| \ge \sum_{j \ne i} |a_{i,j}|$ 且至少有一个严格不等式成立,则称 $\mathbf A$ 为弱对角占优矩阵。若所有不等式均为严格大于,则称为(行)严格对角占优矩阵.
- $$ |a_{i,i}| > \sum_{j \ne i} |a_{i,j}|, \textrm{ where } i=1,2,\cdots,n |a_{i,i}| > \sum_{j \ne i} |a_{i,j}|, \textrm{ where } i=1,2,\cdots,n $$
对 $\mathbf A \mathbf x = \mathbf b$,若 $\mathbf A $ 为严格占优矩阵,则
6 行未改动