sklvq.objectives.GeneralizedLearningObjective
- class sklvq.objectives.GeneralizedLearningObjective(activation_type: str | type, activation_params: dict, discriminant_type: 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, andLGMLVQ.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: np.ndarray, labels: np.ndarray) np.ndarray[source]
Computes the generalized learning objective:

with
the discriminative function,
the activation
function, and
and
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: np.ndarray, labels: np.ndarray) np.ndarray[source]
Computes the generalized learning objective’s gradient with respect to the prototype with a different label:

with
the prototype with a different label than the data and
the distance to that prototype.
with
the prototype with the same label as the data and
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