fgivenx:功能性后位绘图仪

fgivenx的Python项目详细描述


fgivenx:Functional Posterior Plotter
Author:Will Handley
Version:2.2.0
Homepage:https://github.com/williamjameshandley/fgivenx
Documentation:http://fgivenx.readthedocs.io/
Build StatusTest Coverage StatusPyPi locationDocumentation StatusReview StatusPermanent DOI

说明

fgivenx是一个用于绘制函数后验的python包。它是 目前在天文学中使用,但对任何从事 具有作为函数的预测后验的贝叶斯分析。

这个软件包可以绘制一个函数的预测后验图, 取决于采样参数。我们假设一个人有贝叶斯后验 Post(theta|D,M)由一组后验样本{theta_i}~Post描述。 如果有一个由thetay=f(x;theta)参数化的函数,那么这个脚本 将在 (x,y)平面。

驱动程序是fgivenx.plot_contoursfgivenx.plot_linesfgivenx.plot_dkl。代码与getdist兼容,并具有加载功能 由fgivenx.samples_from_getdist_chains提供。

image0

开始

用户可以使用pip进行安装:

pip install fgivenx

来源:

git clone https://github.com/williamjameshandley/fgivenx
cd fgivenx
python setup.py install --user

或者对那些在Arch linux上的人来说 在上提供 AUR

