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.
- Host: GitHub
- URL: https://github.com/j2kun/earthmover
- Owner: j2kun
- License: mit
- Created: 2018-03-04T00:00:09.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2023-07-04T02:03:55.000Z (over 2 years ago)
- Last Synced: 2025-04-02T19:46:55.849Z (10 months ago)
- Topics: earthmover-distance, linear-programming, optimization, python
- Language: Python
- Size: 54.7 KB
- Stars: 14
- Watchers: 2
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```