pytorch / ignite

High-level library to help with training and evaluating neural networks in PyTorch flexibly and transparently.
https://pytorch-ignite.ai
BSD 3-Clause "New" or "Revised" License
4.51k stars 612 forks source link

Add MaximumMeanDiscrepancy metric #3243

Closed kzkadc closed 5 months ago

kzkadc commented 5 months ago

Description: added maximum mean discrepancy (MMD) metric, which measures the discrepancy of two distributions. https://www.onurtunali.com/ml/2019/03/08/maximum-mean-discrepancy-in-machine-learning.html

Check list:

vfdev-5 commented 5 months ago

@kzkadc can you please check and fix the issue with doctest CI job:

**********************************************************************
File "../../ignite/metrics/maximum_mean_discrepancy.py", line ?, in default
Failed example:
    metric = MaximumMeanDiscrepancy()
    metric.attach(default_evaluator, "mmd")
    x = torch.tensor([[-0.80324818, -0.95768364, -0.03807209],
                    [-0.11059691, -0.38230813, -0.4111988],
                    [-0.8864329, -0.02890403, -0.60119252],
                    [-0.68732452, -0.12854739, -0.72095073],
                    [-0.62604613, -0.52368328, -0.24112842]])
    y = torch.tensor([[0.0686768, 0.80502737, 0.53321717],
                    [0.83849465, 0.59099726, 0.76385441],
                    [0.68688272, 0.56833803, 0.98100778],
                    [0.55267761, 0.13084654, 0.45382906],
                    [0.0754253, 0.70317304, 0.4756805]])
    state = default_evaluator.run([[x, y]])
    print(state.metrics["mmd"])
Expected:
    1.0726975202560425
Got:
    1.072697639465332

https://github.com/pytorch/ignite/actions/runs/8991931786/job/24700585654#step:7:895 Thanks!