Computer Simulations and Analyses on Parrondos's Paradox - V2
DarkMoon_Dragon · · 个人记录
Computer Simulations and Analyses on Parrondos's Paradox
廖润龙 2021141500076
Abstract
本研究探讨了两个独立赌局
关键字:Parrondo's Paradox, Markov Chain, Random Walk, Graph Theory, Probability
1. Introduction
概率理论的研究可追溯至十七世纪,始于数学家们对赌博问题的探索。在当今时代,概率理论在神经网络和计算智能领域展现出显著的应用价值。特别地,马尔可夫模型 [1] 已在互联网生态系统中发挥广泛作用,例如在谷歌的网页排名算法中得到应用。Parrondo 提出的悖论 [2] 则是一个通过结合两个失效策略来产生成功策略的反直觉模型,此模型可由马尔可夫链构建。本文首先详细介绍帕隆多悖论中的基本模型及其定量分析方法,并阐释为何将预期亏损的游戏组合起来会产生正收益。
1.1 Parrondo's Games [2]
1.1.1 游戏 A
让我们考虑游戏
- 其中,
\varepsilon 是调整胜败概率的超参数。
令随机变量
当
1.1.2 游戏 B
1.1.2.1 游戏 B定义
游戏
以
下令
1.1.2.2 游戏 B 的模拟计算
下图为不同次数的计算机模拟,观察出游戏 B 的收益和次数的线性关系。 (Appendix code i)
-
<img src="https://cdn.jsdelivr.net/gh/KINGLRL/ImageHost/imgs/Parrondos0.png" /> FIG. 1. -
<img src="https://cdn.jsdelivr.net/gh/KINGLRL/ImageHost/imgs/Parrondos1.png" /> FIG. 2. -
<img src="https://cdn.jsdelivr.net/gh/KINGLRL/ImageHost/imgs/Parrondos2.png" /> FIG. 3. -
<img src="https://cdn.jsdelivr.net/gh/KINGLRL/ImageHost/imgs/Parrondos3.png" /> FIG. 4. -
取
\varepsilon = -0.005 ,10^7 模拟后可以接近收支平衡:<img src="https://cdn.jsdelivr.net/gh/KINGLRL/ImageHost/imgs/Parrondos4.png" />
FIG. 5.
1.1.2.3 游戏 B 的定量分析
设现在的资金为
-
A:n \bmod 3 =0 -
B:n \bmod 3=1 -
C:n \bmod 3 =2
根据游戏
-
<img src="https://cdn.jsdelivr.net/gh/KINGLRL/ImageHost/imgs/Parrondos5.png" />
FIG. 6. 其中有向边
u\to v 表示P(X_n=v \mid X_{n-1}=u)
设
-
\begin{cases} 0.255B_i + 0.745C_i = A_{i+1} \\ 0.095A_i + 0.255C_i = B_{i+1} \\ 0.745B_i + 0.905C_i = C_{i+1} \\ \end{cases}\tag{1}
由于该马氏链有限,则存在平稳分布:
-
\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 \begin{bmatrix} -1 &0.255 &0.745\\ 0.095 &-1 &0.255\\ 0.905 &0.745 &-1\\ \end{bmatrix} \cdot \begin{bmatrix} A \\ B \\ C\\ \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \\ 0\\ \end{bmatrix} \iff \mathbf P \cdot \mathbf y = \mathbf 0
构造常数概率方程
-
\begin{cases} -A + 0.255B + 0.745C = 0 \\ 0.095A - B + 0.255C = 0 \\ A + B + C = 1 \\ \end{cases}\tag{3} \implies \begin{bmatrix} -1 &0.255 &0.745\\ 0.095 &-1 &0.255\\ 1 &1 &1\\ \end{bmatrix} \cdot \begin{bmatrix} A \\ B \\ C\\ \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \\ 1\\ \end{bmatrix} 解得
[A\;B\;C]^\top=[0.3836\;0.1543\;0.4621]^\top .
同样,我们可以考虑
-
设初始状态
\mathbf{y}_0=\begin{bmatrix} A_0 \\ B_0 \\ C_0\\ \end{bmatrix} = \begin{bmatrix} 1 \\ 0 \\ 0\\ \end{bmatrix} -
根据方程
(1) 构造迭代方程(4) :\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)} \tag{4} - 根据附录的迭代法收敛定理,对 任意
\mathbf x^{(0)} 序列\{\mathbf x^{(k)}\} 收敛的 充要条件 迭代矩阵的谱半径小于一:\rho (\mathbf P) < 1
计算得,迭代矩阵
\rho(\mathbf P) \le 1 ,则该迭代矩阵不一定对任意初始向量均收敛(但从马氏链的相关知识可以得知,对定义在\mathcal S 上概率测度向量一定收敛)。计算
\mathbf P 的特征值及特征向量有:\begin{aligned} \mathbf P &= \begin{bmatrix} 0 &0.255 &0.745\\ 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 \begin{bmatrix} 1.0000 &0 &0\\ 0 &-0.8721 &0\\ 0 &0 &-0.1279\\ \end{bmatrix} \cdot \begin{bmatrix} 1.0000 &1.0000 &1.0000\\ 1.0315 &0.6014 &-1.0571\\ -0.5009 &1.5676 &-0.0909\\ \end{bmatrix} \end{aligned} 则迭代
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 \begin{bmatrix} 1 & & \\ &\lambda_2^n &\\ & &\lambda_3^n\\ \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\\ & &\\ \end{bmatrix} \end{aligned} -
注意到
\mathbf X^{-1} 第一行均为一 (实际上 Markov 矩阵的左特征值恒为\mathbf 1^\top ) -
则当进行无穷次迭代后,由于初始状态
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\\ \end{bmatrix} = \begin{bmatrix} \\ \mathbf x_1\\ \\ \end{bmatrix} - P.S. 这里
A_0 + B_0 + C_0 = 1 即验证了讲义中证明「极限分布存在则为平稳分布」中最后一步,\sum \pi_0(x)=1
- P.S. 这里
-
则说明最后概率一定收敛于矩阵
\mathbf P 特征值为1 对应的特征向量,只要初始状态概率和为1 ,则最终结果初始状态无关。
- 根据附录的迭代法收敛定理,对 任意
由上文分析,则长远来看,
- 与程序模拟算出的单次期望相契合,得出结论:单独进行游戏
B 平均每局亏损-0.008724
1.2 对马氏链转移矩阵的讨论
1.2.1 马尔可夫矩阵
对于不同的参数
考虑问题
-
转移矩阵中的元素
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 (为正) ; -
已知初始概率
\mathbf y_{0} 或其满足的条件。 -
构造对应概率转移图,例如:
<img src="https://cdn.jsdelivr.net/gh/KINGLRL/ImageHost/imgs/Parrondos5.png" />
FIG. 7.
转移方程
转移方程
既然所有的
注意到并非所有的情况下均会收敛,虽然随机矩阵不会爆炸,但是可能出现跳跃的情况(不收敛),例如
1.2.2 Positive P or Nonegative P
对于转移概率矩阵,
由于
-
\mathbf P_2$ 包含零元素。则可能存在第二个大小为 $1$ 特征向量 $\lambda_2 -
1. 最大的特征值 $\lambda_1$ 及其对应的特征向量 $\mathbf v_1$ 是严格大于零的。 2. 其他特征值 $\lambda_2,\cdots,\lambda_N$ 有 $|\lambda| < \lambda_1$,对 Markov 矩阵有 $\lambda_1 = 1$。
对所有元素严格为正的矩阵
- 所以
\mathbf P^\top 是一个非负矩阵,特征值其一为\lambda=1 ,对应的特征向量\mathbf 1 = (1,1,\cdots,1)^\top
对于一般情况,即矩阵
考虑将特征值小于一的部分单独分解出来,构造
那么,
-
\mathbf A$ 的所有特征值 $|\lambda|<1$,所以 $\lim_{n\to \infty}\mathbf A^n = \mathbf 0
- 找到一个上三角矩阵
\mathbf S = \mathbf M^{-1} \mathbf A\mathbf M ,其范数||\mathbf S||<1 - 那么
\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
由于
- 最大的特征值并不是矩阵范数,如果
a,b,c 很大\mathbf S^2,\mathbf S^3 仍然会增长,直至n 较大时特征值将\mathbf S^n 拉回零矩阵。如果要一开始即保证不增长需要||\mathbf S||<1 . - 我们已经有
|\lambda_i| <1 ,如果a,b,c 非常小,则\mathbf S 的范数仍然小于一
由 Schur's Theorem, 任意矩阵
则对非常小的
至此,我们证明了
1.3 Brownian Ratchets
<img src="https://cdn.jsdelivr.net/gh/KINGLRL/ImageHost/imgs/Parrondos6.png" />
- FIG. 8. 含有棘轮和棘爪的机械设备。设备由两个盒子组成,其中一个装有单向旋转的轮子,另一个装有棘轮和棘爪。每个盒子均置于处于热平衡状态的气体分子中。这两个盒子通过一个隔热轴机械连接。整个装置设计得极其微小,以使气体分子能随机撞击叶片产生运动。[6]
上图展示了一个含有棘轮和棘爪的机械装置,最初由费曼在 1962 年提出作为一种理论上的永动机。该设计基于波兰物理学家斯莫卢霍夫斯基 (M. Smoluchowski, 1912) 的早期研究。斯莫卢霍夫斯基构想了一种能够从处于温度平衡状态的系统中提取有用功的微观机器,这通过利用气体分子的热布朗运动来实现。如图所示,该机器由一个小桨轮和一个通过轮轴连接的棘轮组成,均置于温度相同
费曼对斯莫卢霍夫斯基的假设性实验进行了校正 [7],并证明了棘轮并不会持续沿同一方向转动 [6]。这是因为制转杆本身也会展现布朗运动,即上下抖动,导致棘轮的齿轮有时向后滑动而非前进。费曼对该设备进行了首次定量分析,得出结论:随时间推移,机器向后转动的次数将与向前转动次数相等,从而抵消任何做功的可能性。而且,如果没有外部能量输入,这种装置最终可能会失去能量。
Magnasco 在 1993 年发表的一篇论文 [8] 进一步发展了布朗棘轮的概念。在这篇论文中,他阐述了布朗微粒可以在特定的空间非对称能量势场下产生定向移动。
一个引人注目的例子 ——“交错棘轮”,这是一种被周期性地“开启”和“关闭”的倾斜系统。通过解福克-普朗克方程,研究者发现,在这样的系统中,布朗粒子可以实现“上坡”移动(Doering, 1995)。相反地,如果电位始终保持在“开启”或“关闭”状态,粒子则会“下坡”移动。这种现象成为帕朗多悖论的灵感来源:尽管每个单独的状态都似乎是一个“失败”的游戏,但当这些状态交替进行时,它们可以产生使粒子“上坡移动”的综合效果,或者说是产生“获胜”的期望。
2.1 结果
2.2.1 AB 轮流进行的模拟计算
在前文中,我们已经对游戏
然而,一个非常反直觉的现象是:如果我们交替进行游戏
以下图表展示了在四种不同情况下进行
图 9.
现在我们引入一种新的表示方法来描述这些游戏。当游戏
下图绘制了
-
<img src="https://cdn.jsdelivr.net/gh/KINGLRL/ImageHost/imgs/Parrondos8.png" />
FIG. 10.
问题(2) 为
ABBABB\cdots ,单局期望收益有极大值,5.714\times10^{-2}
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-03
6.65650e-03 4.37210e-03 2.86550e-03 2.28210e-03 1.31050e-03]
b = 3 [-2.78710e-03 1.08350e-03 4.72100e-04 -1.57590e-03 -2.45330e-03
-3.42490e-03 -3.61850e-03 -4.36010e-03 -4.80130e-03 -5.23950e-03]
b = 4 [ 2.95377e-02 5.19630e-03 1.04617e-02 4.97170e-03 4.93490e-03
3.07010e-03 2.23470e-03 8.96900e-04 -1.38900e-04 -9.17900e-04]
b = 5 [ 1.31690e-03 -1.12750e-03 -2.01900e-04 -2.09470e-03 -2.47510e-03
-2.94870e-03 -3.95350e-03 -4.50690e-03 -4.75770e-03 -4.84930e-03]
b = 6 [ 1.69829e-02 1.71130e-03 5.72630e-03 1.63050e-03 1.79270e-03
3.77000e-05 -8.15100e-04 -1.08530e-03 -1.48770e-03 -2.21610e-03]
b = 7 [ 1.96870e-03 -2.52430e-03 -1.15450e-03 -2.93830e-03 -3.36250e-03
-3.58910e-03 -3.94910e-03 -4.84870e-03 -4.83650e-03 -4.57230e-03]
b = 8 [ 1.05479e-02 -9.95900e-04 2.50430e-03 5.30000e-06 -3.58900e-04
-1.74130e-03 -2.01530e-03 -2.35070e-03 -2.81710e-03 -3.41350e-03]
b = 9 [ 1.25310e-03 -3.56370e-03 -2.05030e-03 -3.86810e-03 -2.76850e-03
-4.27150e-03 -4.09670e-03 -4.78250e-03 -5.19590e-03 -5.46930e-03]
b = 10[ 6.43670e-03 -2.20150e-03 3.11900e-04 -2.10310e-03 -1.19350e-03
-3.07450e-03 -2.87650e-03 -3.68650e-03 -3.58370e-03 -3.52730e-03]]
2.2.2 对 (A_{0.005}^1B_{0.005}^1)^n 的定量分析
下针对游戏
画出
-
<img src="https://cdn.jsdelivr.net/gh/KINGLRL/ImageHost/imgs/Parrondos9.png" alt="image-20231229145018896" style="zoom:67%;" />
FIG. 11. 该情形下的状态转移图
我们记状态 :
-
如上预期,
\mathbf P 的两个极大特征值为-1 和1 ,最终概率向量将在两个特征向量中来回切换,即该马氏链的周期为2 -
幸运的是,这个矩阵是可以对角化的,我们将
P 对角化:A = [0 0 0 0 .255 .745; 0 0 0 .095 0 .255; 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 <img src="https://cdn.jsdelivr.net/gh/KINGLRL/ImageHost/imgs/Parrondos17.png" />
其对应的特征值
<img src="https://cdn.jsdelivr.net/gh/KINGLRL/ImageHost/imgs/Parrondos16.png" />
-
-
其中,得到保留的特征向量
\mathbf v_1,\mathbf v_3 应具有特殊的性质 (\lambda_1 = -1, \lambda_3 = 1 )\mathbf v_1 = \begin{bmatrix} 0.2347\\ 0.0759\\ 0.6895\\ -0.3796\\ -0.4643\\ -0.1561 \end{bmatrix}, \mathbf v_3 = \begin{bmatrix} 0.2347\\ 0.0759\\ 0.6895\\ 0.3796\\ 0.4643\\ 0.1561 \end{bmatrix} -
考虑任意初始概率向量
\mathbf y 由\mathbf v_1,\mathbf v_2,\cdots, \mathbf v_n 线性表出。取其中不会衰减的两个特征值:\hat {\mathbf y }= c_1\cdot \mathbf v_1 + c_3\cdot \mathbf v_3 \tag{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= c_1\cdot \begin{bmatrix} 0.2347\\ 0.0759\\ 0.6895\\ -0.3796\\ -0.4643\\ -0.1561 \end{bmatrix}+ \begin{bmatrix} 0.2347\\ 0.0759\\ 0.6895\\ 0.3796\\ 0.4643\\ 0.1561 \end{bmatrix} 考虑两个状态下分别前三个元素和后三个元素为零,则有
c_1=1/2 所以对于任意初始向量,当前特征值
\mathbf v_1,\mathbf v_3 的组合系数均为二分之一。 -
即
\lim_{n\to\infty} \mathbf y_n&= \frac 1 2(-1)^n\begin{bmatrix} 0.2347\\ 0.0759\\ 0.6895\\ -0.3796\\ -0.4643\\ -0.1561 \end{bmatrix}+ \frac 1 2 \begin{bmatrix} 0.2347\\ 0.0759\\ 0.6895\\ 0.3796\\ 0.4643\\ 0.1561 \end{bmatrix} \tag{13} -
即得
A 游戏三种状态的概率,B 游戏三种状态的概率:\textrm{Game A : } \mathbf x_A= \begin{bmatrix} A_0\\ A_1\\ A_2\\ B_0\\ B_1\\ B_2 \end{bmatrix}= \begin{bmatrix} 0.2347\\ 0.0759\\ 0.6895\\ 0\\ 0\\ 0 \end{bmatrix}, \textrm{Game B : } \mathbf x_B= \begin{bmatrix} A_0\\ A_1\\ A_2\\ B_0\\ B_1\\ B_2 \end{bmatrix}= \begin{bmatrix} 0\\ 0\\ 0\\ 0.3796\\ 0.4643\\ 0.1561 \end{bmatrix} 带入验证,可以发现
\mathbf P^{2n} = [\mathbf x_A\;\mathbf x_A\cdots\mathbf x_A], \mathbf P^{2n+1} = [\mathbf x_B\;\mathbf x_B\cdots\mathbf x_B] 符合预期。(13) 这种情形,即 1.2 所述的\lambda_2 = -1 时的概率跳跃。 -
由于交替进行,并且游戏
B 中亏钱的概率降低,所以导致最终结果向正期望偏移。如果能矫正概率分布使得B_0 的比率尽量小,则可以做到正数收益。所以本质上说由于游戏A 与游戏B 的交互,导致游戏B 的概率分布变化,从而导致游戏期望收益变成正数。
计算最终单次期望:
-
\begin{aligned} \mathbb E(\bar{x}) &= \sum_{i=1}^3\mathbb E(x \mid A_i)\cdot P(A_i) + \mathbb E(x \mid B_i)\cdot P(B_i) \\ &=-0.010/2+ (0.3796\cdot-0.81+0.4643\cdot0.49+0.1561\cdot 0.49)/2\\ &=-0.00674 \end{aligned} 对比程序模拟期望:
-6.77011e-03
2.2.3 讨论
对于上面交替进行两种赌局,实际上可以等价考虑为粒子在交替出现的势能场下的布朗运动。考虑一个一维的坐标轴中交替出现两个势能
<img src="https://cdn.jsdelivr.net/gh/KINGLRL/ImageHost/imgs/Parrondos12.png" />
- FIG. 12. 棘轮势的作用机理。左边的图表,
(a)-(c) ,展示了没有宏观梯度存在且粒子的净运动的方向向右(箭头方向)。右边的图表(d)-(f) 有轻微的梯度,这导致粒子在U_{\text{off}} 作用后整体向做移动,尽管正向粒子的净流量减少了,但粒子整体仍在向右移动。
势能场
考虑到上文中所述的棘轮势,其与赌局结果的相似性令人瞩目。当
鉴于这两个模型的相似性,我们可以提出一个合理的假设:上述的赌局游戏也有一个和资金状况相关联的 “势场”。如果这个势场存在,为了如何找到这个势场?在一个真实的物理系统中,一种可行的测定方法是将粒子均匀地放置在电势存在的地方,记录它们的起始位置,然后释放这些粒子,直至它们达到平衡,然后记录其停止的位置。例如,如果存在一个如图 12(a) 所示的未知的势,那么结果将如图 13(a) 所示。粒子的轨迹模式与电势的形状直接相关。对于游戏 B,我们可以把本金看作布朗棘轮中的粒子。因此,为了找到游戏 B 的势,我们从不同数量的本金开始,玩一些游戏,直到达到稳定状态,并记录最终的资金。结果如图 13(a) 所示。游戏 B 的资金流动图示为 13(b) 中,每当资金达到
<img src="https://cdn.jsdelivr.net/gh/KINGLRL/ImageHost/imgs/Parrondos13.png"/>
- FIG. 13.
两个模型都有非常相似的势。因此,我们期望这两个系统的基本特征也是相似的。我们从图 12(b) 中的
References
- Norris J R, Norris J R. Markov chains[M]. Cambridge university press, 1998.
- Harmer G P, Abbott D. Losing strategies can win by Parrondo's paradox[J]. Nature, 1999, 402(6764): 864-864.
- Strang G, Strang G, Strang G, et al. Introduction to linear algebra[M]. Wellesley, MA: Wellesley-Cambridge Press, 1993.
- Perron–Frobenius theorem - Wikipedia (https://en.wikipedia.org/wiki/Perron–Frobenius_theorem)
- IOI2019 中国国家候选队论文集, 浅谈图模型上的随机游走问题, 成都市第七中学,王修涵
- Harmer G P, Abbott D. Parrondo's paradox[J]. Statistical Science, 1999: 206-213.
- Parrondo and Espafiol disagree with the efficiency of the ratchet and pawl engine calculated by Feynman; Parrondo and Espaniol, 1996
- Magnasco M O. Forced thermal ratchets[J]. Physical Review Letters, 1993, 71(10): 1477.
Appendix
A. Code
i. Game B
# 模拟游戏 B 的期望收益
%matplotlib inline
import math
import time
import numpy as np
import torch
from d2l import torch as d2l
import random
x = []
y = []
n = 0
def play(n): # 模拟单次游戏
x = random.randint(1, 10000)
if (n % 3 == 0): # 如果是三倍数
if (x <= 950): return 1
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)
d2l.plot(x[::], y[::], xlabel='times',
ylabel='money', figsize=(9, 5))
ii. 2D image of [A_{0.005}^aB_{0.005}^b]
# 绘制 AB 轮流进行的二维收益线性图
%matplotlib inline
import math
import time
import numpy as np
import torch
from d2l import torch as d2l
import random
def play1(n):
x = random.randint(1, 10000)
if (n % 3 == 0):
if (x <= 950): return 1
else: return -1
else:
if (x <= 7450): return 1
else: return -1
def play2():
x = random.randint(1, 1000)
if (x <= 495): return 1
else: return -1
times = 10000
def simulate(a = 0, b = 0):
y = []
n = 0
roundcnt = a + b
if (a != 0 and b != 0):
for i in range(1, times):
if (i % roundcnt < a): n = n + play1(n)
else: n = n + play2()
y.append(n)
else: # 随机进行
for i in range(1, times):
if (random.randint(1, 10) > 5): n = n + play1(n)
else: n = n + play2()
y.append(n)
return y
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),
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),
legend=[f'[a={a}, b={b}]' for a, b in params])
iii. 3D image of [A_{0.005}^aB_{0.005}^b]
# 绘制 [10,10] 的三维收益关系图
%matplotlib inline
import math
import time
import numpy as np
import torch
import random
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt
def play1(n):
x = random.randint(1, 10000)
if (n % 3 == 0):
if (x <= 950): return 1
else: return -1
else:
if (x <= 7450): return 1
else: return -1
def play2():
x = random.randint(1, 1000)
if (x <= 495): return 1
else: return -1
times = 10000000
def simulate(a = 0, b = 0): # 模拟游戏
y = []
n = 0
roundcnt = a + b
if (a != 0 and b != 0):
for i in range(1, times):
if (i % roundcnt < a): n = n + play1(n)
else: n = n + play2()
y.append(n)
else: # 随机进行
for i in range(1, times):
if (random.randint(1, 10) > 5): n = n + play1(n)
else: n = n + play2()
y.append(n)
return y[-1] / times
x = list(range(1, times))
params = [(1, 1), (1, 2), (0, 0), (2, 2)]
X = []
Y = []
Z = []
for x in range(1, 11):
for y in range(1, 11):
X.append(x), Y.append(y), Z.append(simulate(x, y))
X = np.arange(1, 11)
Y = np.arange(1, 11)
X, Y = np.meshgrid(X, Y)
Z = np.array(Z)
Z = Z.reshape((10, 10))
maxz = np.max(Z)
print(Z)
font={'family':'serif',
'style':'italic',
'weight':'normal',
'color':'red',
'size':16
}
fig = plt.figure(figsize=(15, 15))
ax = plt.axes(projection='3d')
XX = np.arange(0.5, 11.5, 1)
YY = np.arange(0.5, 11.5, 1)
XX, YY = np.meshgrid(XX, YY)
Z2 = np.zeros((11, 11))
ax.set_xlim(10, 0)
ax.set_ylim(0, 10)
# 调用plot_surface()函数
ax.plot_surface(X, Y, Z,cmap='plasma', edgecolor='white', alpha=1)
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')
ax.set_zlabel('Gains ratio')
ax.set(zticklabels=[])
plt.xticks(np.arange(1, 11, 1))
plt.yticks(np.arange(1, 11, 1))
ax.text(1 + 1.6 , 2 , maxz, "Maximum at [1, 2]", fontdict = font)
# ax.invert_xaxis()
plt.show()
B. 迭代方程
向量收敛
向量收敛本质为
一个
常见向量范数
-
L_2$ 范数:$||x||_2=\left(\sum_{i=1}^n x_i^2\right)^{1/2} -
L_1$ 范数:$||x||_1=\sum_{i=1}^n |x_i| -
\infty $ 范数:$||x||_{\infty} = \max_{1\le i\le n}|x_i|
范数等价性
对于
-
\forall \mathbf x \in \mathbb R ^n,\;m||\mathbf x||_{\beta} \le ||\mathbf x||_{\alpha} \le M||x||_{\beta}
一个点列如果在任意一个范数意义下收敛,则在其它所有范数意义下收敛。
那么只用验证无穷范数意义下收敛。
依坐标收敛
满足
依范数收敛
满足
矩阵范数 Matrix Norms
满足条件:
-
非负性
-
齐次性
|| c \cdot \mathbf A|| = |c| \cdot||\mathbf A|| -
三角不等式 Triangle Inequality
||\mathbf A + \mathbf B|| \le || \mathbf A + \mathbf B || -
相融性 Growth factor
||\mathbf A|| 相融性:设
||\mathbf x||,||\mathbf A|| 分别为\mathbb R^n, \mathbb R^{n\times n} 上的范数,如果满足||\mathbf{Ax}|| \le ||\mathbf A|| \cdot ||\mathbf x|| ,则称该矩阵范数与此向量范数相融|| \mathbf A \mathbf x|| \le ||\mathbf A||\cdot||\mathbf x|| \textrm{ and } ||\mathbf {AB}|| \le ||\mathbf A||\cdot ||\mathbf B||
定义:矩阵的算子范数:设
-
||\mathbf A||_p= \sup_{\mathbf x \ne 0} \frac{||\mathbf{Ax}||_p}{||\mathbf x||_p}=\max _{||\mathbf x||_p=1} ||\mathbf{Ax}||_p -
称为矩阵的算子范数
- 例如
||\mathbf I || = ||\mathbf Q|| =1 : errors don't grow - 根据定义有
|| \mathbf A \mathbf x|| \le ||\mathbf A||\cdot||\mathbf x|| - 对角矩阵的矩阵范数等于其最大元素(最大特征值)
- 例如
-
若矩阵为对称正定矩阵,则
||\mathbf A|| = \lambda_{\max}(\mathbf A) 对任意矩阵,推广为
||\mathbf A||^2 = \max_{\mathbf x \ne 0} \frac{|| \mathbf A \mathbf x || ^2}{||\mathbf x||^2} = \max_{\mathbf x \ne 0} \frac{\mathbf x^\top \mathbf A^\top \mathbf A \mathbf x}{\mathbf x^\top \mathbf x} = \lambda_{\max} (\mathbf A ^\top \mathbf A) 证明:
-
设
\mathbf A^\top \mathbf A 的特征向量为\mathbf q_1, \mathbf q_2,\cdots, \mathbf q_n . 则任意向量\mathbf x 均可由特征向量线性表出,且\mathbf q_i^\top \mathbf q_j=0 -
\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} \end{aligned}
-
-
补充:
|| \mathbf A|| equals the largest singular value\sigma_{\max} of\mathbf A -
又若
\mathbf A 非奇异,则||\mathbf A^{-1}||_2 = \lambda_{\min} (\mathbf A)^{-1}
三种常见的算子范数:
- 谱范数:
||\mathbf A||_2 = \sqrt{\lambda_{\max} (\mathbf A^\top \mathbf A)} - 列范数:
||\mathbf A||_1 = \max_{1 \le j\le n} \sum_{i=1}^n|a_{i,j}| - 行范数:
||\mathbf A||_\infty = \max_{1 \le i\le n} \sum_{j=1}^n|a_{i,j}|
F-范数
谱半径
设
-
-
设
\varepsilon 为任意指定小正数,则必存在算子范数||\cdot||_* 满足||\mathbf A||_* \le \rho(\mathbf A) + \varepsilon -
\lim_{n\to \infty} \mathbf A^n = 0 \iff ||\mathbf A|| < 1 \iff \rho(\mathbf A) < 1
定理:
- 若
|| \mathbf A|| < 1 则\mathbf I + \mathbf A 非奇异,且||(\mathbf I \pm \mathbf A)^{-1} || \le \frac{1}{1- || \mathbf A||}
迭代法
改写方程
则迭代矩阵为:
The speed of each step depends on
收敛性
迭代法收敛基本定理:
-
线性方程组
\mathbf A \mathbf x = \mathbf b ,迭代形式\mathbf x^{(k+1)} = \mathbf B \mathbf x^{k} + \mathbf g -
对 任意
\mathbf x^{(0)} 序列\{\mathbf x^{(k)}\} 收敛的 充要条件 为\rho (\mathbf B) < 1 -
证明:
-
\mathbf x^{(k)} - \mathbf x^* = \mathbf B (\mathbf x^{(k-1)}-\mathbf x ^*)= \cdots = \mathbf B^k (\mathbf x^{(0)}-\mathbf x^*) -
\lim_{k\to\infty}\mathbf B^{k} \to 0 \iff \rho(\mathbf B) < 1
-
-
或者从误差向量的角度来理解,矩阵
\mathbf B 对误差向量\mathbf e 压缩 -
注意
\rho (\mathbf B) \ge 1 时不能说对任意\mathbf x^{(0)} 都不收敛
误差估计:
-
设
\mathbf B = \mathbf S^{-1}\mathbf T ,若\mathbf B 的某一算子范数||\mathbf B|| <1 ,则对任意初始向量\mathbf x^{(0)} 均收敛到方程的解\mathbf x^* ,且有误差估计:|| \mathbf x^{(k)} - \mathbf x^{*}|| \le \frac{||\mathbf B||^k}{1-||\mathbf B||} ||\mathbf x^{(1)} - \mathbf x^{(0)}||\\ || \mathbf x^{(k)} - \mathbf x^{*}|| \le \frac{||\mathbf B||}{1-||\mathbf B||} ||\mathbf x^{(k)} - \mathbf x^{(k-1)}|| -
或估计残差
\mathbf r = \mathbf b - \mathbf A \mathbf x^{(k)}
对角占优矩阵
定义:
-
若矩阵
\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
对
-
- Jacobi 和 Gauss-Seidel 迭代均收敛