scikit-learn/scikit-learn — pull request #2210 by pgervais (2013-07-24 15:18:37+00:00)
Title: Euclidean pairwise distances argmin

The function `metrics.euclidean_distances_argmin` has been created. It is equivalent to:

def euclidean_distances_argmin(X, Y=None, axis=0):
return sklearn.metrics.euclidean_distances(X, Y=Y, squared=True).argmin(axis=axis)

But much more memory efficient. It computes the output array chunk-by-chunk.
Only the argmin has been implemented so far, argmax is trivial to add, but the API must be discussed. E.g. should we create another function or rename this one to something like `euclidean_distances_extrema` and add an option?

This is an implementation of part of what was suggested in issue #325.

As a side effect, the current implementation is faster than the naive one above for some inputs (usually those for which the first array is much bigger than the second, with axis=0).

An improvement in the memory usage of `check_pairwise_arrays` has also been done, and several similar improvements can probably be done elsewhere (see #2206).