sklvq.distances.AdaptiveSquaredEuclidean

class sklvq.distances.AdaptiveSquaredEuclidean[source]

Adaptive squared Euclidean distance

Class that holds the 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 GMLVQ 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: GMLVQ)numpy.ndarray[source]

Computes the adaptive squared Euclidean distance:

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

with the relevance matrix \Lambda = \Omega^{\top} \Omega, the prototype \mathbf{w}, and sample \mathbf{x}.

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.

modelGMLVQ

The model instance, containing the prototypes and relevance matrix.

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: GMLVQ, i_prototype: int)numpy.ndarray[source]

Computes the gradient of the adaptive squared euclidean distance function, with respect to a single prototype:

\frac{\partial d}{\partial \mathbf{w_i}} = -2 \Lambda (\mathbf{x} -
\mathbf{w_i}),

and the 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 data for which the distance gradient to the prototypes of the model need to be computed.

modelGMLVQ

The model instance, containing the prototypes and relevance matrix.

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.