随机漫步模型及其实现

随机漫步(Random Walk)思想最早由 Karl Pearson 在1905年提出,它是一种不规则的变动形式,在变动过程当中的每一步都是随机的。通常来说,随机漫步被假定为具有马尔可夫链的性质,也即是每一个步骤具有“无记忆”的特性,换句话说,每一次变动都不会影响别的变动。除此之外,还有许多更加复杂的随机漫步。在维度方面,随机漫步处于和面上,或者维度更多的结构中,例如
                随机漫步模型及其实现               随机漫步模型及其实现

如果考虑到时间参数,一些随机漫步过程是标记为非连续时间,例如:
X_0,X_1,X_2,\dots
另一些随机漫步过程则采用随机时间,例如 Xt,并且作为连续时间段 t\ge 0;这样的例子包括drunkard's walk和 Lévy flight等等。
随机漫步过程通常与扩散模型和马尔可夫过程相联系,它的一些性质,例如 dispersal distributions, first-passage times 和 encounter rates,已经得到了非常深入的研究。

一维随机漫步
这是一个简单的随机漫步例子,它的特征是每次变化的“量”是一个整数,从零开始,每一步变化记作+1或者-1。下面的图采用一个例子,根据掷硬币来产生随机步骤,头像记作1,背面记作-1:
随机漫步模型及其实现
掷5次后的最终位置如上所示。
但是如果我们想比较正式地定义这个过程,我们可以首先认为不同的时间点(上例中为每次掷硬币)为一个整数线 \mathbb Z,然后我们确立一系列独立随机变量:
Z_1, Z_2,\dots
每一个变量均有50%的概率值为1或者-1,如上所述,我们可以得到:
S_0 = 0\,\!
S_n =\sum_{j=1}^nZ_j.
分别表示初始位置为0,以及中间某一位置为前面所有步骤变化量的总和。
于是,集合 \{S_n\}\,\!可以称为在 \mathbb Z上的简单随机漫步。该集合是所以1和-1的相加,并计算出漫步距离。 S_n\,\!的期望值 E(S_n)\,\!为0,也即是说,如果掷硬币的次数增加,每次掷硬币所得到的值的平均数会趋向于0,有限次数相加的期望值为:
E(S_n)=\sum_{j=1}^n E(Z_j)=0
考虑到 E(Z_n^2)=1,变换成另一个类似的计算公式则为:
E(S_n^2)=\sum_{j=1}^n E(Z_j^2)=n
这样显示了在n次漫步后,期望的转换距离为 E(|S_n|)\,\!,大约为 \sqrt n。事实上,我们能够知道:
\lim_{n\to\infty} \frac{E(|S_n|)}{\sqrt n}= \sqrt{\frac 2{\pi}}.
如果允许无数次随机漫步,整个过程设定的边界能够有多少次会被经过?在 \mathbb Z上的简单随机漫步能够在无限次数中经过所有的点,这样的过程有不同的名字 level-crossing phenomenon, recurrence或者 thegambler's ruin。如同最后一个名字意思显示:如果一个拥有有限金钱的赌徒与一家拥有无限金钱的银行进行公平地赌博,结果就是赌徒会输光所有的钱,因为赌博过程是一个随机漫步,而在某一点时赌徒的钱数会经过0,输光并结束赌博.

How many times will a random walk cross a boundary line if permitted to continue walking forever? A simple random walk on \mathbb Z will cross every point an infinite number of times. This result has many names: the level-crossing phenomenon, recurrence or the gambler's ruin. The reason for the last name is as follows: a gambler with a finite amount of money will eventually lose when playing a fair game against a bank with an infinite amount of money. The gambler's money will perform a random walk, and it will reach zero at some point, and the game will be over.

If a and b are positive integers, then the expected number of steps until a one-dimensional simple random walk starting at 0 first hits b or −a is ab. The probability that this walk will hit b before −a is a/(a+b), which can be derived from the fact that simple random walk is a martingale.

Some of the results mentioned above can be derived from properties of Pascal's triangle. The number of different walks of n steps where each step is +1 or −1 is clearly 2n. For the simple random walk, each of these walks are equally likely. In order for Sn to be equal to a number k it is necessary and sufficient that the number of +1 in the walk exceeds those of −1 by k. The number of walks which satisfy S_n=k is equally the number of ways of choosing (n + k)/2 elements from an n element set,[citation needed] denoted n \choose (n+k)/2. For this to be non-zero, it is necessary that n + k be an even number. Therefore, the probability that S_n=k is equal to 2^{-n}{n\choose (n+k)/2}. By representing entries of Pascal's triangle in terms of factorials and using Stirling's formula, one can obtain good estimates for these probabilities for large values of n.

