一元和多元核密度快速稳健估计工具

fastkde的Python项目详细描述


软件概述

fastkde计算任意维数的核密度估计 数据;它使用最近开发的kde做得如此迅速和可靠 技术。它的统计技巧和 科学状态的“r”kde包,它能做到10000次 对于二元数据更快(对于更高的 维度)。

使用此方法时,请引用下列论文:

O’Brien, T. A., Kashinath, K., Cavanaugh, N. R., Collins, W. D. & O’Brien, J. P. A fast and objective multidimensional kernel density estimation method: fastKDE. Comput. Stat. Data Anal. 101, 148–160 (2016).

O’Brien, T. A., Collins, W. D., Rauscher, S. A. & Ringler, T. D. Reducing the computational cost of the ECF using a nuFFT: A fast and objective probability density estimation method. Comput. Stat. Data Anal. 79, 222–234 (2014).

示例用法:

对于标准pdf

#!python

import numpy as np
from fastkde import fastKDE
import pylab as PP

#Generate two random variables dataset (representing 100000 pairs of datapoints)
N = 2e5
var1 = 50*np.random.normal(size=N) + 0.1
var2 = 0.01*np.random.normal(size=N) - 300

#Do the self-consistent density estimate
myPDF,axes = fastKDE.pdf(var1,var2)

#Extract the axes from the axis list
v1,v2 = axes

#Plot contours of the PDF should be a set of concentric ellipsoids centered on
#(0.1, -300) Comparitively, the y axis range should be tiny and the x axis range
#should be large
PP.contour(v1,v2,myPDF)
PP.show()

对于条件pdf

下面的代码从一个非平凡的关节生成示例 分布

fromfastkdeimportfastKDEimportpylabasPPimportnumpyasnp#***************************# Generate random samples#***************************# Stochastically sample from the function underlyingFunction() (a sigmoid):# sample the absicissa values from a gamma distribution# relate the ordinate values to the sample absicissa values and add# noise from a normal distribution#Set the number of samplesnumSamples=int(1e6)#Define a sigmoid functiondefunderlyingFunction(x,x0=305,y0=200,yrange=4):return(yrange/2)*np.tanh(x-x0)+y0xp1,xp2,xmid=5,2,305#Set gamma distribution parametersyp1,yp2=0,12#Set normal distribution parameters (mean and std)#Generate random samples of X from the gamma distributionx=-(np.random.gamma(xp1,xp2,int(numSamples))-xp1*xp2)+xmid#Generate random samples of y from x and add normally distributed noisey=underlyingFunction(x)+np.random.normal(loc=yp1,scale=yp2,size=numSamples)

现在我们有了x,y样本,下面的代码计算 有条件的

#***************************# Calculate the conditional#***************************pOfYGivenX,axes=fastKDE.conditional(y,x)

下图显示结果:

#***************************# Plot the conditional#***************************fig,axs=PP.subplots(1,2,figsize=(10,5))#Plot a scatter plot of the incoming dataaxs[0].plot(x,y,'k.',alpha=0.1)axs[0].set_title('Original (x,y) data')#Set axis labelsforiin(0,1):axs[i].set_xlabel('x')axs[i].set_ylabel('y')#Draw a contour plot of the conditionalaxs[1].contourf(axes[0],axes[1],pOfYGivenX,64)#Overplot the original underlying relationshipaxs[1].plot(axes[0],underlyingFunction(axes[0]),linewidth=3,linestyle='--',alpha=0.5)axs[1].set_title('P(y|x)')#Set axis limits to be the samexlim=[np.amin(axes[0]),np.amax(axes[0])]ylim=[np.amin(axes[1]),np.amax(axes[1])]axs[1].set_xlim(xlim)axs[1].set_ylim(ylim)axs[0].set_xlim(xlim)axs[0].set_ylim(ylim)fig.tight_layout()PP.savefig('conditional_demo.png')PP.show()
Conditional PDF

有条件PDF

我该怎么做?

标准的python构建:python setup.py install

pip install fastkde

下载源代码

请联系travis a.o'brienTAOBrien@lbl.gov获取最新的 源的版本。

安装先决条件

此代码需要以下软件:

  • python>;=2.7.3
  • numpy>;=1.7
  • scipy
  • 赛顿

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

推荐PyPI第三方库


热门话题
ArrayList Java中的搜索字符串   另一个web应用程序的java访问会话   另一个应用程序中的活动和服务之间的java通信   java根据Json字符串类型将Json字符串转换为对象   eclipse如何解决java中的错误异常。lang.NoSuchMethodError:'java。字符串javax。摆动JOptionPane。showInputDialog(java.lang.String)'   线程“main”java中的安卓异常。lang.NoClassDefFoundError:org/codehaus/jackson/JsonParseException   java如何在安卓 emulator上显示Mat图像?使用NDK   Java在本地读取测试源文件,但在服务器上读取失败   java dowhile循环用于计算输入数字中的数字。故障排除代码   JAva初学者在编写获取成本的方法时遇到困难   java是shell游戏。我如何让物体移动,特别是在特定的曲线上,但顺序是随机的?   java如何区分两个同名的JButton   java为什么我在Spring Boot中需要一个接口?   java将文件路径插入数据库将删除\   使用InterfaceType初始化java对象   java如何部署一个分为Angular、Spring Boot和MySQL的项目?   java如何使用Symja解决不等式?