sklvq.distances.SquaredEuclidean

class sklvq.distances.SquaredEuclidean[source]

Squared Euclidean distance

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 squared Euclidean distance:

d(\mathbf{w}, \mathbf{x}) = (\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 distance gradient to the prototypes of the model need to be computed.

modelGLVQ

The 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 squared 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

The GLVQ model instance.

i_prototypeint

Index of the prototype to compute the gradient for.

Returns
gradientndarray with shape (n_samples, n_features)

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