Skip to content

Add Earth Mover's Distance to linfa-nn#440

Open
mrsanor wants to merge 1 commit into
rust-ml:masterfrom
mrsanor:earthmover-dist
Open

Add Earth Mover's Distance to linfa-nn#440
mrsanor wants to merge 1 commit into
rust-ml:masterfrom
mrsanor:earthmover-dist

Conversation

@mrsanor
Copy link
Copy Markdown
Contributor

@mrsanor mrsanor commented Apr 21, 2026

Add Earth Mover's Distance, aka. Wasserstein to linfa-nn

@mrsanor mrsanor changed the title feat(linfa-nn): Added Earth Mover's Distance Add Earth Mover's Distance to linfa-nn Apr 21, 2026
assert_abs_diff_eq!(ab, 0.9, epsilon = 1e-5);

let a = arr1(&[0.35, 0.15, 0.15, 0.10, 0.25]);
let b = arr1(&[0.1, 0.20, 0.05, 0.20, 0.45]);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight variations in input data, maybe add a comment to explain what we should see as a result. You can also test against scipy examples

let a = arr2(&[[0.3, 0.2, 0.15, 0.10, 0.25], [0.35, 0.15, 0.15, 0.10, 0.25]]);
let b = arr2(&[[0.1, 0.2, 0.05, 0.20, 0.45], [0.1, 0.20, 0.05, 0.20, 0.45]]);
let ab = dist.distance(a.view(), b.view());
assert_abs_diff_eq!(ab, 0.9 + 0.95, epsilon = 1e-5);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use previous a, b, ab variables

Copy link
Copy Markdown
Member

@relf relf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. Some minor requests...

serde(crate = "serde_crate")
)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EarthMoverDist;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would go with WassersteinDist as you put it first above and it will be consistent with scipy impl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants