Tools for fast and robust univariate and multivariate kernel density estimation
Project description
fastKDE
Software Overview
fastKDE calculates a kernel density estimate of arbitrarily dimensioned data; it does so rapidly and robustly using recently developed KDE techniques. It does so with statistical skill that is as good as state-of-the-science 'R' KDE packages, and it does so 10,000 times faster for bivariate data (even better improvements for higher dimensionality).
Please cite the following papers when using this method:
- 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). http://dx.doi.org/10.1016/j.csda.2016.02.014
- 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). http://dx.doi.org/10.1016/j.csda.2014.06.002
Example usage:
For a standard PDF
import numpy as np
from fastkde import fastKDE
import matplotlib.pyplot as plt
#Generate two random variables dataset (representing 100000 pairs of datapoints)
N = int(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, values = fastKDE.pdf(var1,var2)
#Extract the axes from the pdf values list
v1,v2 = values
#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
plt.contour(v1,v2,myPDF)
plt.show()
For a conditional PDF
The following code generates samples from a non-trivial joint distribution
#***************************
# 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)
Now that we have the x,y samples, the following code calculates the conditional
#***************************
# Calculate the conditional
#***************************
pOfYGivenX, values = fastKDE.conditional(y,x)
The following plot shows the results:
#***************************
# Plot the conditional
#***************************
fig,axs = plt.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(values[0],values[1],pOfYGivenX,64)
#Overplot the original underlying relationship
axs[1].plot(values[0],underlyingFunction(values[0]),linewidth=3,linestyle='--',alpha=0.5)
axs[1].set_title('P(y|x)')
#Set axis limits to be the same (limit to the range of the data)
xlim = [x.min(),x.max()]
ylim = [y.min(),y.max()]
axs[1].set_xlim(xlim)
axs[1].set_ylim(ylim)
axs[0].set_xlim(xlim)
axs[0].set_ylim(ylim)
plt.savefig('conditional_demo.png')
plt.show()
Kernel Density Estimate for Specific Points
To see the KDE values at specified points (not necessarily those that were used to generate the KDE):
import numpy as np
from fastkde import fastKDE
train_x = 50*np.random.normal(size=100) + 0.1
train_y = 0.01*np.random.normal(size=100) - 300
test_x = 50*np.random.normal(size=100) + 0.1
test_y = 0.01*np.random.normal(size=100) - 300
test_points = list(zip(test_x, test_y))
test_point_pdf_values = fastKDE.pdf_at_points(train_x, train_y, list_of_points = test_points)
Note that this method can be significantly slower than calls to fastkde.pdf()
since it does not benefit from using a fast Fourier transform during the final stage in which the PDF estimate is transformed from spectral space into data space, whereas fastkde.pdf()
does.
How do I get set up?
python -m pip install fastkde
Copyright Information
See LICENSE.txt
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for fastkde-1.0.30-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e802f21f1b22d237a3a2a2d52ec738b0f44ebfa441e6445bbde9449f2d75f435 |
|
MD5 | 057ac3a1ea1401dae3676f9acafe23c1 |
|
BLAKE2b-256 | 0100107a8e26696c86915bf183762a96fe48aa123fb34803b3e21c57f9fd9b23 |
Hashes for fastkde-1.0.30-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 862b7014ea04b8ab9befa7bacdc57aa2501b7593ab3514cf1a5a8812fb5cae64 |
|
MD5 | 964e1d0f1efa0eeedab9c709cc98cb24 |
|
BLAKE2b-256 | a46ac83b1b8ea1c93ff63587f6681f01b750aa40a4f3cbf1e816d3e20cab3222 |
Hashes for fastkde-1.0.30-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | adbf5a906f3889d814fcbdbb53efc7cb138a0a41b78e0f8befdd2a43b9907ca0 |
|
MD5 | 9f1e88075e81a84ce1071ae3086138f0 |
|
BLAKE2b-256 | 5e5ddec74e65a40a4b4de2540020ea37878ec7e21547fe9fdcddb5e9418d4a92 |
Hashes for fastkde-1.0.30-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6f90c98d44442595fef7ea4c08a09e125a41791f3619cc2f0e0451aa9392896 |
|
MD5 | cda14ecb32ee8aacd3f6df491be7073f |
|
BLAKE2b-256 | a0ecb919321969871fbdebe31a47a33d12d5c479e54f827024e4157e30803b6b |
Hashes for fastkde-1.0.30-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d07bee467308cd97f323bc4414bb5bb6d3168a8435d8e009c515ba489f29a837 |
|
MD5 | 52b7b4a6937deba888a7b01a10c07e92 |
|
BLAKE2b-256 | 72205cb85224d7faa5410b4a18a217bc12870530df946692df4c692f753e04f0 |
Hashes for fastkde-1.0.30-cp312-cp312-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24022b7f8866cc3b0ff6bac39200c1033ceae0b5af26bba9d916c446992c3589 |
|
MD5 | 632a86545389c1a474295d20ae5483aa |
|
BLAKE2b-256 | 2299ec423a2980c869bb5efa245de3cc6855977130fb3f0e4f5b31880eeede94 |
Hashes for fastkde-1.0.30-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd58a5638dc74bc010a1a232aae8aa2cf973af37aeea8be6b92b0e7bac9a6441 |
|
MD5 | 63c86c1bd58e9eebee87744cf15a0e39 |
|
BLAKE2b-256 | c8a22f95e28a4ef5a38249a2da09915503b6594972c41874167ebfb14e1415dd |
Hashes for fastkde-1.0.30-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 886b8cbea64d64f0a7df933483a73d325b308d46d5cb6d0c727abcbadeb5633d |
|
MD5 | 85b63748e12fbdeedb2d6ea8f77e4c16 |
|
BLAKE2b-256 | 4bd951c21d8868dbeae20ef4c97c889cfa13d2e50b578472f9c5eea411562e31 |
Hashes for fastkde-1.0.30-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d54acd6cea422239fe7a8d6b48ab1d74f39839f269d4df1da45508942a73f89 |
|
MD5 | d9db979b1c50e901b9330347a5cc9381 |
|
BLAKE2b-256 | cfd7d929a99e4a6bcee87eea27634e16de6d88be3004cba6fc7d3fbce7b289a5 |
Hashes for fastkde-1.0.30-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c62d7d5a392a9020c327dcf046f5be8821aa98f4caee7aecd8f1be9f854d015 |
|
MD5 | d31574c938869e2a663ace2836cd4c2b |
|
BLAKE2b-256 | d2ed700afcd79fb54cc11e18bf8006e8c6f79aa12ed47f5ec62b85b2a645a34b |
Hashes for fastkde-1.0.30-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46fdb819459b8691784b3b15944f17de8f7396fc55aabeb2e9b59238bf230cf8 |
|
MD5 | 1234e328497780bdc1fb648e7fce5cb4 |
|
BLAKE2b-256 | 0c22ca52b3210dc286ccdd302e8231237d26289f1b289d6aec9d01ac2f680d20 |
Hashes for fastkde-1.0.30-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b431f08229691ee9edb9efa402c66adebfff2d0886e53d94d9f4e7193db1381a |
|
MD5 | c7ce12a278c77db10d5ea3da1845dce5 |
|
BLAKE2b-256 | 7b529de14ed8defb3fca2d5ee98a33118777e0ee22731d060ed3d41a79ec01bf |
Hashes for fastkde-1.0.30-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e65cb55ac79ca4238158d52c3e124609773987551dea3aa5e552374dfdb44424 |
|
MD5 | 4b35c43832387e6866d321fde7e3eaf7 |
|
BLAKE2b-256 | 1cc9630d0260d80381a2e37873bf74ec2ec368cf23fa213d4375deec7c6c7b52 |
Hashes for fastkde-1.0.30-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3346093432ba751b31dbca062991e3375b8739a10b014615869b57db1f9a0a5b |
|
MD5 | b05b5cd7bda2a61cafabace1b064fc86 |
|
BLAKE2b-256 | 59e62cd2314296f642810f54c67a4b297aaee17d623b1e51eb50c7f5b1948e9d |
Hashes for fastkde-1.0.30-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac9c3857bc9c6821d30cac997dfa8e9e8429bfe48b2f3bfc88dbc74888dd54b7 |
|
MD5 | 8feb80dd13994c6ad7a4a578387186f2 |
|
BLAKE2b-256 | 346363eee93bdb6d32de2a7807eb73b2b254115ef6de6c8709c23d7b194e182d |
Hashes for fastkde-1.0.30-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2398636ab1cb3732878c28e620d167dfab7eee2613cb46517ecaec9d300f0dd |
|
MD5 | 1508d0779f86a3df2cd3f862f5ecd9b8 |
|
BLAKE2b-256 | ac225166d2aed9a3276969be68b1d70fe2a82674d2164698af58d03b9732a9b0 |
Hashes for fastkde-1.0.30-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bb7ee19a444f5e8a401f0163ad88d640ea63cc9e8a0244f255ca3b6b50b328a |
|
MD5 | 95897ebb86d4a50760cbe5a774baa79c |
|
BLAKE2b-256 | df68451a4b046d047bbeb4a43645756da12b70238da5b1b24a3d0e6d6e75cefb |
Hashes for fastkde-1.0.30-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa247ef1cc168f3db0bc9dbbbee1e06576aa00bda1bad9f93ec1253ae1ec5a3f |
|
MD5 | d122f229b07b529e4f22cabe58b4a81d |
|
BLAKE2b-256 | e0d4f8a0a1ad394a87a5b0e492352219583db22bf842c7bf7ae40e9871c9d057 |
Hashes for fastkde-1.0.30-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dae56afe64fed210b32f8ed223fd7207ca15458ad9040235228904b3754622c4 |
|
MD5 | 202fefc2417fea0c2b4dee6d2c9d0902 |
|
BLAKE2b-256 | 7f498e647c035776f096cf20f80eb889d10a60ab21793f8d451f76fef783b5bf |
Hashes for fastkde-1.0.30-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1990344969e4cec19b909255cef7f69ba561f8e0e114f34b7f5b165cd7b2250 |
|
MD5 | 4b006d0ba1a0c21567736b84857a7de3 |
|
BLAKE2b-256 | 75c81f770f4022c49c178e5b2895e2cddc235507fc8d1996069768988d89dd14 |
Hashes for fastkde-1.0.30-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 750d343ceb037f1f28320a3f6f41995960200e20759589b6ed07c58b68ca8b85 |
|
MD5 | 8bf50039ef0eb65d11044be1748d97db |
|
BLAKE2b-256 | c6e4de9ace672e6ad6dcf82bf49cc7e30ad0e0cb35744a50d61022827687c5ad |
Hashes for fastkde-1.0.30-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d650334c73edc11862ce3cc35aefd4314af39a48ba50725f7545dbbfaf4751e |
|
MD5 | 107376c9f9c08d10978c8885067e4196 |
|
BLAKE2b-256 | cb532777920d6593692477f8cce7962db0e22d42df80e15a77348f6bcd3864da |
Hashes for fastkde-1.0.30-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9380e1f2fb93baba5221f60b9e7dd81ce3ac87d245563e5d9f457f9029245a66 |
|
MD5 | 3b85b6736b50b54895b79367ba827f3e |
|
BLAKE2b-256 | c3344d94ee2a86a6b587c5f4abade88d9b7ffb803d3a924325259c98906c319b |
Hashes for fastkde-1.0.30-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de6954a9d48ed67d2e4b92f3d82d3aee9fe091e83c171e7023ccc5ed01d02db5 |
|
MD5 | 37c04063ee07319e637583f27f3a08d1 |
|
BLAKE2b-256 | d50d6ab76dc738a752960ceacb6e1c257379fe2d04b4e00686c7e07a0a625e3f |
Hashes for fastkde-1.0.30-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bf91099430007fe24e3debfe4b13df7bfab775a2dc9107d884384bc82130bae |
|
MD5 | 4e144bc11d21b35e0d5cb3779b3b757d |
|
BLAKE2b-256 | 591b9fae0c3791a8cac3d37fd2f1c016420641acd5ca297916a1d4119a9f0d81 |
Hashes for fastkde-1.0.30-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3377b1bbb64cdb51074b82506f2fb8980f9980ed48548f571ecce10d8e9a960 |
|
MD5 | d9d0feabde0a1a97473da2b39646e48d |
|
BLAKE2b-256 | 6a48c6d9f793ab62353187bbf172365d592f7104ed914559d4f30ee0f5078318 |
Hashes for fastkde-1.0.30-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a0dc9288eec7277432686ac1f5361cbf67264a3a599bfc66d9bd04debae36f1 |
|
MD5 | ee3c81e9edb29c34259539006215ed11 |
|
BLAKE2b-256 | 1d7061e00f2dc02306a3995a9efa0dc5bb9fd2dda0b856eddc6809da78d93b09 |
Hashes for fastkde-1.0.30-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68a3089d4b2f858e2e84df92a385ac4426cd646be0e820d6a10c551600b16116 |
|
MD5 | 3ff31d17deee65cb93a59a4abc7243af |
|
BLAKE2b-256 | df23b9c3ed345606b78c0a9c1af564672e8f57cb9bcf5bf0ce11f7ee56f35a9d |
Hashes for fastkde-1.0.30-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3804b794590289ddca259887fb58d14998120c0d778aed8f686851c1e67333d4 |
|
MD5 | 2774bb35d24729d7b5c257bb86bf9001 |
|
BLAKE2b-256 | bb6e6f140aabdf952abb44f2673cc14fcfa71f5b484804437e961890f5e12ae3 |
Hashes for fastkde-1.0.30-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df6d1da3f664bf32fe94ac2324dcf0dee74f495136bb8489634656962bf05430 |
|
MD5 | adae7322a9669b6d0c2d5a3a12133686 |
|
BLAKE2b-256 | 64a3bc9b5de24618fd62220b17bcf8ff4c16157fbd38a2be1aa6623c6e1ac230 |
Hashes for fastkde-1.0.30-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ea0211ad8506b4124f55436c8a24be0d62c27a4d97cb857ab1726fc9b72cbf1 |
|
MD5 | 96a142a6162397e01b41b236a01b5565 |
|
BLAKE2b-256 | 98590a2cd3eb6b51247e904d6c3669f28194da570f7fc34a8965d93982a93a0a |
Hashes for fastkde-1.0.30-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c70d10b52dde5ee3ab51260cf4c574061390ba392390793d0d6926807ca98e5 |
|
MD5 | c2cd80644e2c285ca897e17c53839606 |
|
BLAKE2b-256 | f6fa17387c295bd8fd1b8ff93d1ed5fcbacc562bbbb75cddef3d34481699dee5 |
Hashes for fastkde-1.0.30-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7712349e3c1dba2c715c9092d94f32bfcf6ab41dbc062454a385928235b9c17c |
|
MD5 | 959c53c5a545ef7ecb45ea4f6fd98697 |
|
BLAKE2b-256 | 3c99217f4781305ad9111763569aeb400eac366d44e016e4fb43fbb4cc4c7e85 |
Hashes for fastkde-1.0.30-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bf631aabd11b24cd63b91b140214777b93e74e94736a15e1fe66eaafc294c17 |
|
MD5 | c62dfc93611a8d26eb9b59129c2c2e3b |
|
BLAKE2b-256 | 04a7da7d6fadbb3434e08958aa2baebeb5de7a48b10bfe324e50c31189bf415a |
Hashes for fastkde-1.0.30-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3319f8ca2ea9bbb717a0ed725437cae218364e0b611d8ab7b0efc5d8df8b46d |
|
MD5 | 1bc4772545c366c2e8c39ade01ebaf79 |
|
BLAKE2b-256 | 4c3cab5746ec9c31240cd179e50044c6b3bc8b94d0c5fed60ca0ef7e6b2efaf7 |