# 2D Z-score/Mahalanobis distance that includes a penalty for uncertainty

I have some 2D points and I want to assess their performance against the target point.

When I was doing this in 1D, I took the Z-score Z = (x- mu)/sigma, but that didn't really penalise clouds of points that were wide but centred around the correct answer, so I started using the 'log posterior', which is the derivative of the Gaussian distribution,

log_posterior = -(((data - np.mean(samples))/np.std(samples))**2)/2 + np.log(1/(np.sqrt(2*np.pi)*np.std(samples)))


but now I'm working in 2D, and the parameters are correlated, so I've replaced the Z-score part with the Mahalanobis distance, and at the moment, I've put the log of the determinant of the covariance matrix as the second term - but it's this second term I am unsure of, especially as I have no 2 pi etc. What should I really be using here? I have:

new_log_posterior = distance.mahalanobis( np.array([data,data]) , np.mean(data_points,axis=0), scipy.linalg.inv(np.cov(data_points.T)))  + np.log(np.linalg.det(scipy.linalg.inv(np.cov(data_points.T))))

• Have you tried using a bi-variate Gaussian distribution ? – Jayaram Iyer Apr 6 at 16:15
• Thanks, would that be like the first log_posterior? I'm not sure what to code, I think the mahalanobis function works well for the first term? – Lizardinablizzard Apr 6 at 18:11