Fast EMD for Python: a wrapper for Pele and Werman's C++ implementation of the Earth Mover's Distance metric

Overview
https://img.shields.io/travis/wmayner/pyemd/develop.svg?style=flat-square&maxAge=3600 Python versions badge

PyEMD: Fast EMD for Python

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.

Installation

pip install pyemd

Usage

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

You can also get the associated minimum-cost flow:

>>> from pyemd import emd_with_flow
>>> emd_with_flow(first_histogram, second_histogram, distance_matrix)
(3.5, [[0.0, 0.0], [0.0, 1.0]])

You can also calculate the EMD directly from two arrays of observations:

>>> from pyemd import emd_samples
>>> first_array = [1, 2, 3, 4]
>>> second_array = [2, 3, 4, 5]
>>> emd_samples(first_array, second_array, bins=2)
0.5

Documentation

emd()

emd(first_histogram,
    second_histogram,
    distance_matrix,
    extra_mass_penalty=-1.0)

Arguments:

  • first_histogram (np.ndarray): A 1D array of type np.float64 of length N.
  • second_histogram (np.ndarray): A 1D array of np.float64 of length N.
  • distance_matrix (np.ndarray): A 2D array of np.float64, of size at least N × N. This defines the underlying metric, or ground distance, by giving the pairwise distances between the histogram bins. NOTE: It must represent a metric; there is no warning if it doesn't.

Keyword Arguments:

  • extra_mass_penalty (float): The penalty for extra mass. If you want the resulting distance to be a metric, it should be at least half the diameter of the space (maximum possible distance between any two points). If you want partial matching you can set it to zero (but then the resulting distance is not guaranteed to be a metric). The default value is -1.0, which means the maximum value in the distance matrix is used.

Returns: (float) The EMD value.


emd_with_flow()

emd_with_flow(first_histogram,
              second_histogram,
              distance_matrix,
              extra_mass_penalty=-1.0)

Arguments are the same as for emd().

Returns: (tuple(float, list(list(float)))) The EMD value and the associated minimum-cost flow.


emd_samples()

emd_samples(first_array,
            second_array,
            extra_mass_penalty=-1.0,
            distance='euclidean',
            normalized=True,
            bins='auto',
            range=None)

Arguments:

  • first_array (Iterable): An array of samples used to generate a histogram.
  • second_array (Iterable): An array of samples used to generate a histogram.

Keyword Arguments:

  • extra_mass_penalty (float): Same as for emd().
  • distance (string or function): A string or function implementing a metric on a 1D np.ndarray. Defaults to the Euclidean distance. Currently limited to 'euclidean' or your own function, which must take a 1D array and return a square 2D array of pairwise distances.
  • normalized (boolean): If true (default), treat histograms as fractions of the dataset. If false, treat histograms as counts. In the latter case the EMD will vary greatly by array length.
  • bins (int or string): The number of bins to include in the generated histogram. If a string, must be one of the bin selection algorithms accepted by np.histogram(). Defaults to 'auto', which gives the maximum of the 'sturges' and 'fd' estimators.
  • range (tuple(int, int)): The lower and upper range of the bins, passed to numpy.histogram(). Defaults to the range of the union of first_array and second_array. Note: if the given range is not a superset of the default range, no warning will be given.

Returns: (float) The EMD value between the histograms of first_array and second_array.


Limitations and Caveats

  • emd() and emd_with_flow():
    • The distance_matrix is assumed to represent a metric; there is no check to ensure that this is true. See the documentation in pyemd/lib/emd_hat.hpp for more information.
    • The histograms and distance matrix must be numpy arrays of type np.float64. The original C++ template function can accept any numerical C++ type, but this wrapper only instantiates the template with double (Cython converts np.float64 to double). If there's demand, I can add support for other types.
  • emd_with_flow():
    • The flow matrix does not contain the flows to/from the extra mass bin.
  • emd_samples():
    • With numpy < 1.15.0, using the default bins='auto' results in an extra call to np.histogram() to determine the bin lengths, since the NumPy bin-selectors are not exposed in the public API. For performance, you may want to set the bins yourself. If numpy >= 1.15 is available, np.histogram_bin_edges() is called instead, which is more efficient.

Contributing

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

The Makefile defines some tasks to help with development:

  • test: Run the test suite
  • build Generate and compile the Cython extension
  • clean: Remove the compiled Cython extension
  • default: Run build

Tests for different Python environments can be run with tox.

Credit

  • All credit for the actual algorithm and implementation goes to Ofir Pele and Michael Werman. See the relevant paper.
  • Thanks to the Cython developers for making this kind of wrapper relatively easy to write.

Please cite these papers if you use this code:

Ofir Pele and Michael Werman. Fast and robust earth mover's distances. 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}
}

