2018-04-01 開胃學(xué)習(xí)數(shù)學(xué)系列 - 隨機(jī)數(shù)生成

True and pseudo random numbers

True random number generators (T-RNG) observe random physical processes 真隨機(jī)數(shù)發(fā)生器(T-RNG)觀察隨機(jī)物理過程:

  • often involves quantum effects: radioactive decay, electrical/thermal noise etc. 通常涉及量子效應(yīng):放射性衰減,電/熱噪聲等
  • costly and slow 代價高昂,速度慢
  • mostly used in cryptography that requires a high level of security 主要用于需要高度安全性的密碼學(xué)

Pseudo random number generators (P-RNG) are computer software that
偽隨機(jī)數(shù)發(fā)生器(P-RNG)是計算機(jī)軟件:

  • produce number sequence that only appears to be random 產(chǎn)生看起來隨機(jī)的序列
  • cheap and fast 便宜又快捷
  • can be initialized (seeded) to different states 可以被初始化(播種)到不同的狀態(tài)
  • states can be stored and recovered, convenient for MC 狀態(tài)可以存儲和恢復(fù),方便MC

Pseudo random number generators 偽隨機(jī)數(shù)生成器

  • Building good P-RNG requires highly specialized skills:
  • must pass rigorous statistical tests 必須通過嚴(yán)格的統(tǒng)計測試
  • numerical scientists have devoted their careers to build good P-RNGs
  • always use a good P-RNG libarary and never write your own
    使用一個好的P-RNG libarary并且永遠(yuǎn)不要自己寫一個
  • random() in Excel is implemented incorrectly, don't use it for anything serious
    在Excel中的random執(zhí)行是不正確的,不要嚴(yán)重使用它

Mersenne Twister (MT19937)

The most popular P-RNG:

  • often the default P-RNG for MC :the default choice of Python's numpy.random.uniform
  • very long cycle of 2^ 19937 ? 1 and execellent statistical properties
  • suitable for MC applications, but not good for cryptography
  • very fast: ~100M random numbers per second on a modern PC

Non-uniform random numbers

Box-muller

Normal random number is the most important of all:

  • most quant Finance models are driven by Brownian motions
  • fast and accurate inversion of normal CDF weren't known till recently

Box-muller is a classic method to transform independent uniform RNs to independent normal RNs:

  • takes 2 independent uniforms and produce 2 independent normals
    把兩個獨立的
  • its polar form is faster and more stable, which is behind Python's numpy.random.normal
  • the polar form is a rejection algorithm: the number of output normal RNs is less than the input uniforms
    • about 21% of input uniforms are rejected (wasted)

Normal inversion

Numerical inversion of normal CDF is an effective alternative to genrate normal random numbers:

  • fast and accurate numerical inversion of the normal CDF were discovered recently
  • based on polynomial approximation, accuracy is ~$10^{-9}$
  • every uniform RN produce a normal RN output, more convenient than the polar Box-muller
  • works well with low discrepency sequences (next lecture)
    Normal inversion is often preferred over the Box-muller.

How to create correlated normal RNs from independent normals RNs?

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,424評論 0 10
  • 中秋有約,佳節(jié)快樂!我是健康天使,傳播健康是我的天職!
    馨方3017閱讀 194評論 0 0
  • 常言道40不惑50知天命,可就是這個年紀(jì),煩惱不少。 首先,上有4位老人,大病小病難免,一年要去幾趟醫(yī)院,提心吊膽...
    49遇見你閱讀 417評論 1 2
  • 精要主義者養(yǎng)成的第二步:排除 一、澄清 精要目標(biāo)既具體可行,又鼓舞人心;既充滿意義,又容易衡量。只要目標(biāo)真正明確,...
    馥郁清香閱讀 153評論 0 0
  • 有沒有過,為了一個人向往一座城。有沒有過,為了一個人遠(yuǎn)走一座城。有沒有過,沿著他來時的路,再走一條告別的路。 好好...
    伊恩希閱讀 369評論 5 7