Skip to content

Commit

Permalink
Minor changes to documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-hen committed Feb 3, 2021
1 parent d394201 commit 70fa082
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 46 deletions.
8 changes: 3 additions & 5 deletions docs/implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ the work-around altogether.

The Matlab implementation also bins the data somewhat differently in
1d vs. the 2d case. This minor inconsistency was removed. The change
is arguably insignificant as far the final results are concerned,
but is a deviation nonetheless.

In practical use, based on a handful of tests, both implementations
yield indiscernible results.
is arguably insignificant as far as the final results are concerned,
but is a deviation nonetheless. In practical use, based on a handful
of tests, both implementations yield indiscernible results.

The 2d density is returned in matrix index order, also known as
Cartesian indexing, in which the first index (the matrix row) refers
Expand Down
10 changes: 6 additions & 4 deletions docs/installation.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Installation
------------

The library is [available on PyPI][1] and can be readily installed via `pip`.
The library is [available on PyPI][1] and can be readily installed
via `pip`.

System-wide installation — recommended on Windows:
```none
Expand All @@ -13,9 +14,10 @@ Per-user installation — recommended on Linux and MacOS:
pip install KDE-diffusion --user
```

Requires [NumPy][2] and [SciPy][3]. To remove the library, replace
`install` with `uninstall` in the command from whichever method you
chose.
Requires [NumPy][2] and [SciPy][3], which `pip` will install
automatically if they aren't already. Remove the library from your
system with `pip uninstall KDE-diffusion`.


[1]: https://pypi.org/project/KDE-diffusion/
[2]: https://numpy.org/
Expand Down
4 changes: 2 additions & 2 deletions kde_diffusion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

# Meta information
__title__ = 'KDE-diffusion'
__version__ = '1.0.1'
__date__ = '2020–05–22'
__version__ = '1.0.2'
__date__ = '2021–02–03'
__author__ = 'John Hennig'
__copyright__ = 'John Hennig'
__license__ = 'MIT'
Expand Down
12 changes: 5 additions & 7 deletions kde_diffusion/kde1d.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Kernel density estimation via diffusion for 1-dimensional input data.
"""
"""Kernel density estimation via diffusion for 1-dimensional data."""
__license__ = 'MIT'


Expand Down Expand Up @@ -28,7 +26,7 @@ def kde1d(x, n=1024, limits=None):
observations of a random variable. They are binned on a grid of
`n` points within the data `limits`, if specified, or within
the limits given by the values' range. `n` will be coerced to the
next power of two if it isn't one to begin with.
next highest power of two if it isn't one to begin with.
The limits may be given as a tuple (`xmin`, `xmax`) or a single
number denoting the upper bound of a range centered at zero.
Expand All @@ -48,7 +46,7 @@ def kde1d(x, n=1024, limits=None):
# Convert to array in case a list is passed in.
x = array(x)

# Round up number of bins to the next power of two.
# Round up number of bins to next power of two.
n = int(2**ceil(log2(n)))

# Determine missing data limits.
Expand Down Expand Up @@ -76,7 +74,7 @@ def kde1d(x, n=1024, limits=None):
(binned, edges) = histogram(x, bins=n, range=(xmin, xmax))
grid = edges[:-1]

# Compute 2d discrete cosine transform. Adjust first component.
# Compute 2d discrete cosine transform, then adjust first component.
transformed = dct(binned/N)
transformed[0] /= 2

Expand Down Expand Up @@ -105,7 +103,7 @@ def ξγ(t, l=7):
# Apply Gaussian filter with optimized kernel.
smoothed = transformed * exp(-π**2 * ts/2 * k**2)

# Reverse transformation.
# Reverse transformation after adjusting first component.
smoothed[0] *= 2
inverse = idct(smoothed)

Expand Down
13 changes: 6 additions & 7 deletions kde_diffusion/kde2d.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Kernel density estimation via diffusion for 2-dimensional input data.
"""
"""Kernel density estimation via diffusion for 2-dimensional data."""
__license__ = 'MIT'


Expand All @@ -27,8 +25,9 @@ def kde2d(x, y, n=256, limits=None):
The input is two lists/arrays `x` and `y` of numbers that represent
discrete observations of a random variable with two coordinate
components. The observations are binned on a grid of n×n points,
where `n` must be a power of 2 or will be coerced to the next one.
components. The observations are binned on a grid of n×n points.
`n` will be coerced to the next highest power of two if it isn't
one to begin with.
Data `limits` may be specified as a tuple of tuples denoting
`((xmin, xmax), (ymin, ymax))`. If any of the values are `None`,
Expand Down Expand Up @@ -104,7 +103,7 @@ def kde2d(x, y, n=256, limits=None):
range=((xmin, xmax), (ymin, ymax)))
grid = (xedges[:-1], yedges[:-1])

# Compute discrete cosine transform. Adjust first component.
# Compute discrete cosine transform, then adjust first component.
transformed = dctn(binned/N)
transformed[0, :] /= 2
transformed[:, 0] /= 2
Expand Down Expand Up @@ -164,7 +163,7 @@ def ψ(i, j, t):
smoothed = transformed * outer(exp(-π**2 * k2 * tx2/2),
exp(-π**2 * k2 * tx1/2))

# Reverse transformation.
# Reverse transformation after adjusting first component.
smoothed[0, :] *= 2
smoothed[:, 0] *= 2
inverse = idctn(smoothed)
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module = 'kde_diffusion'
author = 'John Hennig'
requires = ['NumPy', 'SciPy']
requires-python = '>=3.6'
license = 'MIT'
home-page = 'https://pypi.org/project/KDE-diffusion'
description-file = 'ReadMe.md'
keywords = 'kernel density estimation, statistics'
classifiers = [
Expand Down
4 changes: 1 addition & 3 deletions tests/parent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Adds the parent folder to the module search path.
"""
"""Adds the parent folder to the module search path."""
__license__ = 'MIT'


Expand Down
4 changes: 1 addition & 3 deletions tests/test_1d.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Tests the 1d kernel density estimation.
"""
"""Tests the 1d kernel density estimation."""
__license__ = 'MIT'


Expand Down
4 changes: 1 addition & 3 deletions tests/test_2d.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Tests the 2d kernel density estimation.
"""
"""Tests the 2d kernel density estimation."""
__license__ = 'MIT'


Expand Down
4 changes: 1 addition & 3 deletions verification/kde1d_refactored.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Demonstrates that refactoring barely affected 1d result.
"""
"""Demonstrates that refactoring barely affected 1d result."""
__license__ = 'MIT'


Expand Down
4 changes: 1 addition & 3 deletions verification/kde1d_reimplemented.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Reproduces exact same results as 1d reference implementation.
"""
"""Reproduces exact same results as 1d reference implementation."""
__license__ = 'MIT'


Expand Down
4 changes: 1 addition & 3 deletions verification/kde2d_refactored.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Demonstrates that refactoring did not affect 2d result.
"""
"""Demonstrates that refactoring did not affect 2d result."""
__license__ = 'MIT'


Expand Down
4 changes: 1 addition & 3 deletions verification/kde2d_reimplemented.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Reproduces exact same results as 2d reference implementation.
"""
"""Reproduces exact same results as 2d reference implementation."""
__license__ = 'MIT'


Expand Down

0 comments on commit 70fa082

Please sign in to comment.