Ofir Pele and Michael Werman. A linear time histogram metric for improved SIFT matching. 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}
}
Comments
  • I got an error while trying to import pyemd. It only occurred on Ubuntu.

    I got an error while trying to import pyemd. It only occurred on Ubuntu.

    Hi, I'm facing this error message when I tried to import pyemd in my code:

    Traceback (most recent call last):
      File "vincent.py", line 30, in <module>
        from pyemd import emd
      File "/home/cragkhit/anaconda3/envs/myenv/lib/python3.6/site-packages/pyemd/__init__.py", line 67, in <module>
        from .emd import emd
    ImportError: /home/cragkhit/anaconda3/envs/myenv/lib/python3.6/site-packages/pyemd/emd.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZTINSt8ios_base7failureB5cxx11E
    

    I use Anaconda virtual environment in my development. The error message only occur on Ubuntu. Everything works fine on my macOS. I'm using

    Distributor ID:	Ubuntu
    Description:	Ubuntu 16.04.2 LTS
    Release:	16.04
    Codename:	xenial
    
    opened by cragkhit 23
  • Getting the flows

    Getting the flows

    Thanks for the wrapper, it has been very useful to me! For my application, I would like to get the flows as well, and I was wondering whether it would be possible?

    I read over the original C++ code, and if I understood well you can pass a pointer to a std::vector<std::vector<NUM_T>> initialised with 0, and it will modify the container in place, giving you the flows. Am I right? I am a complete beginners with Cython. Would you have any pointer to some useful tutorials (besides the doc) to get me started? Since python functions do not modify objects in place, I am a bit confused.

    I'll see what I can do, and file a PR once/if I ever managed to include this function!

    opened by rlouf 23
  • where can i get emd.c

    where can i get emd.c

    When I run pip install pyemd, it's erroring out on x86_64-linux-gnu-gcc: error: pyemd/emd.c: No such file or directory. Is there some external dependency? Thanks.

    opened by tinman6 16
  • Error upgrading to 0.5.0

    Error upgrading to 0.5.0

    When trying to upgrade to 0.5.0 I'm getting the following output:

    Collecting pyemd
      Using cached pyemd-0.5.0.tar.gz
        Complete output from command python setup.py egg_info:
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "/tmp/pip-build-odst_5et/pyemd/setup.py", line 87, in <module>
            README = f.read()
          File "/srv/.pyenv/versions/3.6.3/lib/python3.6/encodings/ascii.py", line 26, in decode
            return codecs.ascii_decode(input, self.errors)[0]
        UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 2247: ordinal not in range(128)
    
        ----------------------------------------
    Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-odst_5et/pyemd/
    

    Seems like there's an issue with decoding a file. Shouldn't unicode be used instead of ascii? Is this an issue with my system configuration?

    Thanks!

    opened by johnhaley81 7
  • Installation issues with mac

    Installation issues with mac

    I'm having a bit of a problem trying to install this on my mac

    (bio)pyemd mortonjt$ nosetests .
    EE
    ======================================================================
    ERROR: Failure: ImportError (dlopen(/Users/mortonjt/Documents/software/python/pyemd/pyemd/emd.cpython-35m-darwin.so, 2): Symbol not found: __ZNSt8__detail15_List_node_base7_M_hookEPS0_
      Referenced from: /Users/mortonjt/Documents/software/python/pyemd/pyemd/emd.cpython-35m-darwin.so
      Expected in: dynamic lookup
    )
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/mortonjt/miniconda2/envs/bio/lib/python3.5/site-packages/nose/failure.py", line 39, in runTest
        raise self.exc_val.with_traceback(self.tb)
      File "/Users/mortonjt/miniconda2/envs/bio/lib/python3.5/site-packages/nose/loader.py", line 418, in loadTestsFromName
        addr.filename, addr.module)
      File "/Users/mortonjt/miniconda2/envs/bio/lib/python3.5/site-packages/nose/importer.py", line 47, in importFromPath
        return self.importFromDir(dir_path, fqname)
      File "/Users/mortonjt/miniconda2/envs/bio/lib/python3.5/site-packages/nose/importer.py", line 94, in importFromDir
        mod = load_module(part_fqname, fh, filename, desc)
      File "/Users/mortonjt/miniconda2/envs/bio/lib/python3.5/imp.py", line 244, in load_module
        return load_package(name, filename)
      File "/Users/mortonjt/miniconda2/envs/bio/lib/python3.5/imp.py", line 216, in load_package
        return _load(spec)
      File "<frozen importlib._bootstrap>", line 693, in _load
      File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 662, in exec_module
      File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
      File "/Users/mortonjt/Documents/software/python/pyemd/pyemd/__init__.py", line 60, in <module>
        from .emd import emd
    ImportError: dlopen(/Users/mortonjt/Documents/software/python/pyemd/pyemd/emd.cpython-35m-darwin.so, 2): Symbol not found: __ZNSt8__detail15_List_node_base7_M_hookEPS0_
      Referenced from: /Users/mortonjt/Documents/software/python/pyemd/pyemd/emd.cpython-35m-darwin.so
      Expected in: dynamic lookup
    

    pip install gives the exact same issue. I'm also using python3.5.

    Do you have any suggestions around this? Thanks!

    opened by mortonjt 6
  • do you have more challenging example than on main page

    do you have more challenging example than on main page

    do you have more challenging example than on main page to how it works for complicated cases?

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

    opened by Sandy4321 5
  • emd vs emd_samples

    emd vs emd_samples

    I am slightly confused by your description of emd and emd_samples, since for emd you wrote histogram as parameter and for emd_sample 1D samples.

    If I want to compare two images by emd and I use emd_samples. Do I have to pass the images or the histograms of the images to the method?

    opened by Kawue 5
  • Support for multi-dimensional points

    Support for multi-dimensional points

    Hi,

    Do you plan on adding support for multi-dimensional points ? I am working with (x,y,z) coordinates and it would be of huge help if this support would be added.

    Thanks!

    opened by pclucas14 5
  • Do not understand output

    Do not understand output

    Hi, I'd appreciate some explanation on what the inputs/outputs actually mean. I see the distance_matrix as the matrix of distances between the cluster centroids/representatives as described in the paper, where element (i,j) is the distance between cluster i from first_histogram and cluster j from second_histogram. In this case there is of course no restriction on distance_matrix being symmetric. However, I see that in the examples the matrix is always symmetric. Is this just a coincidence or is there something I don't know?

    Also, why is it that the following two examples produce different results? Why is it that the flow is the same?

    first_histogram = np.array([4.0, 6.0]) second_histogram = np.array([5.0, 5.0]) distance_matrix = np.array([[0.5, 0.0],[0.0, 0.5]]) emd_with_flow(first_histogram, second_histogram, distance_matrix) (0.0, [[4.0, 0.0], [1.0, 5.0]])

    first_histogram = np.array([4.0, 6.0]) second_histogram = np.array([5.0, 5.0]) distance_matrix = np.array([[0.0, 0.5],[0.5, 0.0]]) emd_with_flow(first_histogram, second_histogram, distance_matrix) (0.5, [[4.0, 0.0], [1.0, 5.0]])

    Thanks for your time.

    opened by josedvq 4
  • Include LICENSE and data files via MANIFEST.in

    Include LICENSE and data files via MANIFEST.in

    This includes files required for compilation and distribution via MANIFEST.in rather than package_data which gets installed.


    Before this change, this is the content of the source distribution file:

    x pyemd-0.4.2/
    x pyemd-0.4.2/PKG-INFO
    x pyemd-0.4.2/pyemd/
    x pyemd-0.4.2/pyemd/__about__.py
    x pyemd-0.4.2/pyemd/__init__.py
    x pyemd-0.4.2/pyemd/emd.cpp
    x pyemd-0.4.2/pyemd/emd.pyx
    x pyemd-0.4.2/pyemd/lib/
    x pyemd-0.4.2/pyemd/lib/EMD_DEFS.hpp
    x pyemd-0.4.2/pyemd/lib/emd_hat.hpp
    x pyemd-0.4.2/pyemd/lib/emd_hat_impl.hpp
    x pyemd-0.4.2/pyemd/lib/emd_hat_signatures_interface.hpp
    x pyemd-0.4.2/pyemd/lib/flow_utils.hpp
    x pyemd-0.4.2/pyemd/lib/min_cost_flow.hpp
    x pyemd-0.4.2/README.rst
    x pyemd-0.4.2/setup.py
    x pyemd-0.4.2/test/
    x pyemd-0.4.2/test/test_pyemd.py
    

    And the files to be installed:

    build/lib.macosx-10.6-x86_64-3.5
    build/lib.macosx-10.6-x86_64-3.5/pyemd
    build/lib.macosx-10.6-x86_64-3.5/pyemd/__about__.py
    build/lib.macosx-10.6-x86_64-3.5/pyemd/__init__.py
    build/lib.macosx-10.6-x86_64-3.5/pyemd/emd.cpython-35m-darwin.so
    build/lib.macosx-10.6-x86_64-3.5/pyemd/emd.pyx
    build/lib.macosx-10.6-x86_64-3.5/pyemd/lib
    build/lib.macosx-10.6-x86_64-3.5/pyemd/lib/EMD_DEFS.hpp
    build/lib.macosx-10.6-x86_64-3.5/pyemd/lib/emd_hat.hpp
    build/lib.macosx-10.6-x86_64-3.5/pyemd/lib/emd_hat_impl.hpp
    build/lib.macosx-10.6-x86_64-3.5/pyemd/lib/emd_hat_signatures_interface.hpp
    build/lib.macosx-10.6-x86_64-3.5/pyemd/lib/flow_utils.hpp
    build/lib.macosx-10.6-x86_64-3.5/pyemd/lib/min_cost_flow.hpp
    build/lib.macosx-10.6-x86_64-3.5/README.rst
    

    After this change, this is the source distribution content:

    x pyemd-0.4.2/
    x pyemd-0.4.2/conftest.py
    x pyemd-0.4.2/LICENSE
    x pyemd-0.4.2/PKG-INFO
    x pyemd-0.4.2/pyemd/
    x pyemd-0.4.2/pyemd/__about__.py
    x pyemd-0.4.2/pyemd/__init__.py
    x pyemd-0.4.2/pyemd/emd.cpp
    x pyemd-0.4.2/pyemd/emd.pyx
    x pyemd-0.4.2/pyemd/lib/
    x pyemd-0.4.2/pyemd/lib/EMD_DEFS.hpp
    x pyemd-0.4.2/pyemd/lib/emd_hat.hpp
    x pyemd-0.4.2/pyemd/lib/emd_hat_impl.hpp
    x pyemd-0.4.2/pyemd/lib/emd_hat_signatures_interface.hpp
    x pyemd-0.4.2/pyemd/lib/flow_utils.hpp
    x pyemd-0.4.2/pyemd/lib/min_cost_flow.hpp
    x pyemd-0.4.2/README.rst
    x pyemd-0.4.2/setup.py
    x pyemd-0.4.2/test/
    x pyemd-0.4.2/test/test_pyemd.py
    

    And the files to be installed:

    build/lib.macosx-10.6-x86_64-3.5
    build/lib.macosx-10.6-x86_64-3.5/pyemd
    build/lib.macosx-10.6-x86_64-3.5/pyemd/__about__.py
    build/lib.macosx-10.6-x86_64-3.5/pyemd/__init__.py
    build/lib.macosx-10.6-x86_64-3.5/pyemd/emd.cpython-35m-darwin.so
    

    Unless the .pyx and .hpp files are intended for final user's usage, then the latter result is the correct one.

    opened by rmax 4
  • Import error while meetig all requirements

    Import error while meetig all requirements

    When trying to import this package in python 2.7 I keep getting the same error:

    >>> import pyemd
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "build/bdist.linux-x86_64/egg/pyemd/__init__.py", line 63, in <module>
      File "build/bdist.linux-x86_64/egg/pyemd/emd.py", line 7, in <module>
      File "build/bdist.linux-x86_64/egg/pyemd/emd.py", line 6, in __bootstrap__
    ImportError: /home/joris/.cache/Python-Eggs/pyemd-0.3.0-py2.7-linux-x86_64.egg-tmp/pyemd/emd.so: undefined symbol: _ZTINSt8ios_base7failureB5cxx11E
    

    I can't seem to fix this, have tried reinstalling, installing using setup.py, dowloading all requirements (numpy, scipy, cython, g++/gcc, everything in requirements.txt, everything else I could think of) but nothing seems to work. What could cause this error?

    opened by jsbaan 4
  • python 3.11 support

    python 3.11 support

    Hi! Thanks a lot for the project. Is there any plan to support python 3.11?

    When I try to install the package there I get the following error:

    Collecting pyemd
      Using cached pyemd-0.5.1.tar.gz (91 kB)
      Preparing metadata (setup.py) ... done
    Collecting numpy<2.0.0,>=1.9.0
      Using cached numpy-1.23.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.1 MB)
    Building wheels for collected packages: pyemd
      Building wheel for pyemd (setup.py) ... error
      error: subprocess-exited-with-error
      
      × python setup.py bdist_wheel did not run successfully.
      │ exit code: 1
      ╰─> [20 lines of output]
          /home/kyriakos/miniconda3/envs/valentine11/lib/python3.11/site-packages/setuptools/installer.py:27: SetuptoolsDeprecationWarning: setuptools.installer is deprecated. Requirements should be satisfied by a PEP 517 installer.
            warnings.warn(
          running bdist_wheel
          running build
          running build_py
          creating build
          creating build/lib.linux-x86_64-cpython-311
          creating build/lib.linux-x86_64-cpython-311/pyemd
          copying pyemd/__init__.py -> build/lib.linux-x86_64-cpython-311/pyemd
          copying pyemd/__about__.py -> build/lib.linux-x86_64-cpython-311/pyemd
          running build_ext
          building 'pyemd.emd' extension
          creating build/temp.linux-x86_64-cpython-311
          creating build/temp.linux-x86_64-cpython-311/pyemd
          gcc -pthread -B /home/kyriakos/miniconda3/envs/valentine11/compiler_compat -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /home/kyriakos/miniconda3/envs/valentine11/include -fPIC -O2 -isystem /home/kyriakos/miniconda3/envs/valentine11/include -fPIC -I/home/kyriakos/miniconda3/envs/valentine11/include/python3.11 -I/tmp/pip-install-hch1ioh_/pyemd_850fda2363c24de38b5a817d08842ae6/.eggs/numpy-1.23.4-py3.11-linux-x86_64.egg/numpy/core/include -c pyemd/emd.cpp -o build/temp.linux-x86_64-cpython-311/pyemd/emd.o
          pyemd/emd.cpp:200:12: fatal error: longintrepr.h: No such file or directory
            200 |   #include "longintrepr.h"
                |            ^~~~~~~~~~~~~~~
          compilation terminated.
          error: command '/usr/bin/gcc' failed with exit code 1
          [end of output]
      
      note: This error originates from a subprocess, and is likely not a problem with pip.
      ERROR: Failed building wheel for pyemd
      Running setup.py clean for pyemd
    Failed to build pyemd
    Installing collected packages: numpy, pyemd
      Running setup.py install for pyemd ... error
      error: subprocess-exited-with-error
      
      × Running setup.py install for pyemd did not run successfully.
      │ exit code: 1
      ╰─> [20 lines of output]
          running install
          /home/kyriakos/miniconda3/envs/valentine11/lib/python3.11/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
            warnings.warn(
          running build
          running build_py
          creating build
          creating build/lib.linux-x86_64-cpython-311
          creating build/lib.linux-x86_64-cpython-311/pyemd
          copying pyemd/__init__.py -> build/lib.linux-x86_64-cpython-311/pyemd
          copying pyemd/__about__.py -> build/lib.linux-x86_64-cpython-311/pyemd
          running build_ext
          building 'pyemd.emd' extension
          creating build/temp.linux-x86_64-cpython-311
          creating build/temp.linux-x86_64-cpython-311/pyemd
          gcc -pthread -B /home/kyriakos/miniconda3/envs/valentine11/compiler_compat -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /home/kyriakos/miniconda3/envs/valentine11/include -fPIC -O2 -isystem /home/kyriakos/miniconda3/envs/valentine11/include -fPIC -I/home/kyriakos/miniconda3/envs/valentine11/include/python3.11 -I/home/kyriakos/miniconda3/envs/valentine11/lib/python3.11/site-packages/numpy/core/include -c pyemd/emd.cpp -o build/temp.linux-x86_64-cpython-311/pyemd/emd.o
          pyemd/emd.cpp:200:12: fatal error: longintrepr.h: No such file or directory
            200 |   #include "longintrepr.h"
                |            ^~~~~~~~~~~~~~~
          compilation terminated.
          error: command '/usr/bin/gcc' failed with exit code 1
          [end of output]
      
      note: This error originates from a subprocess, and is likely not a problem with pip.
    error: legacy-install-failure
    
    × Encountered error while trying to install package.
    ╰─> pyemd
    
    note: This is an issue with the package mentioned above, not pip.
    hint: See above for output from the failure.
    
    
    opened by kPsarakis 1
  • EMD not leading to any results, without any error raised

    EMD not leading to any results, without any error raised

    Hello,

    My question may be a very easy one but I am loosing my nerves trying to solve it. here are my parameters : first_histogram = [1. 1. 1.] second_histogram = [2. 0. 0.] distance_matrix = array([[0. , 0. , 0. , 0.60058105, 1. ], [0. , 0. , 0. , 0.60058105, 1. ], [0. , 0. , 0. , 0.60058105, 1. ], [0.60058105, 0.60058105, 0.60058105, 0. , 0.98793931], [1. , 1. , 1. , 0.98793931, 0. ]])

    (My distance matrix is the result of sklearn.metrics.pairwise.cosine_distances(), so it truly is a distance matrix) Now if I try to do : D_EMD = emd(first_histogram, second_histogram, distance_matrix)

    The code runs for ever without getting any results, without any Error Raised...

    Does anyone have any idea what I'm doing wrong?

    Thanks a lot !

    Christel

    opened by ChristelDG 1
  • some tests hang using 100% CPU forever on 32-bit Debian powerpc

    some tests hang using 100% CPU forever on 32-bit Debian powerpc

    The Debian package of pyemd fails to build on the 32-bit powerpc port because the tests time out after 150 minutes of inactivity, while on other platforms including ppc64el and ppc64 they complete in under half a second. I logged into the powerpc porterbox perotto.debian.net, executed a build and noticed that the Python process running the tests uses 100% CPU. I deleted tests one at a time until the remaining tests were passing. Only three tests were hanging with 100% CPU: test_emd_3 test_emd_with_flow_3 test_emd_with_flow_4. The three hanging tests seem to have one thing in common, they all have a distance_matrix containing only zeros. One other test that passes has this feature too test_emd_with_flow_5 though. The three hanging tests also seem to have similar signature parameters. When running Python in gdb, interrupting the process gives a stack trace that indicates the compute_shortest_path function from min_cost_flow.hpp is using the CPU.

    Any ideas on how to debug this?

    opened by pabs3 0
  • building 'pyemd.emd' extension    error: Microsoft Visual C++ 14.0 is required.

    building 'pyemd.emd' extension error: Microsoft Visual C++ 14.0 is required.

    (base) D:>pip install pyemd Collecting pyemd Using cached pyemd-0.5.1.tar.gz (91 kB) Requirement already satisfied: numpy<2.0.0,>=1.9.0 in d:\tfs\pandit\anaconda\lib\site-packages (from pyemd) (1.18.1) Building wheels for collected packages: pyemd Building wheel for pyemd (setup.py) ... error ERROR: Command errored out with exit status 1: command: 'D:\tfs\pandit\anaconda\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\mukesh.sah\AppData\Local\Temp\pip-install-db68s9hb\pyemd\setup.py'"'"'; file='"'"'C:\Users\mukesh.sah\AppData\Local\Temp\pip-install-db68s9hb\pyemd\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\mukesh.sah\AppData\Local\Temp\pip-wheel-le7hu_jm' cwd: C:\Users\mukesh.sah\AppData\Local\Temp\pip-install-db68s9hb\pyemd
    Complete output (11 lines): running bdist_wheel running build running build_py creating build creating build\lib.win-amd64-3.7 creating build\lib.win-amd64-3.7\pyemd copying pyemd_about_.py -> build\lib.win-amd64-3.7\pyemd copying pyemd_init_.py -> build\lib.win-amd64-3.7\pyemd running build_ext building 'pyemd.emd' extension error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/

    ERROR: Failed building wheel for pyemd Running setup.py clean for pyemd Failed to build pyemd Installing collected packages: pyemd Running setup.py install for pyemd ... error ERROR: Command errored out with exit status 1: command: 'D:\tfs\pandit\anaconda\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\mukesh.sah\AppData\Local\Temp\pip-install-db68s9hb\pyemd\setup.py'"'"'; file='"'"'C:\Users\mukesh.sah\AppData\Local\Temp\pip-install-db68s9hb\pyemd\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\mukesh.sah\AppData\Local\Temp\pip-record-swz_qpxc\install-record.txt' --single-version-externally-managed --compile --install-headers 'D:\tfs\pandit\anaconda\Include\pyemd' cwd: C:\Users\mukesh.sah\AppData\Local\Temp\pip-install-db68s9hb\pyemd
    Complete output (11 lines): running install running build running build_py creating build creating build\lib.win-amd64-3.7 creating build\lib.win-amd64-3.7\pyemd copying pyemd_about_.py -> build\lib.win-amd64-3.7\pyemd copying pyemd_init_.py -> build\lib.win-amd64-3.7\pyemd running build_ext building 'pyemd.emd' extension error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/ ---------------------------------------- ERROR: Command errored out with exit status 1: 'D:\tfs\pandit\anaconda\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\mukesh.sah\AppData\Local\Temp\pip-install-db68s9hb\pyemd\setup.py'"'"'; file='"'"'C:\Users\mukesh.sah\AppData\Local\Temp\pip-install-db68s9hb\pyemd\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\mukesh.sah\AppData\Local\Temp\pip-record-swz_qpxc\install-record.txt' --single-version-externally-managed --compile --install-headers 'D:\tfs\pandit\anaconda\Include\pyemd' Check the logs for full command output.

    I am getting this error though I have installed Microsoft Visual C++ 14.0. Pyemd bug

    I am using anaconda version 2020.02 python 3.7.6 pymed version = 0.5.1 please help to fix this issue. I am installing through pip.

    opened by mukeshsah1 1
  • pyemd not building on MacOS X

    pyemd not building on MacOS X "Catalina" + Python 3.7

    pyemd fails to install on python 3.7 environment on Mac OS X Catalina (version 10.15 beta). similar to issue [#39] (https://github.com/wmayner/pyemd/issues/39)

    I am using virtualenv with python 3.7.1.

    pip install git+https://github.com/wmayner/pyemd/
    Looking in indexes: https://pypi.python.org/simple, https://pypi.apple.com/simple
    Collecting git+https://github.com/wmayner/pyemd/
      Cloning https://github.com/wmayner/pyemd/ to /private/var/folders/p7/pynm4r6x1m1f4ww8g5j3lb3m0000gn/T/pip-req-build-e51_1oq9
      Running command git clone -q https://github.com/wmayner/pyemd/ /private/var/folders/p7/pynm4r6x1m1f4ww8g5j3lb3m0000gn/T/pip-req-build-e51_1oq9
    Building wheels for collected packages: pyemd
      Building wheel for pyemd (setup.py) ... error
      ERROR: Command errored out with exit status 1:
       command: /Users/arian/Developer/workspace/signal/tilse/dev/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/p7/pynm4r6x1m1f4ww8g5j3lb3m0000gn/T/pip-req-build-e51_1oq9/setup.py'"'"'; __file__='"'"'/private/var/folders/p7/pynm4r6x1m1f4ww8g5j3lb3m0000gn/T/pip-req-build-e51_1oq9/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/p7/pynm4r6x1m1f4ww8g5j3lb3m0000gn/T/pip-wheel-y_qy4mk2 --python-tag cp37
           cwd: /private/var/folders/p7/pynm4r6x1m1f4ww8g5j3lb3m0000gn/T/pip-req-build-e51_1oq9/
      Complete output (16 lines):
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.7-x86_64-3.7
      creating build/lib.macosx-10.7-x86_64-3.7/pyemd
      copying pyemd/__init__.py -> build/lib.macosx-10.7-x86_64-3.7/pyemd
      copying pyemd/__about__.py -> build/lib.macosx-10.7-x86_64-3.7/pyemd
      running build_ext
      building 'pyemd.emd' extension
      creating build/temp.macosx-10.7-x86_64-3.7
      creating build/temp.macosx-10.7-x86_64-3.7/pyemd
      gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/arian/miniconda3/include -arch x86_64 -I/Users/arian/miniconda3/include -arch x86_64 -I/Users/arian/miniconda3/include/python3.7m -I/Users/arian/Developer/workspace/signal/tilse/dev/lib/python3.7/site-packages/numpy/core/include -c pyemd/emd.cpp -o build/temp.macosx-10.7-x86_64-3.7/pyemd/emd.o
      clang: error: no such file or directory: 'pyemd/emd.cpp'
      clang: error: no input files
      error: command 'gcc' failed with exit status 1
      ----------------------------------------
      ERROR: Failed building wheel for pyemd
      Running setup.py clean for pyemd
    Failed to build pyemd
    Installing collected packages: pyemd
      Running setup.py install for pyemd ... error
        ERROR: Command errored out with exit status 1:
         command: /Users/arian/Developer/workspace/signal/tilse/dev/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/p7/pynm4r6x1m1f4ww8g5j3lb3m0000gn/T/pip-req-build-e51_1oq9/setup.py'"'"'; __file__='"'"'/private/var/folders/p7/pynm4r6x1m1f4ww8g5j3lb3m0000gn/T/pip-req-build-e51_1oq9/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/p7/pynm4r6x1m1f4ww8g5j3lb3m0000gn/T/pip-record-a05qi2c7/install-record.txt --single-version-externally-managed --compile --install-headers /Users/arian/Developer/workspace/signal/tilse/dev/include/site/python3.7/pyemd
             cwd: /private/var/folders/p7/pynm4r6x1m1f4ww8g5j3lb3m0000gn/T/pip-req-build-e51_1oq9/
        Complete output (16 lines):
        running install
        running build
        running build_py
        creating build
        creating build/lib.macosx-10.7-x86_64-3.7
        creating build/lib.macosx-10.7-x86_64-3.7/pyemd
        copying pyemd/__init__.py -> build/lib.macosx-10.7-x86_64-3.7/pyemd
        copying pyemd/__about__.py -> build/lib.macosx-10.7-x86_64-3.7/pyemd
        running build_ext
        building 'pyemd.emd' extension
        creating build/temp.macosx-10.7-x86_64-3.7
        creating build/temp.macosx-10.7-x86_64-3.7/pyemd
        gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/arian/miniconda3/include -arch x86_64 -I/Users/arian/miniconda3/include -arch x86_64 -I/Users/arian/miniconda3/include/python3.7m -I/Users/arian/Developer/workspace/signal/tilse/dev/lib/python3.7/site-packages/numpy/core/include -c pyemd/emd.cpp -o build/temp.macosx-10.7-x86_64-3.7/pyemd/emd.o
        clang: error: no such file or directory: 'pyemd/emd.cpp'
        clang: error: no input files
        error: command 'gcc' failed with exit status 1
        ----------------------------------------
    ERROR: Command errored out with exit status 1: /Users/arian/Developer/workspace/signal/tilse/dev/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/p7/pynm4r6x1m1f4ww8g5j3lb3m0000gn/T/pip-req-build-e51_1oq9/setup.py'"'"'; __file__='"'"'/private/var/folders/p7/pynm4r6x1m1f4ww8g5j3lb3m0000gn/T/pip-req-build-e51_1oq9/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/p7/pynm4r6x1m1f4ww8g5j3lb3m0000gn/T/pip-record-a05qi2c7/install-record.txt --single-version-externally-managed --compile --install-headers /Users/arian/Developer/workspace/signal/tilse/dev/include/site/python3.7/pyemd Check the logs for full command output.
    
    opened by arianpasquali 14
  • Can't install pyemd v0.4.4

    Can't install pyemd v0.4.4

    Collecting pyemd==0.4.4 (from -r production.txt (line 175)) Downloading https://files.pythonhosted.org/packages/34/61/0f2803463c695bdde498e63a6300f7878829427ecdb9144b6306883ce7f9/pyemd-0.4.4.tar.gz (67kB) 100% |████████████████████████████████| 71kB 10.5MB/s Complete output from command python setup.py egg_info: Traceback (most recent call last): File "", line 1, in File "/tmp/pip-build-CQ7HD3/pyemd/setup.py", line 104, in 'Programming Language :: Python :: 3.6' File "/usr/lib/python2.7/distutils/core.py", line 111, in setup _setup_distribution = dist = klass(attrs) File "/usr/local/lib/python2.7/dist-packages/setuptools/dist.py", line 268, in init self.fetch_build_eggs(attrs['setup_requires']) File "/usr/local/lib/python2.7/dist-packages/setuptools/dist.py", line 313, in fetch_build_eggs replace_conflicting=True, File "/usr/local/lib/python2.7/dist-packages/pkg_resources/init.py", line 836, in resolve dist = best[req.key] = env.best_match(req, ws, installer) File "/usr/local/lib/python2.7/dist-packages/pkg_resources/init.py", line 1081, in best_match return self.obtain(req, installer) File "/usr/local/lib/python2.7/dist-packages/pkg_resources/init.py", line 1093, in obtain return installer(requirement) File "/usr/local/lib/python2.7/dist-packages/setuptools/dist.py", line 380, in fetch_build_egg return cmd.easy_install(req) File "/usr/local/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 629, in easy_install return self.install_item(spec, dist.location, tmpdir, deps) File "/usr/local/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 659, in install_item dists = self.install_eggs(spec, download, tmpdir) File "/usr/local/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 842, in install_eggs return self.build_and_install(setup_script, setup_base) File "/usr/local/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 1070, in build_and_install self.run_setup(setup_script, setup_base, args) File "/usr/local/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 1056, in run_setup run_setup(setup_script, args) File "/usr/local/lib/python2.7/dist-packages/setuptools/sandbox.py", line 240, in run_setup raise File "/usr/lib/python2.7/contextlib.py", line 35, in exit self.gen.throw(type, value, traceback) File "/usr/local/lib/python2.7/dist-packages/setuptools/sandbox.py", line 193, in setup_context yield File "/usr/lib/python2.7/contextlib.py", line 35, in exit self.gen.throw(type, value, traceback) File "/usr/local/lib/python2.7/dist-packages/setuptools/sandbox.py", line 164, in save_modules saved_exc.resume() File "/usr/local/lib/python2.7/dist-packages/setuptools/sandbox.py", line 139, in resume compat.reraise(type, exc, self._tb) File "/usr/local/lib/python2.7/dist-packages/setuptools/sandbox.py", line 152, in save_modules yield saved File "/usr/local/lib/python2.7/dist-packages/setuptools/sandbox.py", line 193, in setup_context yield File "/usr/local/lib/python2.7/dist-packages/setuptools/sandbox.py", line 237, in run_setup DirectorySandbox(setup_dir).run(runner) File "/usr/local/lib/python2.7/dist-packages/setuptools/sandbox.py", line 267, in run return func() File "/usr/local/lib/python2.7/dist-packages/setuptools/sandbox.py", line 236, in runner _execfile(setup_script, ns) File "/usr/local/lib/python2.7/dist-packages/setuptools/sandbox.py", line 46, in _execfile exec(code, globals, locals) File "/tmp/easy_install-8c1Zng/numpy-1.17.0/setup.py", line 31, in

    RuntimeError: Python version >= 3.5 required.
    
    ----------------------------------------
    

    Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-CQ7HD3/pyemd/

    opened by mike-hollibaugh 1
Releases(0.5.1)
Owner
William Mayner
PhD student in the Neuroscience Training Program, University of Wisconsin–Madison
William Mayner
Code associated with the paper "Towards Understanding the Data Dependency of Mixup-style Training".

Mixup-Data-Dependency Code associated with the paper "Towards Understanding the Data Dependency of Mixup-style Training". Running Alternating Line Exp

Muthu Chidambaram 0 Nov 11, 2021
A graph adversarial learning toolbox based on PyTorch and DGL.

GraphWar: Arms Race in Graph Adversarial Learning NOTE: GraphWar is still in the early stages and the API will likely continue to change. 🚀 Installat

Jintang Li 54 Jan 05, 2023
Public repository of the 3DV 2021 paper "Generative Zero-Shot Learning for Semantic Segmentation of 3D Point Clouds"

Generative Zero-Shot Learning for Semantic Segmentation of 3D Point Clouds Björn Michele1), Alexandre Boulch1), Gilles Puy1), Maxime Bucher1) and Rena