您可以通过运行测试套件来检查工作是否正常(您可以 如果未安装可选依赖项joblib,则会遇到警告:

pip install pytest pytest-runner pytest-mpl
exportMPLBACKEND=Agg
pytest <fgivenx-install-location>

# or, equivalently
git clone https://github.com/williamjameshandley/fgivenx
cd fgivenx
python setup.py test

检查是否安装了下一节中列出的依赖项。然后你可以使用 fgivenx来自脚本的模块。

如果未安装Pillow,OSX或Anaconda的某些用户可能会发现QueueManagerThread错误(运行pip install pillow)。

如果要使用并行化,请使用进度条或getdist兼容性 您应该安装附加的可选依赖项:

pip install joblib tqdm getdist
# or, equivalently
pip install -r  requirements.txt

如果没有可选依赖项^{tt11},则可能会遇到警告$ 安装。

依赖关系

基本要求:

文档:

测试:

可选附加功能:

文档

完整文档位于 ReadTheDocs。 要构建您自己的本地文档副本,您需要安装 sphinx。然后您可以运行:

cd docs
make html

引文

如果使用fgivenx为发布生成绘图,请引用 作为:

Handley, (2018). fgivenx: A Python package for functional posterior
plotting . Journal of Open Source Software, 3(28), 849,
https://doi.org/10.21105/joss.00849

或者使用bibtex:

@article{fgivenx,doi={10.21105/joss.00849},url={http://dx.doi.org/10.21105/joss.00849},year={2018},month={Aug},publisher={The Open Journal},volume={3},number={28},author={Will Handley},title={fgivenx: Functional Posterior Plotter},journal={The Journal of Open Source Software}}

示例用法

绘制用户生成的样本

importnumpyimportmatplotlib.pyplotaspltfromfgivenximportplot_contours,plot_lines,plot_dkl# Model definitions# =================# Define a simple straight line function, parameters theta=(m,c)deff(x,theta):m,c=thetareturnm*x+cnumpy.random.seed(1)# Posterior samplesnsamples=1000ms=numpy.random.normal(loc=-5,scale=1,size=nsamples)cs=numpy.random.normal(loc=2,scale=1,size=nsamples)samples=numpy.array([(m,c)form,cinzip(ms,cs)]).copy()# Prior samplesms=numpy.random.normal(loc=0,scale=5,size=nsamples)cs=numpy.random.normal(loc=0,scale=5,size=nsamples)prior_samples=numpy.array([(m,c)form,cinzip(ms,cs)]).copy()# Set the x range to plot onxmin,xmax=-2,2nx=100x=numpy.linspace(xmin,xmax,nx)# Set the cachecache='cache/test'prior_cache=cache+'_prior'# Plotting# ========fig,axes=plt.subplots(2,2)# Sample plot# -----------ax_samples=axes[0,0]ax_samples.set_ylabel(r'$c$')ax_samples.set_xlabel(r'$m$')ax_samples.plot(prior_samples.T[0],prior_samples.T[1],'b.')ax_samples.plot(samples.T[0],samples.T[1],'r.')# Line plot# ---------ax_lines=axes[0,1]ax_lines.set_ylabel(r'$y = m x + c$')ax_lines.set_xlabel(r'$x$')plot_lines(f,x,prior_samples,ax_lines,color='b',cache=prior_cache)plot_lines(f,x,samples,ax_lines,color='r',cache=cache)# Predictive posterior plot# -------------------------ax_fgivenx=axes[1,1]ax_fgivenx.set_ylabel(r'$P(y|x)$')ax_fgivenx.set_xlabel(r'$x$')cbar=plot_contours(f,x,prior_samples,ax_fgivenx,colors=plt.cm.Blues_r,lines=False,cache=prior_cache)cbar=plot_contours(f,x,samples,ax_fgivenx,cache=cache)# DKL plot# --------ax_dkl=axes[1,0]ax_dkl.set_ylabel(r'$D_\mathrm{KL}$')ax_dkl.set_xlabel(r'$x$')ax_dkl.set_ylim(bottom=0,top=2.0)plot_dkl(f,x,samples,prior_samples,ax_dkl,cache=cache,prior_cache=prior_cache)ax_lines.get_shared_x_axes().join(ax_lines,ax_fgivenx,ax_samples)fig.tight_layout()fig.savefig('plot.png')

image0

绘制getdist链

importnumpyimportmatplotlib.pyplotaspltfromfgivenximportplot_contours,samples_from_getdist_chainsfile_root='./plik_HM_TT_lowl/base_plikHM_TT_lowl'samples,weights=samples_from_getdist_chains(['logA','ns'],file_root)defPPS(k,theta):logA,ns=thetareturnlogA+(ns-1)*numpy.log(k)k=numpy.logspace(-4,1,100)cbar=plot_contours(PPS,k,samples,weights=weights)cbar=plt.colorbar(cbar,ticks=[0,1,2,3])cbar.set_ticklabels(['',r'$1\sigma$',r'$2\sigma$',r'$3\sigma$'])plt.xscale('log')plt.ylim(2,4)plt.ylabel(r'$\ln\left(10^{10}\mathcal{P}_\mathcal{R}\right)$')plt.xlabel(r'$k / {\rm Mpc}^{-1}$')plt.tight_layout()plt.savefig('planck.png')

image1

贡献

想为fgivenx捐款吗?令人惊叹的! 您可以通过 [github存储库](https://github.com/williamjameshandley/fgivenx), 见下文。

开场白

打开问题以报告错误或建议新功能。

提出拉取请求

拉式请求非常受欢迎。注意,如果你打算提出激烈的 更改,请确保先打开一个问题进行讨论,以确保 公关将被接受之前,你花精力编码它。

更改日志

v2.2.0:Paper accepted
v2.1.17:100% coverage
v2.1.16:Tests fixes
v2.1.15:Additional plot tests
v2.1.13:Further bug fix in test suite for image comparison
v2.1.12:Bug fix in test suite for image comparison
v2.1.11:Documentation upgrades
v2.1.10:Added changelog

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在IntelliJ社区版中为maven项目创建war文件?   架构在java编程中创建模型数据的最佳方式   java代码可以打印当前数字右边的最大数字,最后一个数字应该打印1   java上一个和下一个按钮,用于在WebView中从数组中加载字符串   java与直接DB调用/RESTful服务调用相比,测试Hazelcast数据检索速度的最佳方法是什么?   资源/类链接上的Java404   java如何安装play2War插件(Play Framework 2.1.1.)   多线程守护进程线程行为java   java如何从RepainManager生成异常   java Hibernate集合映射问题。无法删除或更新父行:外键约束失败   java LibGDX TextureRegion NullPointerException   java无法在JUnit套件中添加测试类   java通配符捕获/泛型   awt如何在Java中获取当前的鼠标指针类型?   java将probuf转换为POJO   java bouncycastle是否支持RSA PKCS1OAEP填充?   SQLiteDatabase的java问题。SQLITE数据库时的查询()。rawQuery()工作正常   java Android。如何正确存储数据库的数据?   java如何访问与GAE默认服务帐户关联的电子邮件地址?