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
Oriented Object Detection: Oriented RepPoints + Swin Transformer/ReResNet

Oriented RepPoints for Aerial Object Detection The code for the implementation of “Oriented RepPoints + Swin Transformer/ReResNet”. Introduction Based

96 Dec 13, 2022
Torch-ngp - A pytorch implementation of the hash encoder proposed in instant-ngp

HashGrid Encoder (WIP) A pytorch implementation of the HashGrid Encoder from ins

hawkey 1k Jan 01, 2023
DROPO: Sim-to-Real Transfer with Offline Domain Randomization

DROPO: Sim-to-Real Transfer with Offline Domain Randomization Gabriele Tiboni, Karol Arndt, Ville Kyrki. This repository contains the code for the pap

Gabriele Tiboni 8 Dec 19, 2022
A Quick and Dirty Progressive Neural Network written in TensorFlow.

prog_nn .▄▄ · ▄· ▄▌ ▐ ▄ ▄▄▄· ▐ ▄ ▐█ ▀. ▐█▪██▌•█▌▐█▐█ ▄█▪ •█▌▐█ ▄▀▀▀█▄▐█▌▐█▪▐█▐▐▌ ██▀

SynPon 53 Dec 12, 2022
FIGARO: Generating Symbolic Music with Fine-Grained Artistic Control

FIGARO: Generating Symbolic Music with Fine-Grained Artistic Control by Dimitri von Rütte, Luca Biggio, Yannic Kilcher, Thomas Hofmann FIGARO: Generat

Dimitri 83 Jan 07, 2023
Keras implementation of the GNM model in paper ’Graph-Based Semi-Supervised Learning with Nonignorable Nonresponses‘

Graph-based joint model with Nonignorable Missingness (GNM) This is a Keras implementation of the GNM model in paper ’Graph-Based Semi-Supervised Lear

Fan Zhou 2 Apr 17, 2022
Official PyTorch repo for JoJoGAN: One Shot Face Stylization

JoJoGAN: One Shot Face Stylization This is the PyTorch implementation of JoJoGAN: One Shot Face Stylization. Abstract: While there have been recent ad

1.3k Dec 29, 2022
Unofficial implementation of the Involution operation from CVPR 2021

involution_pytorch Unofficial PyTorch implementation of "Involution: Inverting the Inherence of Convolution for Visual Recognition" by Li et al. prese

Rishabh Anand 46 Dec 07, 2022
Measuring if attention is explanation with ROAR

NLP ROAR Interpretability Official code for: Evaluating the Faithfulness of Importance Measures in NLP by Recursively Masking Allegedly Important Toke

Andreas Madsen 19 Nov 13, 2022
Self-supervised learning on Graph Representation Learning (node-level task)

graph_SSL Self-supervised learning on Graph Representation Learning (node-level task) How to run the code To run GRACE, sh run_GRACE.sh To run GCA, sh

Namkyeong Lee 3 Dec 31, 2021
AdaDM: Enabling Normalization for Image Super-Resolution

AdaDM AdaDM: Enabling Normalization for Image Super-Resolution. You can apply BN, LN or GN in SR networks with our AdaDM. Pretrained models (EDSR*/RDN

58 Jan 08, 2023
Trax — Deep Learning with Clear Code and Speed

Trax — Deep Learning with Clear Code and Speed Trax is an end-to-end library for deep learning that focuses on clear code and speed. It is actively us

Google 7.3k Dec 26, 2022
PyTorch version of the paper 'Enhanced Deep Residual Networks for Single Image Super-Resolution' (CVPRW 2017)

About PyTorch 1.2.0 Now the master branch supports PyTorch 1.2.0 by default. Due to the serious version problem (especially torch.utils.data.dataloade

Sanghyun Son 2.1k Dec 27, 2022
Joint parameterization and fitting of stroke clusters

StrokeStrip: Joint Parameterization and Fitting of Stroke Clusters Dave Pagurek van Mossel1, Chenxi Liu1, Nicholas Vining1,2, Mikhail Bessmeltsev3, Al

Dave Pagurek 44 Dec 01, 2022
Deep Learning tutorials in jupyter notebooks.

DeepSchool.io Sign up here for Udemy Course on Machine Learning (Use code DEEPSCHOOL-MARCH to get 85% off course). Goals Make Deep Learning easier (mi

Sachin Abeywardana 1.8k Dec 28, 2022
Synthesizing Long-Term 3D Human Motion and Interaction in 3D in CVPR2021

Long-term-Motion-in-3D-Scenes This is an implementation of the CVPR'21 paper "Synthesizing Long-Term 3D Human Motion and Interaction in 3D". Please ch

Jiashun Wang 76 Dec 13, 2022
ConformalLayers: A non-linear sequential neural network with associative layers

ConformalLayers: A non-linear sequential neural network with associative layers ConformalLayers is a conformal embedding of sequential layers of Convo

Prograf-UFF 5 Sep 28, 2022
Code for "Training Neural Networks with Fixed Sparse Masks" (NeurIPS 2021).

Fisher Induced Sparse uncHanging (FISH) Mask This repo contains the code for Fisher Induced Sparse uncHanging (FISH) Mask training, from "Training Neu

Varun Nair 37 Dec 30, 2022
This a classic fintech problem that introduces real life difficulties such as data imbalance. Check out the notebook to find out more!

Credit Card Fraud Detection Introduction Online transactions have become a crucial part of any business over the years. Many of those transactions use

Jonathan Hasbani 0 Jan 20, 2022
ResNEsts and DenseNEsts: Block-based DNN Models with Improved Representation Guarantees

ResNEsts and DenseNEsts: Block-based DNN Models with Improved Representation Guarantees This repository is the official implementation of the empirica

Kuan-Lin (Jason) Chen 2 Oct 02, 2022