forked from CodeForPhilly/clean-and-green-philly
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request CodeForPhilly#13 from CodeForPhilly/mapbox-upload
mapbox upload and awkde
- Loading branch information
Showing
28 changed files
with
6,383 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ esridump = "*" | |
sqlalchemy = "*" | ||
psycopg2-binary = "*" | ||
geoalchemy2 = "*" | ||
mapbox = "*" | ||
|
||
[dev-packages] | ||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 Thorben Menne | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Adaptive Width KDE with Gaussian Kernels | ||
|
||
## Installation | ||
|
||
This uses the awesome [pybind11](https://github.com/pybind/pybind11) package which makes creating C++ bindings super convenient. | ||
Only the evaluation is written in a small C++ snippet to speed it up, the rest is a pure python implementation. | ||
|
||
The setup is taken from the example at https://github.com/pybind/python_example | ||
Just clone the repository and invoke `pip`: | ||
|
||
```bash | ||
git clone https://github.com/mennthor/awkde | ||
pip install [--user] [-e] ./awkde | ||
``` | ||
Note: `--user` and `-e` are optional. Use `--user` to install in your user site-package directory (recommended) and `-e` if you want to only link the files to the site-package directories, so that when you make any changes in your local copy, you don't have to reinstall all the time. | ||
|
||
Try to run the `example/examply.py`: | ||
|
||
``` | ||
cd awkde/example | ||
python example.py | ||
``` | ||
|
||
You should get this plot in the examples folder (you need matplotlib for the plot): | ||
|
||
![example plot](example/example.png) | ||
|
||
|
||
## Algorithm | ||
|
||
The unweighted kernel density estimator is defined as | ||
|
||
![kernel density formula](tex/kernel_dens.png) | ||
|
||
where the product `h * lambda` takes the role of a local `sigma`. | ||
|
||
The kernel bandwith is choosen locally to account for variations in the | ||
density of the data. | ||
Areas with large density gets smaller kernels and vice versa. | ||
This smoothes the tails and gets high resolution in high statistics regions. | ||
The local bandwidth paramter is defined as | ||
|
||
![kernel density formula](tex/lambda.png) | ||
|
||
where | ||
|
||
![kernel density formula](tex/log_g.png) | ||
|
||
is some normalization and `^f(X_i)` the KDE estimate at the data point `X_i`. | ||
The local bandwidth is multiplied to the global bandwidth for each kernel. | ||
|
||
Furthermore different scales in data is accounted for by scaling it via its | ||
covariance matrix to an equal spread. | ||
First a global kernel bandwidth is applied to the transformed data and then | ||
based on that density a local bandwidth parameter is applied. | ||
|
||
All credit for the method goes to [1] and to S. Schoenen and L. Raedel for | ||
huge parts of the implementation. | ||
For information on Silverman or Scott rule, see [2] or [3]. | ||
|
||
|
||
## References | ||
- [1] B. Wang and X. Wang, "Bandwidth Selection for Weighted Kernel Density Estimation", Sep. 2007, DOI: 10.1214/154957804100000000. | ||
- [2] D.W. Scott, "Multivariate Density Estimation: Theory, Practice, and Visualization", John Wiley & Sons, New York, Chicester, 1992. | ||
- [3] B.W. Silverman, "Density Estimation for Statistics and Data Analysis", Vol. 26, Monographs on Statistics and Applied Probability, Chapman and Hall, London, 1986. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Metadata-Version: 2.1 | ||
Name: awkde | ||
Version: 0.1 | ||
Summary: Adaptive width gaussian KDE | ||
Home-page: https://github.com/mennthor/awkde | ||
Author: Thorben Menne | ||
Author-email: [email protected] | ||
License-File: LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
LICENSE | ||
README.md | ||
pyproject.toml | ||
setup.py | ||
awkde/__init__.py | ||
awkde/awkde.py | ||
awkde/tools.py | ||
awkde.egg-info/PKG-INFO | ||
awkde.egg-info/SOURCES.txt | ||
awkde.egg-info/dependency_links.txt | ||
awkde.egg-info/requires.txt | ||
awkde.egg-info/top_level.txt | ||
cpp/backend.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
numpy | ||
scipy | ||
scikit-learn | ||
pybind11 | ||
future |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
awkde |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# coding: utf-8 | ||
|
||
from __future__ import print_function | ||
from __future__ import division | ||
from __future__ import absolute_import | ||
from future import standard_library | ||
|
||
standard_library.install_aliases() | ||
|
||
from .awkde import GaussianKDE |
Oops, something went wrong.