valeo.ai 15 Dec 22, 2022
Phy-Q: A Benchmark for Physical Reasoning

Phy-Q: A Benchmark for Physical Reasoning Cheng Xue*, Vimukthini Pinto*, Chathura Gamage* Ekaterina Nikonova, Peng Zhang, Jochen Renz School of Comput

29 Dec 19, 2022
This is the repo for the paper "Improving the Accuracy-Memory Trade-Off of Random Forests Via Leaf-Refinement".

Improving the Accuracy-Memory Trade-Off of Random Forests Via Leaf-Refinement This is the repository for the paper "Improving the Accuracy-Memory Trad

3 Dec 29, 2022
Template repository to build PyTorch projects from source on any version of PyTorch/CUDA/cuDNN.

The Ultimate PyTorch Source-Build Template Translations: 한국어 TL;DR PyTorch built from source can be x4 faster than a naïve PyTorch install. This repos

Joonhyung Lee/이준형 651 Dec 12, 2022
CoSMA: Convolutional Semi-Regular Mesh Autoencoder. From Paper "Mesh Convolutional Autoencoder for Semi-Regular Meshes of Different Sizes"

Mesh Convolutional Autoencoder for Semi-Regular Meshes of Different Sizes Implementation of CoSMA: Convolutional Semi-Regular Mesh Autoencoder arXiv p

