sklvq.discriminants.RelativeDistance¶
-
class
sklvq.discriminants.RelativeDistance[source]¶ Relative distance function
Class that holds the relative distance function and gradient as described in [1].
References
[1] Sato, A., and Yamada, K. (1996) “Generalized Learning Vector Quantization.” Advances in Neural Network Information Processing Systems, 423–429, 1996.
-
__call__(dist_same: numpy.ndarray, dist_diff: numpy.ndarray) → numpy.ndarray[source]¶ - The relative distance discriminant function for a single sample (
): 
with
the prototype with the same label and
the
prototype with a different label.- Parameters
- dist_samendarray with shape (n_samples, 1), with n_samples >= 1
Shortest distance of n_samples to a prototype with the same label.
- dist_diffndarray with shape (n_samples, 1), with n_samples >= 1
Shortest distance of n_samples to a prototype with a different label.
- Returns
- ndarray with shape (n_samples, 1)
Evaluation of the relative distance discriminative function.
- The relative distance discriminant function for a single sample (
-
gradient(dist_same: numpy.ndarray, dist_diff: numpy.ndarray, same_label: bool) → numpy.ndarray[source]¶ Computes the relative distance discriminant function’s gradient.
The partial derivative with respect to the closest prototypes with the same label (same_label=True):

The partial derivative with respect to the closest prototypes with a different label (same_label=False):

with
the distance to the prototype with the same label
and
the distance to the closest prototype with a
different label.- Parameters
- dist_samendarray with shape (n_samples, 1), with n_samples >= 1
Shortest distance of n_samples to a prototype with the same label.
- dist_diffndarray with shape (n_samples, 1), with n_samples >= 1
Shortest distance of n_samples to a prototype with a different label.
- same_labelbool
Indicating if the derivative with respect to a prototype with the same label (True) or a different label (False) needs to be calculated.
- Returns
- ndarray with shape (n_samples, 1)
Evaluation of the relative distance function’s gradient.
-