蒙特卡洛模型
蒙特卡洛
? ? ? ?蒙特卡洛(Monte Carlo)又稱統計模擬法、隨機抽樣技術,是一種隨機模擬方法,以概率和統計理論方法使用隨機數(或更常見的偽隨機數)來解決很多計算問題的方法。將所求解的問題同一定的概率模型相聯系,用電子計算機實現統計模圳成地樣以獲得問波的近似解。為象征性地表明這一方法的概率統計特征,故借用賭城蒙特卡羅命名。
? ? ? ?隨著二十世紀電子計算機的出現,蒙特卡洛法已經在諸多領域展現出了超強的能力, 主要出現在風險管理知識領域中的定量風險分析過程,是用于做項目定量風險分析的工具之一,同時蒙特卡洛模擬也可以用于估算進度或成本以及制定進度計劃等,在機器學習和自然語言處理技術中,常常被用到的MCMC也是由此發展而來。
# -*- coding: utf-8 -*- import numpy as np import pandas as pd import matplotlib.pyplot as plt from scipy import statsnp.random.seed(1) # 先畫出三個要素工期的正態分布概率密度圖 def normplot(mu,sigma,n,name,ax):x = np.linspace(mu-3*sigma,mu+3*sigma,n)y = stats.norm.pdf(x,mu,sigma)#繪圖需要用到latexax.plot(x, y,label=r'{}:$\mu={},\sigma={}$'.format(name,mu,sigma))# plt.show()# plt.savefig(name + '.png')fig,ax = plt.subplots(1,2,figsize=(15,5)) normplot(14, 2, 1000,'desgin',ax[0]) # normplot(23, 3, 1000,'build',ax[0]) # normplot(22, 4, 1000,'tests',ax[0]) ax[0].legend(prop={'family':'SimHei','size':10}) ax[0].set_xlabel('x') ax[0].set_ylabel('y')x = pd.Series(np.random.normal(loc=14,scale=2,size=10000)) # x2 = pd.Series(np.random.normal(loc=23,scale=3,size=10000)) # x3 = pd.Series(np.random.normal(loc=22,scale=4,size=10000)) # x = x1+x2+x3n,bins,paches = ax[1].hist(x,bins=50,range=(40,80),density=True) mean,std = x.mean(),x.std() y = stats.norm.pdf(bins,mean,std) ax[1].plot(bins,y, label ='ret$\mu={:.2f},\sigma={:.2f},\sigma^2={:.2f}$'.format(mean, std,std**2)) ax[1].legend(prop={'family':'SimHei','size':10}) ax[1].set_ylim(0,0.09)plt.show() plt.savefig('mtkl.png')參考
蒙特卡洛法 - coshaho - 博客園 (cnblogs.com)
蒙特卡羅方法 - MBA智庫百科 (mbalib.com)
蒙特卡洛模擬在實際的項目管理中的應用——Python_camerayuhangyuhang.的博客-CSDN博客_蒙特卡洛分析 項目管理
matplotlib.pyplot.plot()參數詳解?
python 可視化:fig, ax = plt.subplots()?
總結
- 上一篇: USGS下载遥感影像——以Landsat
- 下一篇: dqo变换_一种基于dqo变换改进的电流