Fraunhofer SCAI 10 Oct 11, 2022
Unsupervised Video Interpolation using Cycle Consistency

Unsupervised Video Interpolation using Cycle Consistency Project | Paper | YouTube Unsupervised Video Interpolation using Cycle Consistency Fitsum A.

NVIDIA Corporation 100 Nov 30, 2022
Neural-Pull: Learning Signed Distance Functions from Point Clouds by Learning to Pull Space onto Surfaces(ICML 2021)

Neural-Pull: Learning Signed Distance Functions from Point Clouds by Learning to Pull Space onto Surfaces(ICML 2021) This repository contains the code

149 Dec 15, 2022
This repository contains codes of ICCV2021 paper: SO-Pose: Exploiting Self-Occlusion for Direct 6D Pose Estimation

SO-Pose This repository contains codes of ICCV2021 paper: SO-Pose: Exploiting Self-Occlusion for Direct 6D Pose Estimation This paper is basically an

shangbuhuan 52 Nov 25, 2022
MINIROCKET: A Very Fast (Almost) Deterministic Transform for Time Series Classification

MINIROCKET: A Very Fast (Almost) Deterministic Transform for Time Series Classification

187 Dec 26, 2022
Continual World is a benchmark for continual reinforcement learning

Continual World Continual World is a benchmark for continual reinforcement learning. It contains realistic robotic tasks which come from MetaWorld. Th

