跳转到主要内容

快速且稳健的单变量和多变量核密度估计工具

项目描述

软件概述

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

以下代码生成一个非平凡联合分布的样本

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

#***************************
# 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 samples
numSamples = int(1e6)

#Define a sigmoid function
def underlyingFunction(x,x0=305,y0=200,yrange=4):
     return (yrange/2)*np.tanh(x-x0) + y0

xp1,xp2,xmid = 5,2,305  #Set gamma distribution parameters
yp1,yp2 = 0,12          #Set normal distribution parameters (mean and std)

#Generate random samples of X from the gamma distribution
x = -(np.random.gamma(xp1,xp2,int(numSamples))-xp1*xp2) + xmid
#Generate random samples of y from x and add normally distributed noise
y = 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 data
axs[0].plot(x,y,'k.',alpha=0.1)
axs[0].set_title('Original (x,y) data')

#Set axis labels
for i in (0,1):
    axs[i].set_xlabel('x')
    axs[i].set_ylabel('y')

#Draw a contour plot of the conditional
axs[1].contourf(axes[0],axes[1],pOfYGivenX,64)
#Overplot the original underlying relationship
axs[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 same
xlim = [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’Brien TAOBrien@lbl.gov以获取源代码的最新版本。

安装先决条件

此代码需要以下软件

  • Python >= 2.7.3

  • Numpy >= 1.7

  • scipy

  • cython

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

psyneulink-fastkde-1.0.19.tar.gz (208.3 kB 查看哈希值)

上传时间 源代码

构建分发

psyneulink_fastkde-1.0.19-cp39-cp39-win_amd64.whl (217.0 kB 查看哈希值)

上传时间 CPython 3.9 Windows x86-64

psyneulink_fastkde-1.0.19-cp39-cp39-manylinux2010_x86_64.whl (1.0 MB 查看哈希值)

上传时间 CPython 3.9 manylinux: glibc 2.12+ x86-64

psyneulink_fastkde-1.0.19-cp39-cp39-manylinux2010_i686.whl (994.7 kB 查看哈希值)

上传时间 CPython 3.9 manylinux: glibc 2.12+ i686

psyneulink_fastkde-1.0.19-cp39-cp39-manylinux1_x86_64.whl (1.1 MB 查看哈希值)

上传时间 CPython 3.9

psyneulink_fastkde-1.0.19-cp39-cp39-manylinux1_i686.whl (1.0 MB 查看哈希值)

上传时间 CPython 3.9

psyneulink_fastkde-1.0.19-cp39-cp39-macosx_10_9_x86_64.whl (236.0 kB 查看哈希值)

上传时间 CPython 3.9 macOS 10.9+ x86-64

psyneulink_fastkde-1.0.19-cp39-cp39-macosx_10_9_universal2.whl (420.7 kB 查看哈希值)

上传时间 CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

psyneulink_fastkde-1.0.19-cp38-cp38-win_amd64.whl (218.7 kB 查看哈希值)

上传于 CPython 3.8 Windows x86-64

psyneulink_fastkde-1.0.19-cp38-cp38-manylinux2010_x86_64.whl (1.1 MB 查看哈希值)

上传于 CPython 3.8 manylinux: glibc 2.12+ x86-64

psyneulink_fastkde-1.0.19-cp38-cp38-manylinux2010_i686.whl (1.1 MB 查看哈希值)

上传于 CPython 3.8 manylinux: glibc 2.12+ i686

psyneulink_fastkde-1.0.19-cp38-cp38-macosx_10_9_x86_64.whl (230.2 kB 查看哈希值)

上传于 CPython 3.8 macOS 10.9+ x86-64

psyneulink_fastkde-1.0.19-cp37-cp37m-win_amd64.whl (212.9 kB 查看哈希值)

上传于 CPython 3.7m Windows x86-64

psyneulink_fastkde-1.0.19-cp37-cp37m-manylinux2010_x86_64.whl (952.8 kB 查看哈希值)

上传于 CPython 3.7m manylinux: glibc 2.12+ x86-64

psyneulink_fastkde-1.0.19-cp37-cp37m-manylinux2010_i686.whl (901.7 kB 查看哈希值)

上传于 CPython 3.7m manylinux: glibc 2.12+ i686

psyneulink_fastkde-1.0.19-cp37-cp37m-manylinux1_x86_64.whl (1.0 MB 查看哈希值)

上传时间: CPython 3.7m

psyneulink_fastkde-1.0.19-cp37-cp37m-manylinux1_i686.whl (972.5 kB 查看哈希值)

上传时间: CPython 3.7m

psyneulink_fastkde-1.0.19-cp37-cp37m-macosx_10_9_x86_64.whl (229.5 kB 查看哈希值)

上传时间: CPython 3.7m macOS 10.9+ x86-64

psyneulink_fastkde-1.0.19-cp36-cp36m-win_amd64.whl (212.5 kB 查看哈希值)

上传时间: CPython 3.6m Windows x86-64

psyneulink_fastkde-1.0.19-cp36-cp36m-manylinux2014_aarch64.whl (1.1 MB 查看哈希值)

上传时间: CPython 3.6m

psyneulink_fastkde-1.0.19-cp36-cp36m-manylinux2010_x86_64.whl (961.7 kB 查看哈希值)

上传时间: CPython 3.6m manylinux: glibc 2.12+ x86-64

psyneulink_fastkde-1.0.19-cp36-cp36m-manylinux2010_i686.whl (909.5 kB 查看哈希值)

上传时间: CPython 3.6m manylinux: glibc 2.12+ i686

psyneulink_fastkde-1.0.19-cp36-cp36m-manylinux1_x86_64.whl (1.0 MB 查看哈希值)

上传时间: CPython 3.6m

psyneulink_fastkde-1.0.19-cp36-cp36m-manylinux1_i686.whl (979.7 kB 查看哈希值)

上传时间: CPython 3.6m

psyneulink_fastkde-1.0.19-cp36-cp36m-macosx_10_9_x86_64.whl (228.1 kB 查看哈希值)

上传时间: CPython 3.6m macOS 10.9+ x86-64

psyneulink_fastkde-1.0.19-cp35-cp35m-win_amd64.whl (204.7 kB 查看哈希值)

上传时间: CPython 3.5m Windows x86-64

psyneulink_fastkde-1.0.19-cp35-cp35m-manylinux2010_x86_64.whl (921.4 kB 查看哈希值)

上传时间 CPython 3.5m manylinux: glibc 2.12+ x86-64

psyneulink_fastkde-1.0.19-cp35-cp35m-manylinux2010_i686.whl (868.9 kB 查看哈希值)

上传时间 CPython 3.5m manylinux: glibc 2.12+ i686

psyneulink_fastkde-1.0.19-cp35-cp35m-manylinux1_x86_64.whl (972.9 kB 查看哈希值)

上传时间 CPython 3.5m

psyneulink_fastkde-1.0.19-cp35-cp35m-manylinux1_i686.whl (930.5 kB 查看哈希值)

上传时间 CPython 3.5m

psyneulink_fastkde-1.0.19-cp35-cp35m-macosx_10_9_x86_64.whl (217.8 kB 查看哈希值)

上传时间 CPython 3.5m macOS 10.9+ x86-64

由以下机构支持