prospero-x / kdtree-python

A Python implementation of a K-D-Tree, as well as the Nearest Neighbor algorithm.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Summary

This library implements a k-d-tree as well as the closest neighbor algorithm in N dimensions.

Requirements

Python 3 is required.

Distance Formula

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.

Example

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

Developer

Setup

Create a new virtual environment and install the dependencies:

pew new <custom_env_name>
pip install -r requirements.txt

Testing

To test, simply run

pytest

Settings re in setup.cfg.

Style

You should regularly run flake8 from the root of the project. Certain warnings are ignored as defined in setup.cfg.

About

A Python implementation of a K-D-Tree, as well as the Nearest Neighbor algorithm.


Languages

Language:Python 100.0%