sklvq.distances.LocalAdaptiveSquaredEuclidean

class sklvq.distances.LocalAdaptiveSquaredEuclidean[source]

Local adaptive squared Euclidean distance

Class that holds the localized adaptive squared Euclidean distance function and its gradient as described in [1] and [2].

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 LGMLVQ algorithm (only).

References

[1] Schneider, P. (2010). Advanced methods for prototype-based classification. Groningen.

[2] Schneider, P., Biehl, M., & Hammer, B. (2009). Adaptive Relevance Matrices in Learning Vector Quantization. Neural Computation, 21(12), 3532–3561.

__call__(data: numpy.ndarray, model: LGMLVQ)numpy.ndarray[source]

Computes the local variant of the adaptive squared Euclidean distance:

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

with \Omega_j depending on the localization setting of the model and \Lambda_j = \Omega_j^{\top} \Omega_j. The localization can be either per prototype or per class, see the documentation of LGMLVQ.

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.

modelLGMLVQ

A LGMLVQ model instance, containing the prototypes and relevance matrices.

Returns
ndarray with shape (n_samples, n_prototypes)

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

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

Computes the gradient of the localized adaptive squared euclidean distance function with respect to a specified prototype:

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

and implicitly coupled omega matrix (per element):

\frac{\partial d}{\partial \Omega_{lm}} =  2 \sum_i (x^i - w^i)
\Omega_{li} (x^m - w^m)

Parameters
datandarray with shape (n_samples, n_features)

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

modelLGMLVQ

The LGMLVQ model instance, containing the prototypes and relevance matrices.

i_prototypeint

An integer index value of the relevant prototype

Returns
ndarray with shape (n_samples, n_features + n_omega_elements)

The gradient of the prototype and omega matrix with respect to each data sample.