sklvq.objectives.GeneralizedLearningObjective

class sklvq.objectives.GeneralizedLearningObjective(activation_type: Union[str, type], activation_params: dict, discriminant_type: Union[str, type], discriminant_params: dict)[source]

Generalized learning objective

Class that holds the generalized learning objective function and its gradient as described in [1].

Parameters
activation_type{“identity”, “sigmoid”, “soft-plus”, “swish”} or type

If string needs to be one of the indicated options. If not a string needs to be a custom activation class. See sklvq.activations.ActivationBaseClass.

activation_paramsdict or None

The dictionary with the parameters for the activation function or None if it doesn’t require any parameters.

discriminant_type: {“relative-distance”} or type

Can only be the relative distance. If not a string it can be a custom class. See sklvq.discriminants.DiscriminantBaseClass.

discriminant_paramsdict or None

The dictionary with the parameters for the discriminant function or None if it doesn’t require any parameters.

Notes

Compatible and used within the following models: GLVQ, GMLVQ, and LGMLVQ.

References

[1] Sato, A., and Yamada, K. (1996) “Generalized Learning Vector Quantization.” Advances in Neural Network Information Processing Systems, 423–429, 1996.

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

Computes the generalized learning objective:

E = \sum_{i=1}^{N} f(\mu(d_0(\mathbf{x}_i), d_1(\mathbf{x}_i))

with \mu(\cdot) the discriminative function, f(\cdot) the activation function, and d_0(\mathbf{x}_i) and d_1(\mathbf{x}_i) the shortest distance to a prototype with a different and the same label respectively.

Parameters
modelLVQBaseClass

The model which can be any LVQBaseClass compatible with this objective function.

data: ndarray with shape (n_samples, n_features)

The data.

labels: ndarray with shape (n_samples)

The labels of the samples in the data.

Returns
float:

The cost

gradient(model: LVQBaseClass, data: numpy.ndarray, labels: numpy.ndarray)numpy.ndarray[source]

Computes the generalized learning objective’s gradient with respect to the prototype with a different label:

\frac{\partial E}{\partial \mathbf{w}_0} = \frac{\partial f}{\partial \mu}
\frac{\partial \mu}{\partial d_0} \frac{\partial d_0}{\partial \mathbf{w}_0}

with \mathbf{w}_0 the prototype with a different label than the data and d_0 the distance to that prototype.

\frac{\partial E}{\partial \mathbf{w}_1} = \frac{\partial f}{\partial \mu}
\frac{\partial \mu}{\partial d_1} \frac{\partial d_1}{\partial \mathbf{w}_1}

with \mathbf{w}_1 the prototype with the same label as the data and d_1 the distance to that prototype.

Parameters
modelLVQBaseClass

The model which can be any LVQBaseClass compatible with this objective function.

data: ndarray with shape (n_samples, n_features)

The data.

labels: ndarray with shape (n_samples)

The labels of the samples in the data.

Returns
ndarray with the same shape as the model variables array (depending on the model)

The generalized learning objective function’s gradient