【问题标题】:how to calculate mahalanobis distance in pytorch?如何在pytorch中计算马氏距离?
【发布时间】:2020-12-16 18:17:12
【问题描述】:

计算马氏距离最有效的方法是什么:在pytorch中?

【问题讨论】:

  • 在您的上下文中,x、mu 和 sigma 是什么?喜欢它们的形状、大小、类型等?

标签: pytorch mahalanobis


【解决方案1】:

基于马氏距离的SciPy's implementation,您可以在 PyTorch 中执行此操作。假设uv 是一维的,cov 是二维协方差矩阵。

def mahalanobis(u, v, cov):
    delta = u - v
    m = torch.dot(delta, torch.matmul(torch.inverse(cov), delta))
    return torch.sqrt(m)

注意:scipy.spatial.distance.mahalanobis 接受协方差矩阵的

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-01
    • 1970-01-01
    • 2018-06-29
    • 2015-06-25
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    • 2019-07-28
    相关资源
    最近更新 更多