If the space is confined to \mathbb Z+ for brevity, the number of ways in which a random walk will land on any given number having five flips can be shown as {0,5,0,4,0,1}.

This relation with Pascal's triangle is demonstrated for small values of n. At zero turns, the only possibility will be to remain at zero. However, at one turn, there is one chance of landing on −1 or one chance of landing on 1. At two turns, a marker at 1 could move to 2 or back to zero. A marker at −1, could move to −2 or back to zero. Therefore, there is one chance of landing on −2, two chances of landing on zero, and one chance of landing on 2.

k−5−4−3−2−1012345
P[S_0=k]     1     
2P[S_1=k]    1 1    
2^2P[S_2=k]   1 2 1   
2^3P[S_3=k]  1 3 3 1  
2^4P[S_4=k] 1 4 6 4 1 
2^5P[S_5=k]1 5 10 10 5 1

The central limit theorem and the law of the iterated logarithm describe important aspects of the behavior of simple random walk on \mathbb Z. In particular, the former entails that as n increases, the probabilities (proportional to the numbers in each row) approach a normal distribution.

如果a和b是正整数,我们可以进一步推导概率中的 鞅(Martingale)以及 杨辉三角形(Pascal's triangle)
一维的随机漫步也可以看作是马尔可夫链,其状态矢量空间(state space)为: i=0,\pm 1,\pm 2,\dots .,其中某些数 p 满足 \,0 < p < 1,转换概率(表示从state i到state j的概率)则为 \,P_{i,i+1}=p=1-P_{i,i-1}
高斯随机漫步
这个主要应用于现实的时间序列,例如金融市场等,条件是漫步的步长满足正态分布。
例如一个逆积累正态分布( inverse cumulative normal distribution)中, Φ− 1(z,μ,σ), 其中 0 z 1是分布一致的随机数, 并且 μ 和 σ分别是正态分布的平均数和标准差,在步长分布满足平均数为0以及有限方差的情况下,n步漫步后的 平方平均数(root mean square)为:
\sqrt{E|S_n^2|} = \sigma \sqrt{n}.

高维度的随机漫步和其它应用,可以看这里:

应用
计算机科学中,随机漫步可用于万维网尺度的预测;
图像分割中,可以用来确认每一个像素的标签(例如是目标还是背景),常用的分割算法包括 随机漫步者(Random Walker)等。
无线网络中,可以应用于模型节点运动的研究。
等等。

随机漫步的变体
主要包括Random Walks on graphs 和self-interacting Random Walks.


通过Perl语言对Random Walk的实现:
#####################################################
######The one-dimensional Random Walk###############
#####################################################
#! /usr/bin/perl

# Total times we want to run (value can be modified)
$Total_Times_We_Run = 1000;

# How many steps for each run (value can be modified)
$N = 1000;

# Initialize "Show times" to zero
for ($Position = -$N; $Position <= $N; $Position ++){
$show_times{$Position} = 0;
}

print "Hash size:", scalar keys %show_times, "\n";

# File handling
open (FINAL_POSITION, ">final_position_counts.csv");
open (FREQUENCY, ">frequency_count.csv");

for ($times = 1; $times <= $Total_Times_We_Run; $times ++){
# Intial position set to 0
$Px = 0;
# Define step counter
$S = 0;
# even or odd number of steps
# if (rand() < 0.5) {$N = 99;}
# else {$N = 100;}

# Single time, N steps of random walks
while ($S <= $N){
$R = rand();
if ($R < 0.4){$Px--;}
if ($R >= 0.4){$Px++;}
### print "Position = $Px \n";
$S++;
}
# Final position after the end of a single random walk process
print "Final Position ($times) = $Px \n";
# Print to file (final_position_counts.csv)
print FINAL_POSITION "$times".","."$Px\n";
# Count frequencies @ each position
$show_times{$Px}++;
}

# Print to file (frequency_counts.csv)
for ($Position = -$N; $Position <= $N; $Position ++){
print FREQUENCY "$Position".","."$show_times{$Position}\n";
}


  • 6
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值