mlpack
Public Types | Public Member Functions | List of all members
mlpack::lmnn::Constraints< MetricType > Class Template Reference

Interface for generating distance based constraints on a given dataset, provided corresponding true labels and a quantity parameter (k) are specified. More...

#include <constraints.hpp>

Public Types

typedef neighbor::NeighborSearch< neighbor::NearestNeighborSort, MetricType > KNN
 Convenience typedef.
 

Public Member Functions

 Constraints (const arma::mat &dataset, const arma::Row< size_t > &labels, const size_t k)
 Constructor for creating a Constraints instance. More...
 
void TargetNeighbors (arma::Mat< size_t > &outputMatrix, const arma::mat &dataset, const arma::Row< size_t > &labels, const arma::vec &norms)
 Calculates k similar labeled nearest neighbors and stores them into the passed matrix. More...
 
void TargetNeighbors (arma::Mat< size_t > &outputMatrix, const arma::mat &dataset, const arma::Row< size_t > &labels, const arma::vec &norms, const size_t begin, const size_t batchSize)
 Calculates k similar labeled nearest neighbors for a batch of dataset and stores them into the passed matrix. More...
 
void Impostors (arma::Mat< size_t > &outputMatrix, const arma::mat &dataset, const arma::Row< size_t > &labels, const arma::vec &norms)
 Calculates k differently labeled nearest neighbors for each datapoint and writes them back to passed matrix. More...
 
void Impostors (arma::Mat< size_t > &outputNeighbors, arma::mat &outputDistance, const arma::mat &dataset, const arma::Row< size_t > &labels, const arma::vec &norms)
 Calculates k differently labeled nearest neighbors & distances to impostors for each datapoint and writes them back to passed matrices. More...
 
void Impostors (arma::Mat< size_t > &outputMatrix, const arma::mat &dataset, const arma::Row< size_t > &labels, const arma::vec &norms, const size_t begin, const size_t batchSize)
 Calculates k differently labeled nearest neighbors for a batch of dataset and writes them back to passed matrix. More...
 
void Impostors (arma::Mat< size_t > &outputNeighbors, arma::mat &outputDistance, const arma::mat &dataset, const arma::Row< size_t > &labels, const arma::vec &norms, const size_t begin, const size_t batchSize)
 Calculates k differently labeled nearest neighbors & distances to impostors for a batch of dataset and writes them back to passed matrices. More...
 
void Impostors (arma::Mat< size_t > &outputNeighbors, arma::mat &outputDistance, const arma::mat &dataset, const arma::Row< size_t > &labels, const arma::vec &norms, const arma::uvec &points, const size_t numPoints)
 Calculates k differently labeled nearest neighbors & distances to impostors for some points of dataset and writes them back to passed matrices. More...
 
void Triplets (arma::Mat< size_t > &outputMatrix, const arma::mat &dataset, const arma::Row< size_t > &labels, const arma::vec &norms)
 Generate triplets {i, j, l} for each datapoint i and writes back generated triplets to matrix passed. More...
 
const size_t & K () const
 Get the number of target neighbors (k).
 
size_t & K ()
 Modify the number of target neighbors (k).
 
const bool & PreCalulated () const
 Access the boolean value of precalculated.
 
bool & PreCalulated ()
 Modify the value of precalculated.
 

Detailed Description

template<typename MetricType = metric::SquaredEuclideanDistance>
class mlpack::lmnn::Constraints< MetricType >

Interface for generating distance based constraints on a given dataset, provided corresponding true labels and a quantity parameter (k) are specified.

Class provides TargetNeighbors() (Used for calculating target neighbors of each data point), Impostors() (used for calculating impostors of each data point) and Triplets() (Generates sets of {dataset, target neighbors, impostors} tripltets.)

Constructor & Destructor Documentation

◆ Constraints()

template<typename MetricType >
mlpack::lmnn::Constraints< MetricType >::Constraints ( const arma::mat &  dataset,
const arma::Row< size_t > &  labels,
const size_t  k 
)

Constructor for creating a Constraints instance.

Parameters
datasetInput dataset.
labelsInput dataset labels.
kNumber of target neighbors, impostors & triplets.

Member Function Documentation

◆ Impostors() [1/5]

template<typename MetricType >
void mlpack::lmnn::Constraints< MetricType >::Impostors ( arma::Mat< size_t > &  outputMatrix,
const arma::mat &  dataset,
const arma::Row< size_t > &  labels,
const arma::vec &  norms 
)

Calculates k differently labeled nearest neighbors for each datapoint and writes them back to passed matrix.

Parameters
outputMatrixCoordinates matrix to store impostors.
datasetInput dataset.
labelsInput dataset labels.
normsInput dataset norms.

◆ Impostors() [2/5]

template<typename MetricType >
void mlpack::lmnn::Constraints< MetricType >::Impostors ( arma::Mat< size_t > &  outputNeighbors,
arma::mat &  outputDistance,
const arma::mat &  dataset,
const arma::Row< size_t > &  labels,
const arma::vec &  norms 
)

Calculates k differently labeled nearest neighbors & distances to impostors for each datapoint and writes them back to passed matrices.

Parameters
outputNeighborsCoordinates matrix to store impostors.
outputDistancematrix to store distance.
datasetInput dataset.
labelsInput dataset labels.
normsInput dataset norms.

◆ Impostors() [3/5]

template<typename MetricType >
void mlpack::lmnn::Constraints< MetricType >::Impostors ( arma::Mat< size_t > &  outputMatrix,
const arma::mat &  dataset,
const arma::Row< size_t > &  labels,
const arma::vec &  norms,
const size_t  begin,
const size_t  batchSize 
)

Calculates k differently labeled nearest neighbors for a batch of dataset and writes them back to passed matrix.

Parameters
outputMatrixCoordinates matrix to store impostors.
datasetInput dataset.
labelsInput dataset labels.
normsInput dataset norms.
beginIndex of the initial point of dataset.
batchSizeNumber of data points to use.

◆ Impostors() [4/5]

template<typename MetricType >
void mlpack::lmnn::Constraints< MetricType >::Impostors ( arma::Mat< size_t > &  outputNeighbors,
arma::mat &  outputDistance,
const arma::mat &  dataset,
const arma::Row< size_t > &  labels,
const arma::vec &  norms,
const size_t  begin,
const size_t  batchSize 
)

Calculates k differently labeled nearest neighbors & distances to impostors for a batch of dataset and writes them back to passed matrices.

Parameters
outputNeighborsCoordinates matrix to store impostors.
outputDistancematrix to store distance.
datasetInput dataset.
labelsInput dataset labels.
normsInput dataset norms.
beginIndex of the initial point of dataset.
batchSizeNumber of data points to use.

◆ Impostors() [5/5]

template<typename MetricType >
void mlpack::lmnn::Constraints< MetricType >::Impostors ( arma::Mat< size_t > &  outputNeighbors,
arma::mat &  outputDistance,
const arma::mat &  dataset,
const arma::Row< size_t > &  labels,
const arma::vec &  norms,
const arma::uvec &  points,
const size_t  numPoints 
)

Calculates k differently labeled nearest neighbors & distances to impostors for some points of dataset and writes them back to passed matrices.

Parameters
outputNeighborsCoordinates matrix to store impostors.
outputDistancematrix to store distance.
datasetInput dataset.
labelsInput dataset labels.
normsInput dataset norms.
pointsIndices of data points to calculate impostors on.
numPointsNumber of points to actually calculate impostors on.

◆ TargetNeighbors() [1/2]

template<typename MetricType >
void mlpack::lmnn::Constraints< MetricType >::TargetNeighbors ( arma::Mat< size_t > &  outputMatrix,
const arma::mat &  dataset,
const arma::Row< size_t > &  labels,
const arma::vec &  norms 
)

Calculates k similar labeled nearest neighbors and stores them into the passed matrix.

Parameters
outputMatrixCoordinates matrix to store target neighbors.
datasetInput dataset.
labelsInput dataset labels.
normsInput dataset norms.

◆ TargetNeighbors() [2/2]

template<typename MetricType >
void mlpack::lmnn::Constraints< MetricType >::TargetNeighbors ( arma::Mat< size_t > &  outputMatrix,
const arma::mat &  dataset,
const arma::Row< size_t > &  labels,
const arma::vec &  norms,
const size_t  begin,
const size_t  batchSize 
)

Calculates k similar labeled nearest neighbors for a batch of dataset and stores them into the passed matrix.

Parameters
outputMatrixCoordinates matrix to store target neighbors.
datasetInput dataset.
labelsInput dataset labels.
normsInput dataset norms.
beginIndex of the initial point of dataset.
batchSizeNumber of data points to use.

◆ Triplets()

template<typename MetricType >
void mlpack::lmnn::Constraints< MetricType >::Triplets ( arma::Mat< size_t > &  outputMatrix,
const arma::mat &  dataset,
const arma::Row< size_t > &  labels,
const arma::vec &  norms 
)

Generate triplets {i, j, l} for each datapoint i and writes back generated triplets to matrix passed.

Parameters
outputMatrixCoordinates matrix to store triplets.
datasetInput dataset.
labelsInput dataset labels.
normsInput dataset norms.

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