From 70fa082e814cb0bd5d2043e6076b548b9b3c55ff Mon Sep 17 00:00:00 2001 From: John Hennig Date: Wed, 3 Feb 2021 14:55:53 +0100 Subject: [PATCH] Minor changes to documentation. --- docs/implementation.md | 8 +++----- docs/installation.md | 10 ++++++---- kde_diffusion/__init__.py | 4 ++-- kde_diffusion/kde1d.py | 12 +++++------- kde_diffusion/kde2d.py | 13 ++++++------- pyproject.toml | 2 ++ tests/parent.py | 4 +--- tests/test_1d.py | 4 +--- tests/test_2d.py | 4 +--- verification/kde1d_refactored.py | 4 +--- verification/kde1d_reimplemented.py | 4 +--- verification/kde2d_refactored.py | 4 +--- verification/kde2d_reimplemented.py | 4 +--- 13 files changed, 31 insertions(+), 46 deletions(-) diff --git a/docs/implementation.md b/docs/implementation.md index 9216eae..2d66458 100644 --- a/docs/implementation.md +++ b/docs/implementation.md @@ -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 diff --git a/docs/installation.md b/docs/installation.md index a2f9196..1907a2c 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -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 @@ -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/ diff --git a/kde_diffusion/__init__.py b/kde_diffusion/__init__.py index c4f6b68..d0fdd01 100644 --- a/kde_diffusion/__init__.py +++ b/kde_diffusion/__init__.py @@ -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' diff --git a/kde_diffusion/kde1d.py b/kde_diffusion/kde1d.py index d993182..15e3016 100644 --- a/kde_diffusion/kde1d.py +++ b/kde_diffusion/kde1d.py @@ -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' @@ -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. @@ -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. @@ -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 @@ -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) diff --git a/kde_diffusion/kde2d.py b/kde_diffusion/kde2d.py index 5214ffb..3f5b4ed 100644 --- a/kde_diffusion/kde2d.py +++ b/kde_diffusion/kde2d.py @@ -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' @@ -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`, @@ -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 @@ -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) diff --git a/pyproject.toml b/pyproject.toml index c74a7f2..136dd0b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [ diff --git a/tests/parent.py b/tests/parent.py index be20be3..f83f189 100644 --- a/tests/parent.py +++ b/tests/parent.py @@ -1,6 +1,4 @@ -""" -Adds the parent folder to the module search path. -""" +"""Adds the parent folder to the module search path.""" __license__ = 'MIT' diff --git a/tests/test_1d.py b/tests/test_1d.py index 98cf984..02cfa9f 100644 --- a/tests/test_1d.py +++ b/tests/test_1d.py @@ -1,6 +1,4 @@ -""" -Tests the 1d kernel density estimation. -""" +"""Tests the 1d kernel density estimation.""" __license__ = 'MIT' diff --git a/tests/test_2d.py b/tests/test_2d.py index 4c08063..cdc7b4b 100644 --- a/tests/test_2d.py +++ b/tests/test_2d.py @@ -1,6 +1,4 @@ -""" -Tests the 2d kernel density estimation. -""" +"""Tests the 2d kernel density estimation.""" __license__ = 'MIT' diff --git a/verification/kde1d_refactored.py b/verification/kde1d_refactored.py index 8dfcbf4..f95ea01 100644 --- a/verification/kde1d_refactored.py +++ b/verification/kde1d_refactored.py @@ -1,6 +1,4 @@ -""" -Demonstrates that refactoring barely affected 1d result. -""" +"""Demonstrates that refactoring barely affected 1d result.""" __license__ = 'MIT' diff --git a/verification/kde1d_reimplemented.py b/verification/kde1d_reimplemented.py index 534735d..efd3d1f 100644 --- a/verification/kde1d_reimplemented.py +++ b/verification/kde1d_reimplemented.py @@ -1,6 +1,4 @@ -""" -Reproduces exact same results as 1d reference implementation. -""" +"""Reproduces exact same results as 1d reference implementation.""" __license__ = 'MIT' diff --git a/verification/kde2d_refactored.py b/verification/kde2d_refactored.py index 07177aa..8bbf9bd 100644 --- a/verification/kde2d_refactored.py +++ b/verification/kde2d_refactored.py @@ -1,6 +1,4 @@ -""" -Demonstrates that refactoring did not affect 2d result. -""" +"""Demonstrates that refactoring did not affect 2d result.""" __license__ = 'MIT' diff --git a/verification/kde2d_reimplemented.py b/verification/kde2d_reimplemented.py index ec3776c..f3bbdef 100644 --- a/verification/kde2d_reimplemented.py +++ b/verification/kde2d_reimplemented.py @@ -1,6 +1,4 @@ -""" -Reproduces exact same results as 2d reference implementation. -""" +"""Reproduces exact same results as 2d reference implementation.""" __license__ = 'MIT'