Skip to content

j2kun/earthmover

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

Earthmover distance

Python code for the post 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

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

About

Implementation of the Earthmover distance metric in python.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages