From ba518178a15d46e217e0d92898997d9f3b9d89d0 Mon Sep 17 00:00:00 2001 From: weixin_43297441 Date: Mon, 24 Mar 2025 11:01:49 +0800 Subject: [PATCH] py --- utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/utils.py b/utils.py index d2f866d..a2b100e 100644 --- a/utils.py +++ b/utils.py @@ -954,4 +954,8 @@ You are an AI assistant. You'll provide helpful, harmless, and detailed response "\n#Question#: " + question + # "\n#Right Answer#: " + answer + "\n#Answer#: "} - ] \ No newline at end of file + ] +def mahalanobis_distance(x, mean, cov): + cov_inv = torch.inverse(cov) + delta = x - mean + return torch.sqrt(torch.einsum('bi,ij,bj->b', delta, cov_inv, delta)) \ No newline at end of file