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
GMLVQalgorithm (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:

with the relevance matrix
, the prototype
, and 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.
- 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:

and the omega matrix (per element):

- 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.