SoftmaxErrorFunction< MetricType > Class Template Reference

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...

 

Detailed Description


template
<
typename
MetricType
=
metric::SquaredEuclideanDistance
>

class mlpack::nca::SoftmaxErrorFunction< MetricType >

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 43 of file nca_softmax_error_function.hpp.

Constructor & Destructor Documentation

◆ SoftmaxErrorFunction()

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.

Parameters
datasetMatrix containing the dataset.
labelsVector of class labels for each point in the dataset.
kernelInstantiated kernel (optional).

Member Function Documentation

◆ Evaluate() [1/2]

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.

Parameters
covarianceCovariance matrix of Mahalanobis distance.

◆ Evaluate() [2/2]

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.

Parameters
covarianceCovariance matrix of Mahalanobis distance.
beginIndex of the initial point to use for objective function.
batchSizeNumber of points to use for objective function.

◆ GetInitialPoint()

const arma::mat GetInitialPoint ( ) const

Get the initial point.

◆ Gradient() [1/2]

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.

Parameters
covarianceCovariance matrix of Mahalanobis distance.
gradientMatrix to store the calculated gradient in.

◆ Gradient() [2/2]

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.

Template Parameters
GradTypeThe type of the gradient out-param.
Parameters
covarianceCovariance matrix of Mahalanobis distance.
beginIndex of the initial point to use for objective function.
batchSizeNumber of points to use for objective function.
gradientMatrix to store the calculated gradient in.

◆ NumFunctions()

size_t NumFunctions ( ) const
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 130 of file nca_softmax_error_function.hpp.

◆ Shuffle()

void Shuffle ( )

Shuffle the dataset.


The documentation for this class was generated from the following file: