Presentation is loading. Please wait.

Presentation is loading. Please wait.

Monte Carlo Simulation Part.2 Metropolis Algorithm Dept. Phys. Tunghai Univ. Numerical Methods C. T. Shih.

Similar presentations


Presentation on theme: "Monte Carlo Simulation Part.2 Metropolis Algorithm Dept. Phys. Tunghai Univ. Numerical Methods C. T. Shih."— Presentation transcript:

1 Monte Carlo Simulation Part.2 Metropolis Algorithm Dept. Phys. Tunghai Univ. Numerical Methods C. T. Shih

2 Simple/Importance Sampling 當我們用 MC 法計算積分時,若該函數為常數 函數 f(x)=constant ,則取樣數不管多少,準 確度皆為百分之百 相對的,如果 f(x) 為 delta 函數,則取樣數不 管多少,準確度幾乎皆為零 也就是說,如果在積分區間內, f(x) 為一平滑 函數,則 MC 法較準確,如果 f(x) 的變動很劇 烈,則 MC 法的誤差會變大

3

4 Weight Function: w(x) 因此,在 f(x) 變化劇烈時,在以 MC 取樣時, 最好依據 f(x) 的大小來決定取樣機率 亦即: |f(x)| 大的,對 ∫f(x)dx 的貢獻較大,如 果沒有被選中則結果的誤差極大 解決方式:改變 x 被選中的機率,讓 |f(x)| 大 的被選中的機率增加 Weight distribution function: w(x) ,決定每個 x 被選中的機率

5 Weight Function: w(x) w(x) 必須歸一化,即在積分區間內 ∫w(x)dx=1 由於 x 的選取已被 w(x) 扭曲,所以計算積分 時要把這個部分「還」回去:若一共取樣了 M 個 x ,則其積分值為

6 Metropolis 演算法 如何產生一連串的 x ,使得 x 的分佈滿足 w(x)? 步驟如 下: 由均勻亂數產生一任意 x , a<x<b 再產生另外一個亂數 x’ , a<x’<b 兩者的機率權重比為 P(x → x’) w(x’)/w(x) 若 P ≧ 1 ,則接受 x’ 為新的 x 值 若 P < 1 ,則產生一亂數 y ,若 y<P ,則接受 x’ 為新的 x ,否則下一個被選取的仍然是舊的 x 如此即可得到一連串的 x ,重複此步驟 M 次,將每次所 得到的 x 所對應的 f(x)/w(x) 求平均,即為所求之積分 近似值

7

8 f(x) 與 w(x) 最好的 w(x) 當然就是 |f(x)| 本身,但是因為 w(x) 必須滿足 ∫w(x)dx=1 ,所以得先對 w(x) 做積分 → 回到問題的原點 但是如果 f(x) 是物理上的 probability distribution function (如波茲曼函數),我們 經常要積分的是一些物理量的平均值: 這類問題即可以 Metropolis algorithm 來產生 根據 f(x) 所分佈的 M 個 x


Download ppt "Monte Carlo Simulation Part.2 Metropolis Algorithm Dept. Phys. Tunghai Univ. Numerical Methods C. T. Shih."

Similar presentations


Ads by Google