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
""" Demonstrate the first README example. """
import numpy as np
import fastkde
import matplotlib.pyplot as plt
#Generate two random variables dataset (representing 100,000 pairs of datapoints)
N = int(1e5)
x = 50*np.random.normal(size=N) + 0.1
y = 0.01*np.random.normal(size=N) - 300
#Do the self-consistent density estimate
PDF = fastkde.pdf(x, y, var_names = ['x', 'y'])
PDF.plot();
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
#***************************
cPDF = fastkde.conditional(y, x, var_names = ['y', 'x'])
The following plot shows the results:
#***************************
# Plot the conditional
#***************************
fig,axs = plt.subplots(1,2,figsize=(10,5), sharex=True, sharey=True)
#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')
axs[0].set_xlabel('x')
axs[0].set_ylabel('y')
#Draw a contour plot of the conditional
cPDF.plot(ax = axs[1], add_colorbar = False)
#Overplot the original underlying relationship
axs[1].plot(cPDF.x,underlyingFunction(cPDF.x),linewidth=3,linestyle='--',alpha=0.5)
axs[1].set_title('P(y|x)')
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):
""" Demonstrate using the pdf_at_points function. """""
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-2.0.1-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5be3410f7d805ec3079bb980354647aec7ade67a34c3e2077adac19169b8b4be |
|
MD5 | 4fe711e749678aaf4a006315adccc07d |
|
BLAKE2b-256 | 991fa390fa581510cec26f204607226195521f49b81ab0cef663ceae87e6c586 |
Hashes for fastkde-2.0.1-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2a8e8e408f660dfd97b7e49a004ba4a1422090f0449cbaf1338f9bcc492aa3c |
|
MD5 | c637dcc86a924b3a7676b573fb7215d1 |
|
BLAKE2b-256 | f051dc261d10543f7cfb1e5ca5c9481850d5db3c94cab7cd9a978d35d2a0abbb |
Hashes for fastkde-2.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee2b28f7409b2dcd3ae561ba3203788885a7db22e2b0ed4fd4da911e90de4b3f |
|
MD5 | b475a4dc046679ffaa50a36147e4e003 |
|
BLAKE2b-256 | 367eeb7a95dc2379939474a1f9302f90c8cad432af1c700fc22d20aff8e0e36e |
Hashes for fastkde-2.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31d702f0ad5885fb3564c9ccacc72dcc328bcbfb28bbc235f8812d193558925f |
|
MD5 | 03543c75addd5ee9c453f2dd0d34f515 |
|
BLAKE2b-256 | a85eb6a4be2a2400616d79d90194f7979c9cba1e48042227b55d8f863727908c |
Hashes for fastkde-2.0.1-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c76b14e6bf0c5d66523e0a89278c67d0ffa37d06483f02df4ed3e3cff76d1428 |
|
MD5 | 48637e416e33d260b171a95dcfcbfa8d |
|
BLAKE2b-256 | f67d9ad7d93c1b25e37719a90e85ff238e5affb243ecdae5b30eb435eca69c17 |
Hashes for fastkde-2.0.1-cp312-cp312-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a718144f165306dcb8549da9ca198f39e3a303994a8dfd6e8e3c6ec08d3b127d |
|
MD5 | c6fc956e247fc280ea1e77edacc5134e |
|
BLAKE2b-256 | 2bf0882d88d46a1e6a2c8ac126058f601df66992c3cf202a4f534f6db0c6aa93 |
Hashes for fastkde-2.0.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04911189a486aec4052b8336b4efd9375cbef445fd5cad23ba4962a7289cc5c8 |
|
MD5 | 6ccceec84eb8f9f51d6cbc808f66f69c |
|
BLAKE2b-256 | 683d9041eb6328164e580bc777f312c595f74eb3b102382c56e9f6767b4b84d0 |
Hashes for fastkde-2.0.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04ce8dba87f5413b9cfaecd98f103dc5ce75405dbd3eb870083701158ac98a40 |
|
MD5 | 67ed4ad9ca51638a1f94ba0b0a5c14be |
|
BLAKE2b-256 | 909053cd9330cae84b1262ca8a0fe4664fc468d9e3d1bd7cb1f0f8901b3379bb |
Hashes for fastkde-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f523bf2ff5ab1e25730491383d1b56ca766ba8dbe221b3568c953dedf90f39ec |
|
MD5 | ed2e022522f668224706b30265205596 |
|
BLAKE2b-256 | 2f1a7a24ba7c50f88ecdc5086a5ccbec65b51bfa9081ec8ee06495b175b74ab2 |
Hashes for fastkde-2.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae0cbe2c1d3b155877d5a971d2935c36e6535ea4540ba0df2051cd19122fc676 |
|
MD5 | 56582b602b65ccc3ad2272a98651fd83 |
|
BLAKE2b-256 | 1331b05e2ab5cf9f51261ed71eeb747321d61cbfe07917683b3afaa934d7b6f6 |
Hashes for fastkde-2.0.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55a5cedb0854d5f0ce64554d5d33edaa6ab34e7254cfc02f33c31bfbf75c54a6 |
|
MD5 | 77c679d62c5c052cf6d23a63f6eef461 |
|
BLAKE2b-256 | ae4ee69355382f6c0a57341a01d5314f026cef3d07816c8da0c946a9e8e95cb7 |
Hashes for fastkde-2.0.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9dfb848ff529c21bff47235d9eb234a986125218384645693903da73af5c3a8 |
|
MD5 | 885461735de2b6c2b8ceb1431373d48f |
|
BLAKE2b-256 | 362816df4f06a9d29085d26c1bc90ef90ad8221d9f7827b176ac6725297d801e |
Hashes for fastkde-2.0.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 715e76b26112e64c4466d507f4515e40eec15403e3bd11d3bccee26e9b94045f |
|
MD5 | c3b2d16d562167322404c3db7f8c548d |
|
BLAKE2b-256 | 25a4be609d45c9b0acfba9d626632044c9ae070501f22020b3042dbf0b422f47 |
Hashes for fastkde-2.0.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41a8f9b08ddeec981a7b684f0518a50f5576fbf5fb7b55bcc88013d403183a90 |
|
MD5 | 8a692c98dab56b44f182863bb3627187 |
|
BLAKE2b-256 | 918072008fed08bc2a257a2e575e4c25f27af5d6f100dbb632155e597f0f0ac0 |
Hashes for fastkde-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a099a54f4baa559765929b75484b420abd214e81266472a901392b5291d87413 |
|
MD5 | 0c559b54ae4c08058e9585c8e8f3a9bf |
|
BLAKE2b-256 | 873e94c06c9a52100bc0dbc245de0b379500035ec7a8748333f88fa38aa74c53 |
Hashes for fastkde-2.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 372b18cd0924fa60f5dd7fbdcb2772b9e5e0ab7ef7fa71a3f6b48c3cdfeba70d |
|
MD5 | 0ab567f678e74a7918a478cd4cd2082a |
|
BLAKE2b-256 | 3f368a35f59ae530ba7d30fe937ea9aab097ed4a11a0a8175e58a8a89008f8ea |
Hashes for fastkde-2.0.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbf16da0ee2dcc534f5834579aa4d12cd25c88cd087ada4f0728125fab147355 |
|
MD5 | d26b7115d095e0409035b3e8918f73bb |
|
BLAKE2b-256 | 70d208d68a7255f300a55bf6627fbb5f343b6fed134c06caa7ff869be8edfddc |
Hashes for fastkde-2.0.1-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ded55bb0d1279711f54b389b2218fea7b9029e13afb8ccc33e24d147199947c |
|
MD5 | 9e39f30651535b8d8bff35b1539ecada |
|
BLAKE2b-256 | f83048796bd1cf22661b7224ff0654982561329951b747e8462cf7e56b6f82a2 |
Hashes for fastkde-2.0.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5436e31754bd5999c1b5262ff0adaa96f701f7003bf14f846f7241128229f7ce |
|
MD5 | 3955f85dbd7a83e6a068a61999794ef5 |
|
BLAKE2b-256 | 7ccb3cabf72cee2375e1df2d7e644872aa4dbaa4e3ec181c6e178816fa0c47ea |
Hashes for fastkde-2.0.1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b18195c368a586419bbe34993af63dbb7de4483cdeceb1dbeffe9654269ef253 |
|
MD5 | de43229ee0b1bf691ec1765a07cd06aa |
|
BLAKE2b-256 | 6bdd967fd2f3e34591a710bfd215efdb9751fd86d412b2eb258ec6822f1af859 |
Hashes for fastkde-2.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 855cc9d224bd5b724cffcb2e632d59f18019e9ff2abc1c3b64d2975a5caf44e7 |
|
MD5 | 4af7420efad04f16b675bcec6706618a |
|
BLAKE2b-256 | e993711018c35e432d9153d6c09f3465d7e2b02832f80577e9b6717fca89b118 |
Hashes for fastkde-2.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6834b621ea4c0c9e9fdf4c06affbbd7c52638f640315e116c5cdf8f00a0c589 |
|
MD5 | 1ec1e7add9c461c118e17ccb0acfd65c |
|
BLAKE2b-256 | 86df21b5d78f5b105d5106f03f0bc4943d634ad11486ab9939057a0bd3cc3f3c |
Hashes for fastkde-2.0.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7075576f31b844fb5654e1314982a53a309b9e62312eb52a3a35f8691236830a |
|
MD5 | 0489ef79ab77909f5456edecb8554175 |
|
BLAKE2b-256 | ade8016d81fb64bae36e1c535adcf89d833093a5fe4d0a527e9d0bb51b3e8dc8 |
Hashes for fastkde-2.0.1-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15c5b475c9d6cae56bd51756980af55007d4b359f9441536f32ac7f1b68cd78b |
|
MD5 | 0a74f945087379f9ba7e5257713e3df9 |
|
BLAKE2b-256 | 2faffd54a1df2da83457493bdf9922111fb4edc28b9be888cdd1bed12251bcf3 |
Hashes for fastkde-2.0.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 286ab5017331a00079307223146e72770c088803c1486fcb3ebace1acb757209 |
|
MD5 | da6058cba63cbf47a5f98650ea17fafd |
|
BLAKE2b-256 | 568c7f53f13b86bcb81408f58541195eea94a48f21c2d2478d03ba09b193bcc6 |
Hashes for fastkde-2.0.1-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9fda39923db1a4c335396a09e59997cb383e8527d47ff7479d508b5699aed85 |
|
MD5 | 21c222e1562672d705b719543bbab71d |
|
BLAKE2b-256 | d9388a59ea6a556b04d9aa198101c61e0ddedb9e85ff8758f8565f3cff5a92f5 |
Hashes for fastkde-2.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a05594a46d4acdbc6dfab2e44c2d287ccfaa09f80dfb9a8d81b9df3235890ae7 |
|
MD5 | d66613f2ce8fb351d9fcfbbe7e224519 |
|
BLAKE2b-256 | a70be1aa9f13f4068abf96dcf35810786eb212c6e916541fa32ddcafb95d4792 |
Hashes for fastkde-2.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee39894745e59844ddccdd761ec414cccda010f45f06a0e9fb0cf7f98327c7df |
|
MD5 | b2a12411f668d18e34ff4a12782b9032 |
|
BLAKE2b-256 | 7f9fa76920001d5a062fbcfac20089c6833a9a516819d2b578c9ed086ed6da41 |
Hashes for fastkde-2.0.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3665dc5a7ac6c1b11b16348d7d99b231e3fc9afe3ee2c7c168c7665be35928c |
|
MD5 | 98e617f0093b4644c0e10befc0df6093 |
|
BLAKE2b-256 | e8fef19693bf142ed4c1a25361200cd10aa18bc6756db11f7d80ebc0b3322f74 |
Hashes for fastkde-2.0.1-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83a2a09f87cf70a4da6ba6fb128598286f1c390bb128caaf2eeaa7587e78b8cf |
|
MD5 | 43e891fcbe27bee745a5aab4b9f9a2c9 |
|
BLAKE2b-256 | 25105556e86ae424d824113d1f0e206ada67a1184dcca7d0ca136c50a0d7b67d |
Hashes for fastkde-2.0.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94358b709ab1efc6370ec16d97031ccb134cd207f83b6127cd10cc67dd57f13f |
|
MD5 | 90bc8f62e4a4b2f045886bf3f53fff5c |
|
BLAKE2b-256 | 6ca6fe3decccd9ee65ae469b6658fca15631952f51cbbf8e2e894e9f1e5d1969 |
Hashes for fastkde-2.0.1-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 054a805220fcb4a0680a973f20665dfaa56f23a8be427faa52f11ee947e03e36 |
|
MD5 | e5770981d33e08b1837df42ae0ca2180 |
|
BLAKE2b-256 | 6f25f9f4fcd94bcc4736a768779eab9d3a7080b99072af80f7f1c187a02baa82 |
Hashes for fastkde-2.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a082d239903ecbbbba68f96f6e17f26b49a4d75955d38423e636c768b42c2a0a |
|
MD5 | 74b32c4de06c95ad880a8865483c17d0 |
|
BLAKE2b-256 | 3c793ceb88a97f92ea050ab23563cb3cc9053907b7b837ebde039845e46838f4 |
Hashes for fastkde-2.0.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8c83d39a5106c4ebc0652d3ffe1159300aa4114f5885121c4d0248f90677e94 |
|
MD5 | 48e0a0277e7e96850d206ffe97e66e87 |
|
BLAKE2b-256 | 672d2e392faac4dca93bcf59dcc942acded18eec0d4f3f5b9ee481ef137b10c4 |
Hashes for fastkde-2.0.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d028809cc0c436e67bd73d6db0a75ef6bb6701cc897b1e48607a7e8421ef888 |
|
MD5 | 9386a8d64215966861042e3ea0206553 |
|
BLAKE2b-256 | a3499673b3756610f9d1e0323e538ee9f66a7c1a58b4fc052160536459217dda |