We implemented nadaraya waston kernel density and kernel conditional probability estimator using cuda through cupy. It is much faster than cpu version but it requires GPU with high memory.
Project description

kde_gpu
Kernel density estimator using Nadaraya-Watson with GPU (CUDA)
Author
Chen Chen
Running Environment Setup
You have to have cupy installed to be able to use GPU!! See https://github.com/cupy/cupy
Similar to scipy.kde_gaussian and statsmodels.nonparametric.kernel_density.KDEMultivariateConditional, we implemented nadaraya waston kernel density and kernel conditional probability estimator using cuda through cupy. However, it is much faster than cpu version and it maximise the use of GPU memory.
-
Make a folder with name "data" in current directory. Then copy ORL and CroppedYaleB dataset inside. Please make sure you have the following file tree structure:
|--- kde_gpu\
***|--- version.py \
***|--- nadaraya_watson.py \
***|--- conditional_probability.py \
*|--- setup.py \
*|--- example.py \
*|--- README.md \ -
Install
kde_gpuwith following command: (Please usepip3if the defaultpythonin your computer ispython2)$ pip install -e .
This command will run setup.py where we specify the dependencies required to run nmf. The dependencies we require are:
"scipy>=1.0.0",
"pandas>=0.20.2",
Please note that if the version number of installed package in your machine is lower than the stated version number, pip will uninstall your out-of-date package and install the one with version number greater than or equal to the stated one in setup.py.
Example
"""
@author: chen.chen.adl@gmail.com
"""
#import kernel_smoothing
from scipy import stats
import pandas as pd
import cupy as cp
import numpy as np
import time
rv = stats.expon(0,1)
x = rv.rvs(size=10000)
density_real = rv.pdf(x)
t1=time.time()
kde_scipy=stats.gaussian_kde(x.T,bw_method='silverman')
kde_scipy=kde_scipy(x.T)
print(time.time()-t1)
t1=time.time()
kde_cupy=kde(cp.asarray(x.T),bw_method='silverman')
print(time.time()-t1)
df = pd.DataFrame({'x1':x,'kde_scipy':kde_scipy,
'kde_cupy':cp.asnumpy(kde_cupy).squeeze(),'real density':density_real})
df['scipy_mean_absolute_error']=np.abs(df['kde_scipy']-df['real density'])
df['cupy_mean_absolute_error']=np.abs(df['kde_cupy']-df['real density'])
print(df.mean())
rv = stats.truncnorm(-3,2,30,10)
nsample=10000
x = cp.asarray(rv.rvs(nsample))
ycondx = cp.asarray(cp.random.rand(nsample))
y = 10*(ycondx-0.5)+x
cdf_conditional_real = ycondx
df = pd.DataFrame({'y':cp.asnumpy(y),'x':cp.asnumpy(x),'real density':cp.asnumpy(cdf_conditional_real)})
df['nadaraya watson']= kernel_smoothing_ecdf(y,x)
df['nw_error']=np.abs(df['nadaraya watson']-df['real density'])
df.mean()
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 Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kde_gpu-0.1.0.tar.gz.
File metadata
- Download URL: kde_gpu-0.1.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0215e21b1b2a2adcf3e91d145e4571bea36367a692220c7f5e7a825cca44031
|
|
| MD5 |
dd53bc5d48e38575e9b324409514dcb5
|
|
| BLAKE2b-256 |
d9fe410d24e280428efcbbabaf32f12673d2d868329cb0a70a3544d9bab46b70
|
File details
Details for the file kde_gpu-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kde_gpu-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d103109fe47e3d0723ff32f7e3669556e4cdb9cdef9891000d8a0fdfead38d8b
|
|
| MD5 |
a30572322f3c8274743685202c43b626
|
|
| BLAKE2b-256 |
a2335e976fc5e4eece71b16d36280924d99c77d2f58e20dc445ca4eb9b22276e
|