41 Dec 24, 2022
Visualize Camera's Pose Using Extrinsic Parameter by Plotting Pyramid Model on 3D Space

extrinsic2pyramid Visualize Camera's Pose Using Extrinsic Parameter by Plotting Pyramid Model on 3D Space Intro A very simple and straightforward modu

JEONG HYEONJIN 106 Dec 28, 2022
MPViT:Multi-Path Vision Transformer for Dense Prediction

MPViT : Multi-Path Vision Transformer for Dense Prediction This repository inlcu

Youngwan Lee 272 Dec 20, 2022
OpenCV, MediaPipe Pose Estimation, Affine Transform for Icon Overlay

Yoga Pose Identification and Icon Matching Project Goal Detect yoga poses performed by a user and overlay a corresponding icon image. Running the main

Anna Garverick 1 Dec 03, 2021
3ds-Ghidra-Scripts - Ghidra scripts to help with 3ds reverse engineering

3ds Ghidra Scripts These are ghidra scripts to help with 3ds reverse engineering

Zak 7 May 23, 2022
Official Python implementation of the 'Sparse deconvolution'-v0.3.0

Sparse deconvolution Python v0.3.0 Official Python implementation of the 'Sparse deconvolution', and the CPU (NumPy) and GPU (CuPy) calculation backen

Weisong Zhao 23 Dec 28, 2022
JupyterLite demo deployed to GitHub Pages 🚀

JupyterLite Demo JupyterLite deployed as a static site to GitHub Pages, for demo purposes. ✨ Try it in your browser ✨ ➡️ https://jupyterlite.github.io

JupyterLite 223 Jan 04, 2023
Car Parking Tracker Using OpenCv

Car Parking Vacancy Tracker Using OpenCv I used basic image processing methods i

Adwait Kelkar 30 Dec 03, 2022
[CVPR 2021 Oral] ForgeryNet: A Versatile Benchmark for Comprehensive Forgery Analysis

ForgeryNet: A Versatile Benchmark for Comprehensive Forgery Analysis ForgeryNet: A Versatile Benchmark for Comprehensive Forgery Analysis [arxiv|pdf|v

Yinan He 78 Dec 22, 2022