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.0-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f681b6a78a506a18cac30133b30ccfc7ca960b1ea563d985820889f43b135829 |
|
MD5 | fab3fc6b9bd3a35c700d0d44eddb9547 |
|
BLAKE2b-256 | 0c4a264038256fe28d9e2707620030fe76d96748c9f2e5d48b56d01fad26941a |
Hashes for fastkde-2.0.0-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63ab85c823e62cbf8ba57c06508f3187a097432bdbbb04053d5d215a4220f5ab |
|
MD5 | 998ec83857e26d0bd8e69f22b34e3673 |
|
BLAKE2b-256 | dbcad3274b2cc7723e61093e23a86210ad1b411327b5a96ab4b9c8d8b4267453 |
Hashes for fastkde-2.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74d5048612bcdc1f1c3debbc924c05d989630e33a0f2dd2b7953dd66d5e2d3a7 |
|
MD5 | b467398c177dee6d797b336a9c845fb8 |
|
BLAKE2b-256 | d053d601c02c9cdf25fd2f71972251a5dfc0b574cda2786655fdc8dd20c0461d |
Hashes for fastkde-2.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35fcdecf499cfac963f0e107bf1849fc104c6def855dbecf500c7f632c7ef2c9 |
|
MD5 | c7fef6404a8546e54b93cae45d323b50 |
|
BLAKE2b-256 | f32be5e0b440869c9f179200612990b110c0e7fca6ff63a8074157b0a841a28c |
Hashes for fastkde-2.0.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21b7e3a02dbb5d191c9d4c1c26ae48582ff379a6a15c2064a481841f9caa0b4f |
|
MD5 | c80db3e458dfce76c87f88f617dde831 |
|
BLAKE2b-256 | eb3ca02c7614333cdc0d8946a86f29c0e81422a5df969769c913329fa6160e9b |
Hashes for fastkde-2.0.0-cp312-cp312-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b59685911a92cb525e5a880e28680723995032a0b4bd0566342ce4005a98de0b |
|
MD5 | 6fc0172549d91a5f5e0ba35ccc046b54 |
|
BLAKE2b-256 | b64c10252f30a716b0485796b33ba73ddc7c9e88d8657fa124fcd30ed3ebec04 |
Hashes for fastkde-2.0.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7808b8f9f3c44e3d77a484bf3212a31e9b5c82b63e07be96493c0d70bc1f6dd |
|
MD5 | ef23206b7ae2b256a56cd8626baba4d3 |
|
BLAKE2b-256 | 44913625c983422a390ecce2c1f168732dc38829a2151b47bfb2a78415c84055 |
Hashes for fastkde-2.0.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b71e50d973f4a1796b262300c28915653348777f8696e9f0aba88181e1ae3aa5 |
|
MD5 | 659edf9330201bba905012f9c3778afd |
|
BLAKE2b-256 | e3667085c045b0980166d12cfeb0393186df10a395916c0654fea839deb665c2 |
Hashes for fastkde-2.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ead814d8647cdf12aa21fbf439ee335c0271830f86e29c70469a36128cd6e824 |
|
MD5 | cec39fa9afcc6a49dc0b8ed75166aa4b |
|
BLAKE2b-256 | 08b0c56d8d3c2057005cc0febec9ec231325e76fba337aa3fbc95b607f3ff6fa |
Hashes for fastkde-2.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdb0942304d74d46ac2bb4fbf199c17588a8cd12aebd6c036e548acbf7e407ae |
|
MD5 | 69eaa30ee0080fd46fd11eb3bafb941a |
|
BLAKE2b-256 | 6693311e87a8c49989946e553f76236429b4ea957b525e9fc7fbe36e03a718c1 |
Hashes for fastkde-2.0.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b017c36778e9fdb83632cca97f479cf7a7709f3bf016871dff6fcff708cb8743 |
|
MD5 | 198b5efc5d1e17e79e40a4ddfdcbacfb |
|
BLAKE2b-256 | 251175e296e230d1c19f62856fd90bfb5c64a411ff1a2a82c81c33deb87a37f9 |
Hashes for fastkde-2.0.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed6dd1d01b0b9d52b629268b1df88a4ff7a46173ad23a748634881d240e8796f |
|
MD5 | f871835c321609f8ff17734a36cff671 |
|
BLAKE2b-256 | 82ae09a83d56329ba19cb8d14786af20fbfc287a15366aa65ec07180d8513c99 |
Hashes for fastkde-2.0.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 809356453426cfc431c49043530f8a38f01160abb4ae91fe88404539b8977366 |
|
MD5 | 965337a22738b6506f94759a745b6b87 |
|
BLAKE2b-256 | 79fc942472caa40270f5de4f9c9ae7d669f0354a28fa21f463e47f13761bb477 |
Hashes for fastkde-2.0.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da6447c7fc5fb6055c7ddea74d2051e85d43efd3fdee641913f7399cba454394 |
|
MD5 | 234ea1d37e242552f6752ad540c739d9 |
|
BLAKE2b-256 | 582fbcfa92eb00d784a8d9caae9028f3a121fbce1bedaf53df07af1c50b49f7b |
Hashes for fastkde-2.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6df4ada4625c0827a0d5657e8d7fd46386fe801a88d1194fde6c2953a42c07b2 |
|
MD5 | ed8e7e6956baac3534017bfcdc87555d |
|
BLAKE2b-256 | 2232aaea5d63bc974c522153302bdc5fb3acb715cc2f01a4a7c23df148e8dfa3 |
Hashes for fastkde-2.0.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35e4e56a4726479918538df5dba8db6ae46c702773a10f9739f70792182f87cb |
|
MD5 | 389cd007fe626dcbb1f5ceddddef2306 |
|
BLAKE2b-256 | 61c38fc64202d27a84b44633f58d507dc8420c69e7ee6ee3f9716d0fea842eff |
Hashes for fastkde-2.0.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3550f2bc3acf7c5257cd78ec42aa4fb82b3bd3df1f040d43a6491f48d8df0f3 |
|
MD5 | 5c22e6f02a9b694325ac7c72ee76fc03 |
|
BLAKE2b-256 | 9b28a02418cd4c44d5a2a4a9fb6ba4da39bb348d5e3cd9b54e4ab01acde409e1 |
Hashes for fastkde-2.0.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b726b1512cf2fe849e21f4c19e8a3da0ee18c2ab883127e6237a0a1332e82e9 |
|
MD5 | f5f031f3be59e6587000e11c93cb2cd8 |
|
BLAKE2b-256 | 01f13a1a3fc8d50a791ff3f81538393347a68e71fa1de8b0423836293284f381 |
Hashes for fastkde-2.0.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a846441870f00d62c3018ff01d6663bb37010d7160bf9bde4eff4f0248ae39bf |
|
MD5 | abefb070477b3ee953e9708b379caa99 |
|
BLAKE2b-256 | e73038d1a1fbd62bd94356587e9a09f95cfbe9dacede7fd0566a9775e54d9939 |
Hashes for fastkde-2.0.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3663009c6218609a690dcd4160f403c9796b2afe2bf64e751caf1b3662c311c9 |
|
MD5 | c2ab87e56438f02850bc6f07e8fb5d3a |
|
BLAKE2b-256 | 70a3539a3a9e5c340f2b21aa5be4b351c78393ec530c9f47c3c14c033e16b661 |
Hashes for fastkde-2.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20040acec887b6723e9d4b56510477df0a9d20098b76566bb70fb366e4b0b01d |
|
MD5 | 9ef96e35ba1e090e91440dd31c7a9d46 |
|
BLAKE2b-256 | 89f6389f43fec855382a05753f7d3af28d83dd97680dc1c8c387f48f0391edbe |
Hashes for fastkde-2.0.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 712ec168e147ca613017642aa6a034d78968099cd35fb72ae4ea8a63d01f71e4 |
|
MD5 | 145f095a5a6a2751de7f15b84df5a0a7 |
|
BLAKE2b-256 | 43b09dbf3e157b6ee37e40d72870d3e6f5493eeacd13780b947428b88656580d |
Hashes for fastkde-2.0.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42f7759b686db5de3863fb65b0c4ac768da9883477f98e704932940e122b96b0 |
|
MD5 | c625f4875167d3349baf7c8679048811 |
|
BLAKE2b-256 | 2c13214c4d647717fc14a754f5d36aaadebc1733bfb6f6b9353b8491ef033138 |
Hashes for fastkde-2.0.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ea64a72296fcaa49ea5f43a9549bb42e65e8182bace515aca39813302d4caa3 |
|
MD5 | 1c1016f2b3c62dc0f18b977851e4cf5e |
|
BLAKE2b-256 | 27808b52ef47b67197ce4a185651f681926b65d2e5a4ce50412425ffbe65e12d |
Hashes for fastkde-2.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d2a798a2733581dbfa9d4df506e4810c1ea65e530821008b1cc5ef914e37c49 |
|
MD5 | efec788e713b741a2f1cb172917cfb31 |
|
BLAKE2b-256 | 33b81bb4b0f13436d60728fb33c9230859dcef5e7a49f8545e0c9d4f2ca530b3 |
Hashes for fastkde-2.0.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e3975dd5643f0f8dbd1dd7c18ce7d1e9f3e19dac931b8798cfb35dc2abb1bd5 |
|
MD5 | 51fbf3e47b034ade398fc8bb458addf6 |
|
BLAKE2b-256 | 6b2d8a134f3650dff44f994d3e35057f3b7e26fe26f360350d21b38b700715f2 |
Hashes for fastkde-2.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a765fcfc86063e15a46b9651b40d0512920d1afea314ad473aa9ad1274c8c20 |
|
MD5 | 6f2e65949b156fd16c5f5fbff95b81f4 |
|
BLAKE2b-256 | 729d05fe78c5c27f79c353b2ce3806036e03b3aec2647a83e2c4ca7b08b06da3 |
Hashes for fastkde-2.0.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30b6d7bdf2ad4f31a1b23d891a65c816098bb7fd300ab1b1d5c44218c755808a |
|
MD5 | bc8a5221254d351953a6003f3359c366 |
|
BLAKE2b-256 | 228a133e3a274562630be3b9a91664ee8f9d56429b8dfd8b663a9679b9ecd25d |
Hashes for fastkde-2.0.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c404a41ee7cae99ee20016f549a553d0198066c4d652dc2a2fe03a20de6ff06b |
|
MD5 | 0b4d09b85c501837e600f96fa6875740 |
|
BLAKE2b-256 | 947266c09d039c916ae5d10f6f0a69412aade86323a91e086a8cb63c65f71efc |
Hashes for fastkde-2.0.0-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cca8efb9f919dfaf63ed2206545261117b2583dae4b5138ee4c73634b2ae533 |
|
MD5 | dee59a8057781b3d7f0e1a5fa491f554 |
|
BLAKE2b-256 | 800225949668bf548b4a284ee5c4c2d2881e50e0db79b9fcc22697cdad96fccc |
Hashes for fastkde-2.0.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6acd0e20d6c3ba20a37f69d6823d7fc4d35878b0cd7210eaaca3c80f9738f77b |
|
MD5 | ab6d08ffdd5c739b12e03ac90f0a28a8 |
|
BLAKE2b-256 | 4368ac74801f26d28137ff7825b24e10dec1d2bd7567f88938ba90241a755122 |
Hashes for fastkde-2.0.0-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab5a0f7debc1057b0c88aabec5b92de4f89d74ac4e78235937dd4460515b5883 |
|
MD5 | 0fb5c592e469fa886c1c1e671d098914 |
|
BLAKE2b-256 | c2c1c8f55c827df03f49ddb7c08f55945c809d66ad93609e0b0b18f7969a0619 |
Hashes for fastkde-2.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d583a080366082886a2b9531be8fa90084fd7d84226f6490b7b6fa18991acb33 |
|
MD5 | 8a8661dc335f71bfe56e7f30afa32c11 |
|
BLAKE2b-256 | d28fedf9a5080f65a5aa38e591132733f46b1d2f69d3e72ac67ad50e6701ba1c |
Hashes for fastkde-2.0.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | efefacacb4e52a89411a7b4ef9ab45157878876576b097c12b4eb69f9d357738 |
|
MD5 | 77a0379861e3fbddc64805d3b0636c25 |
|
BLAKE2b-256 | 21d9704f552e4467133c4edfa1c660bdc271ff008dfc3e65ab051487b2495072 |
Hashes for fastkde-2.0.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4d0037dd423e30197f9e1dcb9d038786ea6f6efd2aa6331a7c6aafbd3cd0eb4 |
|
MD5 | b25d82b3b8cc53c6e9c6b3ed0df95ef5 |
|
BLAKE2b-256 | 1357e565f3ca2fcc1ec0365f783279f6289e094192cc5eafd5c74d5a5fd8794f |