sklvq.distances.Euclidean

class sklvq.distances.Euclidean[source]

Euclidean distance function

Class that holds the euclidean distance function and its gradient.

Parameters
force_all_finite{True, False, “allow-nan”}

Parameter to indicate that NaNLVQ distance variant should be used. If true no nans are allowed. If False or “allow-nan” nans are allowed.

Notes

Compatible with the GLVQ algorithm (only).

__call__(data: numpy.ndarray, model: GLVQ)numpy.ndarray[source]
Computes the Euclidean distance:

d(\mathbf{w}, \mathbf{x}) = \sqrt{(\mathbf{x} - \mathbf{w})^{\top} (\mathbf{x} - \mathbf{w})},

with \mathbf{w} a prototype and \mathbf{x} a sample.

Parameters
datandarray with shape (n_samples, n_features)

The data for which the distances to the prototypes of the model need to be computed.

modelGLVQ

A GLVQ model instance, containing the prototypes.

Returns
ndarray with shape (n_samples, n_prototypes)

Evaluation of the distance between each sample and prototype of the model.

gradient(data: numpy.ndarray, model: GLVQ, i_prototype: int)numpy.ndarray[source]

Computes the gradient of the euclidean distance with respect to a single prototype:

\frac{\partial d}{\partial \mathbf{w}_i} = -2 \cdot (\mathbf{x} - \mathbf{w}_i)

Parameters
datandarray with shape (n_samples, n_features)

The data for which the distance gradient to the prototypes of the model need to be computed.

modelGLVQ

A GLVQ model instance.

i_prototypeint

Index of the prototype to compute the gradient for.

Returns
ndarray with shape (n_samples, n_features)

The gradient of the prototype with respect to every sample in the data.