This library implements a k-d-tree as well as the closest neighbor algorithm in N dimensions.
Python 3 is required.
This library uses a modification of the Euclidean Distance Formula, whereby the square of the Euclidean Distance, rather than the Euclidean Distance itself, is used. This optimization is possible because we're only comparing distances rather than measuring their absolute values. Note that, if using this library to find closest neighbors with 2-dimensional geographical coordinates, the Euclidean Distance Formula will only be accurate for small distances. For large distances, the Haversine Formula is needed.
An example which returns the nearest Chicago CTA Station is implemented, which uses data published on the Chicago Data Portal. It has its own set of dependencies, which can be installed with:
pew new <custom_env_name>
pip install -r example/requirements.txt
To run:
example/bin/run
Create a new virtual environment and install the dependencies:
pew new <custom_env_name>
pip install -r requirements.txt
To test, simply run
pytest
Settings re in setup.cfg.
You should regularly run flake8
from the root of the project. Certain warnings are ignored as defined in setup.cfg.