sklvq.distances.DistanceBaseClass

class sklvq.distances.DistanceBaseClass[source]

Distance base class

Abstract class for implementing distance functions. It provides abstract methods with expected call signatures.

Custom distance function ‘__init__’ should accept any parameters as key-value pairs.

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

Should implement a distance function.

Parameters
datandarray with shape (n_samples, n_features)

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

modelLVQBaseClass

Any class extending the LVQBaseClass or depending on the type of distance function is implemented a class that provides the required attributes.

Returns
ndarray with shape (n_samples, n_prototypes)

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

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

The distance gradient method.

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.

modelLVQBaseClass

Any class extending the LVQBaseClass or depending on the type of distance function is implemented, a class that provides the required attributes.

i_prototypeint

The index of the prototype for which the gradient needs to be computed.

Returns
ndarray with shape (n_samples, n_features)

The gradient with respect to the prototype (i_prototype) and every sample in X.

Examples using sklvq.distances.DistanceBaseClass