Skip to main content

A Python wrapper for Ofir Pele and Michael Werman's implementation of the Earth Mover's Distance.

Project description

https://travis-ci.org/wmayner/pyemd.svg?branch=develop

PyEMD is a Python wrapper for Ofir Pele and Michael Werman’s implementation of the Earth Mover’s Distance that allows it to be used with NumPy. If you use this code, please cite the papers listed at the end of this document.

This wrapper does not expose the full functionality of the underlying implementation; it can only used be with the np.float data type, and with a symmetric distance matrix that represents a true metric. See the documentation for the original Pele and Werman library for the other options it provides.

Installation

To install the latest release:

pip install pyemd

To install the latest development version:

pip install "git+https://github.com/wmayner/pyemd@develop#egg=pyemd"

Usage

Use PyEMD like so:

>>> from pyemd import emd
>>> import numpy as np
>>> first_signature = np.array([0.0, 1.0])
>>> second_signature = np.array([5.0, 3.0])
>>> distance_matrix = np.array([[0.0, 0.5], [0.5, 0.0]])
>>> emd(first_signature, second_signature, distance_matrix)
3.5

API

emd(first_signature, second_signature, distance_matrix)
  • first_signature: A 1-dimensional numpy array of np.float, of size N.

  • second_signature: A 1-dimensional numpy array of np.float, of size N.

  • distance_matrix: A 2-dimensional array of np.float, of size NxN. Must be symmetric and represent a metric.

Limitations and Caveats

  • distance_matrix must be symmetric.

  • distance_matrix is assumed to represent a true metric. This must be enforced by the caller. See the documentation in pyemd/lib/emd_hat.hpp.

  • The signatures and distance matrix must be numpy arrays of np.float. The original C++ template function can accept any numerical C++ type, but this wrapper only instantiates the template with double (Cython converts np.float to double). If there’s demand, I can add support for other types.

  • The original C++ functions have an optional parameter F to return the flow, which is not exposed by this wrapper. See the documentation in pyemd/lib/emd_hat.hpp.

Contributing

To help develop PyEMD, fork the project on GitHub and install the requirements with pip.

The Makefile defines some tasks to help with development:

  • buildcython: compiles the Cython code into C++ and then builds the C++ into a Python extension

  • runtests: builds everything and then runs the unit tests

  • clean: removes the compiled C++

Credit

  • All credit for the actual algorithm and implementation goes to Ofir Pele and Michael Werman. See the relevant paper.

  • Thanks to the Cython devlopers for making this kind of wrapper relatively easy to write.

Please cite these papers if you use this code:

Ofir Pele and Michael Werman, “A linear time histogram metric for improved SIFT matching,” in Computer Vision–ECCV 2008, Marseille, France, 2008, pp. 495-508.

@INPROCEEDINGS{pele2008,
  title={A linear time histogram metric for improved sift matching},
  author={Pele, Ofir and Werman, Michael},
  booktitle={Computer Vision--ECCV 2008},
  pages={495--508},
  year={2008},
  month={October},
  publisher={Springer}
}

Ofir Pele and Michael Werman, “Fast and robust earth mover’s distances,” in Proc. 2009 IEEE 12th Int. Conf. on Computer Vision, Kyoto, Japan, 2009, pp. 460-467.

@INPROCEEDINGS{pele2009,
  title={Fast and robust earth mover's distances},
  author={Pele, Ofir and Werman, Michael},
  booktitle={2009 IEEE 12th International Conference on Computer Vision},
  pages={460--467},
  year={2009},
  month={September},
  organization={IEEE}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyemd-0.2.0.tar.gz (52.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyemd-0.2.0-cp34-cp34m-macosx_10_10_x86_64.whl (54.0 kB view details)

Uploaded CPython 3.4mmacOS 10.10+ x86-64

File details

Details for the file pyemd-0.2.0.tar.gz.

File metadata

  • Download URL: pyemd-0.2.0.tar.gz
  • Upload date:
  • Size: 52.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyemd-0.2.0.tar.gz
Algorithm Hash digest
SHA256 724d49d76433af6d9d0dd2e13daff5dafafb88afcfec7377d0e02422d91cf8d1
MD5 1cd8428384903939e596fc5bd2bb688a
BLAKE2b-256 05e4d006f53edefc19b2edba0889bb754551c03d664e74ad13666c623e2ab149

See more details on using hashes here.

File details

Details for the file pyemd-0.2.0-cp34-cp34m-macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for pyemd-0.2.0-cp34-cp34m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 df80a6da5656c0efda5417ce5a36893fb9ccb7ef79998069a33f588f3901f540
MD5 2ef8eba1ef40b0e40b7681a010fb45c2
BLAKE2b-256 04ff7bf3a43e12eee43a3268b4f0e55ad2f1b24706d77ecb52ff0fc8a6cf9993

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page