Possibly a bug in scipy.spatial.distance.mahalanobis

Dear Scipy Developers: The documentation below mentions the following for the formula of mahalanobis distance: [image: \sqrt{ (u-v) V^{-1} (u-v)^T }] http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.spatial.dis... However, in the following source code, the transpose of the delta seems to be missing. u = _validate_vector(u) v = _validate_vector(v)VI = np.atleast_2d(VI)delta = u - vm = np.dot(np.dot(delta, VI), delta)return np.sqrt(m) https://github.com/scipy/scipy/blob/6a7327e8bb8248b2ea165180bc602edf1ab33dda... Please forgive me if I could not understand the source code perfectly. Thanks. Simen

@Simen seems to be right. Even on master branch [1] its still without delta transpose. [1] https://github.com/scipy/scipy/blob/master/scipy/spatial/distance.py Att, *Helder C. R. de Oliveira* EESC/Universidade de São Paulo http://helderc.net 2014-12-29 9:53 GMT-02:00 Simen Langseth <simlangen@gmail.com>:
Dear Scipy Developers:
The documentation below mentions the following for the formula of mahalanobis distance:
[image: \sqrt{ (u-v) V^{-1} (u-v)^T }]
http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.spatial.dis...
However, in the following source code, the transpose of the delta seems to be missing.
u = _validate_vector(u) v = _validate_vector(v)VI = np.atleast_2d(VI)delta = u - vm = np.dot(np.dot(delta, VI), delta)return np.sqrt(m)
https://github.com/scipy/scipy/blob/6a7327e8bb8248b2ea165180bc602edf1ab33dda...
Please forgive me if I could not understand the source code perfectly.
Thanks.
Simen
_______________________________________________ SciPy-Dev mailing list SciPy-Dev@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-dev

On Mon, Dec 29, 2014 at 6:53 AM, Simen Langseth <simlangen@gmail.com> wrote:
Dear Scipy Developers:
The documentation below mentions the following for the formula of mahalanobis distance:
[image: \sqrt{ (u-v) V^{-1} (u-v)^T }]
http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.spatial.dis...
However, in the following source code, the transpose of the delta seems to be missing.
u = _validate_vector(u) v = _validate_vector(v)VI = np.atleast_2d(VI)delta = u - vm = np.dot(np.dot(delta, VI), delta)return np.sqrt(m)
https://github.com/scipy/scipy/blob/6a7327e8bb8248b2ea165180bc602edf1ab33dda...
Please forgive me if I could not understand the source code perfectly.
The x and y arguments to mahalanobis() must be one-dimensional arrays. This is enforced by _validate_vector(), which converts arguments with shape (N,1) or (1,N) to have shape (N,). A transpose applied to a one-dimensional array doesn't do anything, so there is no need for the transpose operation in the code. Warren Thanks.
Simen
_______________________________________________ SciPy-Dev mailing list SciPy-Dev@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-dev

Dear Warren Weckesser Thanks for your explanation, and sorry for my ignorance. Your answer made me confidence in using Scipy functions. On Mon, Dec 29, 2014 at 11:27 PM, Warren Weckesser < warren.weckesser@gmail.com> wrote:
On Mon, Dec 29, 2014 at 6:53 AM, Simen Langseth <simlangen@gmail.com> wrote:
Dear Scipy Developers:
The documentation below mentions the following for the formula of mahalanobis distance:
[image: \sqrt{ (u-v) V^{-1} (u-v)^T }]
http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.spatial.dis...
However, in the following source code, the transpose of the delta seems to be missing.
u = _validate_vector(u) v = _validate_vector(v)VI = np.atleast_2d(VI)delta = u - vm = np.dot(np.dot(delta, VI), delta)return np.sqrt(m)
https://github.com/scipy/scipy/blob/6a7327e8bb8248b2ea165180bc602edf1ab33dda...
Please forgive me if I could not understand the source code perfectly.
The x and y arguments to mahalanobis() must be one-dimensional arrays. This is enforced by _validate_vector(), which converts arguments with shape (N,1) or (1,N) to have shape (N,). A transpose applied to a one-dimensional array doesn't do anything, so there is no need for the transpose operation in the code.
Warren
Thanks.
Simen
_______________________________________________ SciPy-Dev mailing list SciPy-Dev@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-dev
_______________________________________________ SciPy-Dev mailing list SciPy-Dev@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-dev
participants (3)
-
Helder
-
Simen Langseth
-
Warren Weckesser