The "softmax" stochastic neighbor assignment probability function. More...
Public Member Functions | |
SoftmaxErrorFunction (const arma::mat &dataset, const arma::Row< size_t > &labels, MetricType metric=MetricType()) | |
Initialize with the given kernel; useful when the kernel has some state to store, which is set elsewhere. More... | |
double | Evaluate (const arma::mat &covariance) |
Evaluate the softmax function for the given covariance matrix. More... | |
double | Evaluate (const arma::mat &covariance, const size_t begin, const size_t batchSize=1) |
Evaluate the softmax objective function for the given covariance matrix on the given batch size from a given inital point of the dataset. More... | |
const arma::mat | GetInitialPoint () const |
Get the initial point. More... | |
void | Gradient (const arma::mat &covariance, arma::mat &gradient) |
Evaluate the gradient of the softmax function for the given covariance matrix. More... | |
template < typename GradType > | |
void | Gradient (const arma::mat &covariance, const size_t begin, GradType &gradient, const size_t batchSize=1) |
Evaluate the gradient of the softmax function for the given covariance matrix on the given batch size, from a given initial point of the dataset. More... | |
size_t | NumFunctions () const |
Get the number of functions the objective function can be decomposed into. More... | |
void | Shuffle () |
Shuffle the dataset. More... | |
The "softmax" stochastic neighbor assignment probability function.
The actual function is
p_ij = (exp(-|| A x_i - A x_j || ^ 2)) / (sum_{k != i} (exp(-|| A x_i - A x_k || ^ 2)))
where x_n represents a point and A is the current scaling matrix.
This class is more flexible than the original paper, allowing an arbitrary metric function to be used in place of || A x_i - A x_j ||^2, meaning that the squared Euclidean distance is not the only allowed metric for NCA. However, that is probably the best way to use this class.
In addition to the standard Evaluate() and Gradient() functions which mlpack optimizers use, overloads of Evaluate() and Gradient() are given which only operate on one point in the dataset. This is useful for optimizers like stochastic gradient descent (see mlpack::optimization::SGD).
Definition at line 45 of file nca_softmax_error_function.hpp.
SoftmaxErrorFunction | ( | const arma::mat & | dataset, |
const arma::Row< size_t > & | labels, | ||
MetricType | metric = MetricType() |
||
) |
Initialize with the given kernel; useful when the kernel has some state to store, which is set elsewhere.
If no kernel is given, an empty kernel is used; this way, you can call the constructor with no arguments. A reference to the dataset we will be optimizing over is also required.
dataset | Matrix containing the dataset. |
labels | Vector of class labels for each point in the dataset. |
metric | Instantiated metric (optional). |
double Evaluate | ( | const arma::mat & | covariance | ) |
Evaluate the softmax function for the given covariance matrix.
This is the non-separable implementation, where the objective function is not decomposed into the sum of several objective functions.
covariance | Covariance matrix of Mahalanobis distance. |
double Evaluate | ( | const arma::mat & | covariance, |
const size_t | begin, | ||
const size_t | batchSize = 1 |
||
) |
Evaluate the softmax objective function for the given covariance matrix on the given batch size from a given inital point of the dataset.
This is the separable implementation, where the objective function is decomposed into the sum of many objective functions, and here, only one of those constituent objective functions is returned.
covariance | Covariance matrix of Mahalanobis distance. |
begin | Index of the initial point to use for objective function. |
batchSize | Number of points to use for objective function. |
const arma::mat GetInitialPoint | ( | ) | const |
Get the initial point.
void Gradient | ( | const arma::mat & | covariance, |
arma::mat & | gradient | ||
) |
Evaluate the gradient of the softmax function for the given covariance matrix.
This is the non-separable implementation, where the objective function is not decomposed into the sum of several objective functions.
covariance | Covariance matrix of Mahalanobis distance. |
gradient | Matrix to store the calculated gradient in. |
void Gradient | ( | const arma::mat & | covariance, |
const size_t | begin, | ||
GradType & | gradient, | ||
const size_t | batchSize = 1 |
||
) |
Evaluate the gradient of the softmax function for the given covariance matrix on the given batch size, from a given initial point of the dataset.
This is the separable implementation, where the objective function is decomposed into the sum of many objective functions, and here, only one of those constituent objective functions is returned. The type of the gradient parameter is a template argument to allow the computation of a sparse gradient.
GradType | The type of the gradient out-param. |
covariance | Covariance matrix of Mahalanobis distance. |
begin | Index of the initial point to use for objective function. |
batchSize | Number of points to use for objective function. |
gradient | Matrix to store the calculated gradient in. |
|
inline |
Get the number of functions the objective function can be decomposed into.
This is just the number of points in the dataset.
Definition at line 132 of file nca_softmax_error_function.hpp.
void Shuffle | ( | ) |
Shuffle the dataset.