mlpack  2.2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
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 i)
 Evaluate the softmax objective function for the given covariance matrix on only one 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...
 
void Gradient (const arma::mat &covariance, const size_t i, arma::mat &gradient)
 Evaluate the gradient of the softmax function for the given covariance matrix on only one point of the dataset. More...
 
size_t NumFunctions () const
 Get the number of functions the objective function can be decomposed into. 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 42 of file nca_softmax_error_function.hpp.

Constructor & Destructor Documentation

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

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.
double Evaluate ( const arma::mat &  covariance,
const size_t  i 
)

Evaluate the softmax objective function for the given covariance matrix on only one 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.
iIndex of point 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.

Parameters
covarianceCovariance matrix of Mahalanobis distance.
gradientMatrix to store the calculated gradient in.
void Gradient ( const arma::mat &  covariance,
const size_t  i,
arma::mat &  gradient 
)

Evaluate the gradient of the softmax function for the given covariance matrix on only one 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.
iIndex of point to use for objective function.
gradientMatrix to store the calculated gradient in.
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 114 of file nca_softmax_error_function.hpp.


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