Skip to content

Commit

Permalink
Merge pull request #3 from glemvik/proofReading
Browse files Browse the repository at this point in the history
Proof reading
  • Loading branch information
tommyod committed Sep 14, 2018
2 parents 713c452 + 1e36ce8 commit 7dbc62e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 46 deletions.
4 changes: 2 additions & 2 deletions docs/source/bandwidth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ We require that :math:`\sum_i w_i = 1`.
\widehat{f}(x) = \sum_{i=1}^{N} w_i K \left( \left \| x - x_i \right \|_p \right)
To extend the equation above we divide by a scaling factor :math:`h` called the *bandwidth*.
When diving with :math:`h`, every dimension :math:`d` is stretched, so we must
When dividing with :math:`h`, every dimension :math:`d` is stretched, so we must
re-scale with :math:`h^d` to ensure that :math:`\int \widehat{f}(x) \, dx`
evaluates to unity.

Expand All @@ -23,7 +23,7 @@ We will now briefly explain two ways to find a good :math:`h`.

.. note::
In KDEpy, the bandwidth :math:`h` is the standard deviation of the kernel function.
This is because many kernels are implemented, some with bounded support and some without, and using the standard deviation to quantify the bandwidth allows easy comparison.
This is because the implementation contains many kernels, some with bounded support and some without, and using the standard deviation to quantify the bandwidth allows easy comparison.

.. image:: _static/img/KDE_bw_animation.gif
:target: #
Expand Down
12 changes: 6 additions & 6 deletions docs/source/comparison.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ Being able to weight each data point individually *and* use a fast algorithm is
``statsmodels`` implements a fast algorithm for unweighed data using the Gaussian kernel in 1D, but everything else runs using a naive algorithm, which is many orders of magnitude slower.

Automatic bandwidth selection is not available out-of-the-box in ``sklearn``, but every other implementation has one or more options.
Normal reference rules (NR) assume a normal distribution when selecting the optimal bandwidth, cross valiation (CV) minimizes an error function and the improved Sheather-Jones (ISJ) algorithm provides an asymptotically optimal bandwidth as the number of data points :math:`N \to \infty`.
Normal reference rules (NR) assume a normal distribution when selecting the optimal bandwidth, cross validation (CV) minimizes an error function and the improved Sheather-Jones (ISJ) algorithm provides an asymptotically optimal bandwidth as the number of data points :math:`N \to \infty`.
The ISJ algorithm is also very robust to multimodal distributions, which NR is not.

The times for the one-dimensional :math:`N = 10^6` data points were computed taking the median of 5 runs.
The kernel was Gaussian and the number of grid points were chosen to be :math:`n=2^{10}`.
The times for the 2D :math:`N=10^2 \times 10^2` data points are also based on the median of 5 runs using a Gaussian kernel.
The times for the 2D :math:`N=10^2 \times 10^2` data points were also based on the median of 5 runs using a Gaussian kernel.


Speed in 1D
Expand All @@ -64,14 +64,14 @@ We run the algorithms 20 times on normally distributed data and compare the medi
The plot below compares the speed of the implementations with a **Gaussian kernel**.
The 1D ``statsmodels`` implementation uses a similar algorithm when the kernel is Gaussian, and the performance is therefore somewhat comparable.

:class:`~KDEpy.FFTKDE.FFTKDE` is slower initially because it solves a non-linear equation to obtain a support threshold for the Gaussian kernel (which does not have finite support).
This is a constant cost, and as :math:`N \to \infty` it the algorithm is orders of magnitude faster than the competitors.
:class:`~KDEpy.FFTKDE.FFTKDE` is initially slower because it solves a non-linear equation to obtain a support threshold for the Gaussian kernel (which does not have finite support).
This is a constant cost, and as :math:`N \to \infty` the algorithm is orders of magnitude faster than the competitors.

.. image:: _static/img/profiling_1D_gauss.png
:scale: 100 %
:align: center

Switching to the **Epanechnikov kernel** (scipy falls back to Gaussian, since it only implements this kernel) the picture is very different.
Switching to the **Epanechnikov kernel** (scipy falls back to Gaussian, the only kernel implemented) the picture is very different.
:class:`~KDEpy.FFTKDE.FFTKDE` knows the support and does not solve an equation, while ``statsmodels`` is now forced to use a naive algorithm.
The difference is tremendous.

Expand All @@ -84,7 +84,7 @@ Speed in 2D
-----------

We run the 2D algorithms 20 times on normally distributed data and compare medians of the running times.
:class:`~KDEpy.FFTKDE.FFTKDE` is fast because of the underlying algorithm -- it implements a :math:`d`- dimensional linear binning routine and uses :math:`d`-dimensional convolution.
:class:`~KDEpy.FFTKDE.FFTKDE` is fast because of the underlying algorithm -- it implements a :math:`d`-dimensional linear binning routine and uses :math:`d`-dimensional convolution.


.. image:: _static/img/profiling_2D_gauss.png
Expand Down

0 comments on commit 7dbc62e

Please sign in to comment.