An open API service indexing awesome lists of open source software.

https://github.com/j2kun/earthmover

Implementation of the Earthmover distance metric in python.
https://github.com/j2kun/earthmover

earthmover-distance linear-programming optimization python

Last synced: 9 months ago
JSON representation

Implementation of the Earthmover distance metric in python.

Awesome Lists containing this project

README

          

# Earthmover distance

Python code for the post [Earthmover Distance](https://jeremykun.com/2018/03/05/earthmover-distance/).

To install:

```
git clone https://github.com/j2kun/earthmover.git
cd earthmover
virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt
```

To run:

```
$ python earthmover.py
```

Example usage

```python
p1 = [
(0, 0),
(0, 1),
(0, -1),
(1, 0),
(-1, 0),
]

p2 = [
(0, 0),
(0, 2),
(0, -2),
(2, 0),
(-2, 0),
]

print(earthmover_distance(p1, p2))
```

Example output (with logging):

```
move 0.2 dirt from (0, 0) to (0, 0) for a cost of 0.0
move 0.2 dirt from (0, 1) to (0, 2) for a cost of 0.2
move 0.2 dirt from (0, -1) to (0, -2) for a cost of 0.2
move 0.2 dirt from (1, 0) to (2, 0) for a cost of 0.2
move 0.2 dirt from (-1, 0) to (-2, 0) for a cost of 0.2
0.8
```