单变量分布抽样
samplep的Python项目详细描述
samplepy为单变量分布实现三种采样方法。套餐包括:
- 重要性抽样:samplepy.importance
- 拒绝抽样:samplepy.rejection
- 大都会黑斯廷斯抽样:samplepy.mh
示例:
fromsamplepyimportRejectionimportmatplotlib.pyplotaspltimportnumpyasnp""" Rejection sampling example from 2 different functions """# define a unimodal function to sample underf=lambdax:2.0*np.exp(-2.0*x)rej=Rejection(f,[0.01,3.0])# instantiate Rejection sampling with f and intervalsample=rej.sample(10000,1)# create a sample of 10K pointsx=np.arange(0.01,3.0,(3.0-0.01)/10000)fx=f(x)figure,axis=plt.subplots()axis.hist(sample,normed=1,bins=40)axis2=axis.twinx()axis2.plot(x,fx,'g',label="f(x)=2.0*exp(-2*x)")plt.legend(loc=1)plt.show()
更多示例和包文档可在<;https://github.com/elena-sharova/samplepy/blob/master/README.rst>;
安装
pip install samplepy