Skip to main content

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


Kernel density estimator using Nadaraya-Watson with GPU (CUDA)


Chen Chen

Running Environment Setup

You have to have cupy installed to be able to use GPU!! See

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.

  1. 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\
    ***|--- \
    ***|--- \
    ***|--- \
    *|--- \
    *|--- \
    *|--- \

  2. Install kde_gpu with following command: (Please use pip3 if the default python in your computer is python2)

    $ pip install -e .

This command will run where we specify the dependencies required to run nmf. The dependencies we require are:


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



#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)



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'])

rv = stats.truncnorm(-3,2,30,10)
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'])

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kde_gpu-0.1.0.tar.gz (4.4 kB view hashes)

Uploaded source

Built Distribution

kde_gpu-0.1.0-py3-none-any.whl (9.0 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page