Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7733877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:06:31+00:00 2026-06-01T07:06:31+00:00

I’m looking for java code (or a library) that calculates the earth mover’s distance

  • 0

I’m looking for java code (or a library) that calculates the earth mover’s distance (EMD) between two histograms. This could be directly or indirectly (e.g. using the Hungarian algorithm). I found several implementations of this in c/c++ (e.g. “Fast and Robust Earth Mover’s Distances”, but I’m wondering if there is a Java version readily available.

I will be using the EMD calculation to evaluate the approach given by this paper in the context of a science project I’m working on.

Update

Using a variety of resources I estimate that the code below should do the trick. determineMinCostAssignment is the calculation of the optimal assignment as determined by the Hungarian algorithm. For this I will be using the code from http://konstantinosnedas.com/dev/soft/munkres.htm
My main concern is the calculated flow: I am not sure if this is correct. Is there someone who can verify that this is correct or not?

    /**
 * Determines the Earth Mover's Distance between two histogram assuming an equal distance between two buckets of a histogram. The distance between
 * two buckets is equal to the differences in the indexes of the buckets.
 * 
 * @param threshold
 *          The maximum distance to use between two buckets.
 */
public static double determineEarthMoversDistance(double[] histogram1, double[] histogram2, int threshold) {
    if (histogram1.length != histogram2.length)
        throw new InvalidParameterException("Each histogram must have the same number of elements");

    double[][] groundDistances = new double[histogram1.length][histogram2.length];
    for (int i = 0; i < histogram1.length; ++i) {
        for (int j = 0; j < histogram2.length; ++j) {
            int abs_diff = Math.abs(i - j);
            groundDistances[i][j] = Math.min(abs_diff, threshold);
        }
    }

    int[][] assignment = determineMinCostAssignment(groundDistances);
    double costSum = 0, flowSum = 0;
    for (int i = 0; i < assignment.length; i++) {
        double cost = groundDistances[assignment[i][0]][assignment[i][1]];
        double flow = histogram2[assignment[i][1]];
        costSum += cost * flow;
        flowSum += flow;
    }
    return costSum / flowSum;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:06:33+00:00Added an answer on June 1, 2026 at 7:06 am

    Here’s a pure Java port of the FastEMD algorithm, that I just released:
    https://github.com/telmomenezes/JFastEMD

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.