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 (\mathbf{x}):

\mu(\mathbf{x}) = \frac{d(\mathbf{x}, \mathbf{w}_1) - d(\mathbf{x}, \mathbf{w}_0)}{d(
\mathbf{x}, \mathbf{w}_1) + d(\mathbf{x}, \mathbf{w}_0)},

with \mathbf{w}_1 the prototype with the same label and \mathbf{w}_0 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.

gradient(dist_same: numpy.ndarray, dist_diff: numpy.ndarray, same_label: bool)numpy.ndarray[source]

Computes the relative distance discriminant function’s gradient.

  1. The partial derivative with respect to the closest prototypes with the same label (same_label=True):

\frac{\partial \mu}{\partial \mathbf{w}_1} = \frac{2 \cdot d(\mathbf{x},
\mathbf{w}_0))}{(d(\mathbf{x}, \mathbf{w}_1) + d(\mathbf{x}, \mathbf{w}_0))^2}.

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

\frac{\partial \mu}{\partial \mathbf{w}_0} = \frac{-2 \cdot d(\mathbf{x},
\mathbf{w}_1))}{(d(\mathbf{x}, \mathbf{w}_1) + d(\mathbf{x}, \mathbf{w}_0))^2},

with d(\mathbf{x}, \mathbf{w}_1) the distance to the prototype with the same label and d(\mathbf{x}, \mathbf{w}_0) 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.