mlpack  master
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
mlpack::fastmks::FastMKSRules< KernelType, TreeType > Class Template Reference

The FastMKSRules class is a template helper class used by FastMKS class when performing exact max-kernel search. More...

Classes

struct  CandidateCmp
 Compare two candidates based on the value. More...
 

Public Types

typedef tree::TraversalInfo< TreeType > TraversalInfoType
 

Public Member Functions

 FastMKSRules (const typename TreeType::Mat &referenceSet, const typename TreeType::Mat &querySet, const size_t k, KernelType &kernel)
 Construct the FastMKSRules object. More...
 
double BaseCase (const size_t queryIndex, const size_t referenceIndex)
 Compute the base case (kernel value) between two points. More...
 
size_t BaseCases () const
 Get the number of times BaseCase() was called. More...
 
size_t & BaseCases ()
 Modify the number of times BaseCase() was called. More...
 
void GetResults (arma::Mat< size_t > &indices, arma::mat &products)
 Store the list of candidates for each query point in the given matrices. More...
 
double Rescore (const size_t queryIndex, TreeType &referenceNode, const double oldScore) const
 Re-evaluate the score for recursion order. More...
 
double Rescore (TreeType &queryNode, TreeType &referenceNode, const double oldScore) const
 Re-evaluate the score for recursion order. More...
 
double Score (const size_t queryIndex, TreeType &referenceNode)
 Get the score for recursion order. More...
 
double Score (TreeType &queryNode, TreeType &referenceNode)
 Get the score for recursion order. More...
 
size_t Scores () const
 Get the number of times Score() was called. More...
 
size_t & Scores ()
 Modify the number of times Score() was called. More...
 
const TraversalInfoTypeTraversalInfo () const
 
TraversalInfoTypeTraversalInfo ()
 

Private Types

typedef std::pair< double, size_t > Candidate
 Candidate represents a possible candidate point (value, index). More...
 
typedef boost::heap::priority_queue< Candidate, boost::heap::compare< CandidateCmp > > CandidateList
 Use a min heap to represent the list of candidate points. More...
 

Private Member Functions

double CalculateBound (TreeType &queryNode) const
 Calculate the bound for a given query node. More...
 
void InsertNeighbor (const size_t queryIndex, const size_t index, const double product)
 Helper function to insert a point into the list of candidate points. More...
 

Private Attributes

size_t baseCases
 For benchmarking. More...
 
std::vector< CandidateListcandidates
 Set of candidates for each point. More...
 
const size_t k
 Number of points to search for. More...
 
KernelType & kernel
 The instantiated kernel. More...
 
double lastKernel
 The last kernel evaluation resulting from BaseCase(). More...
 
size_t lastQueryIndex
 The last query index BaseCase() was called with. More...
 
size_t lastReferenceIndex
 The last reference index BaseCase() was called with. More...
 
arma::vec queryKernels
 Cached query set self-kernels (|| q || for each q). More...
 
const TreeType::Mat & querySet
 The query dataset. More...
 
arma::vec referenceKernels
 Cached reference set self-kernels (|| r || for each r). More...
 
const TreeType::Mat & referenceSet
 The reference dataset. More...
 
size_t scores
 For benchmarking. More...
 
TraversalInfoType traversalInfo
 

Detailed Description

template<typename KernelType, typename TreeType>
class mlpack::fastmks::FastMKSRules< KernelType, TreeType >

The FastMKSRules class is a template helper class used by FastMKS class when performing exact max-kernel search.

For each point in the query dataset, it keeps track of the k best candidates in the reference dataset.

Template Parameters
KernelTypeType of kernel to run FastMKS with.
TreeTypeType of tree to run FastMKS with; it must satisfy the TreeType policy API.

Definition at line 34 of file fastmks_rules.hpp.

Member Typedef Documentation

template<typename KernelType , typename TreeType >
typedef std::pair<double, size_t> mlpack::fastmks::FastMKSRules< KernelType, TreeType >::Candidate
private

Candidate represents a possible candidate point (value, index).

Definition at line 134 of file fastmks_rules.hpp.

template<typename KernelType , typename TreeType >
typedef boost::heap::priority_queue<Candidate, boost::heap::compare<CandidateCmp> > mlpack::fastmks::FastMKSRules< KernelType, TreeType >::CandidateList
private

Use a min heap to represent the list of candidate points.

We will use a boost::heap::priority_queue instead of a std::priority_queue because we need to iterate over all the candidates and std::priority_queue doesn't provide that interface.

Definition at line 149 of file fastmks_rules.hpp.

template<typename KernelType , typename TreeType >
typedef tree::TraversalInfo<TreeType> mlpack::fastmks::FastMKSRules< KernelType, TreeType >::TraversalInfoType

Definition at line 122 of file fastmks_rules.hpp.

Constructor & Destructor Documentation

template<typename KernelType , typename TreeType >
mlpack::fastmks::FastMKSRules< KernelType, TreeType >::FastMKSRules ( const typename TreeType::Mat &  referenceSet,
const typename TreeType::Mat &  querySet,
const size_t  k,
KernelType &  kernel 
)

Construct the FastMKSRules object.

This is usually done from within the FastMKS class at search time.

Parameters
referenceSetSet of reference data.
querySetSet of query data.
kNumber of candidates to search for.
kernelKernel to run FastMKS with.

Member Function Documentation

template<typename KernelType , typename TreeType >
double mlpack::fastmks::FastMKSRules< KernelType, TreeType >::BaseCase ( const size_t  queryIndex,
const size_t  referenceIndex 
)

Compute the base case (kernel value) between two points.

template<typename KernelType , typename TreeType >
size_t mlpack::fastmks::FastMKSRules< KernelType, TreeType >::BaseCases ( ) const
inline

Get the number of times BaseCase() was called.

Definition at line 113 of file fastmks_rules.hpp.

References mlpack::fastmks::FastMKSRules< KernelType, TreeType >::baseCases.

template<typename KernelType , typename TreeType >
size_t& mlpack::fastmks::FastMKSRules< KernelType, TreeType >::BaseCases ( )
inline

Modify the number of times BaseCase() was called.

Definition at line 115 of file fastmks_rules.hpp.

References mlpack::fastmks::FastMKSRules< KernelType, TreeType >::baseCases.

template<typename KernelType , typename TreeType >
double mlpack::fastmks::FastMKSRules< KernelType, TreeType >::CalculateBound ( TreeType &  queryNode) const
private

Calculate the bound for a given query node.

template<typename KernelType , typename TreeType >
void mlpack::fastmks::FastMKSRules< KernelType, TreeType >::GetResults ( arma::Mat< size_t > &  indices,
arma::mat &  products 
)

Store the list of candidates for each query point in the given matrices.

Parameters
indicesMatrix storing lists of candidate for each query point.
productsMatrix storing kernel value for each candidate.
template<typename KernelType , typename TreeType >
void mlpack::fastmks::FastMKSRules< KernelType, TreeType >::InsertNeighbor ( const size_t  queryIndex,
const size_t  index,
const double  product 
)
private

Helper function to insert a point into the list of candidate points.

Parameters
queryIndexIndex of point whose neighbors we are inserting into.
indexIndex of reference point which is being inserted.
productKernel value for given candidate.
template<typename KernelType , typename TreeType >
double mlpack::fastmks::FastMKSRules< KernelType, TreeType >::Rescore ( const size_t  queryIndex,
TreeType &  referenceNode,
const double  oldScore 
) const

Re-evaluate the score for recursion order.

A low score indicates priority for recursion, while DBL_MAX indicates that a node should not be recursed into at all (it should be pruned). This is used when the score has already been calculated, but another recursion may have modified the bounds for pruning. So the old score is checked against the new pruning bound.

Parameters
queryIndexIndex of query point.
referenceNodeCandidate node to be recursed into.
oldScoreOld score produced by Score() (or Rescore()).
template<typename KernelType , typename TreeType >
double mlpack::fastmks::FastMKSRules< KernelType, TreeType >::Rescore ( TreeType &  queryNode,
TreeType &  referenceNode,
const double  oldScore 
) const

Re-evaluate the score for recursion order.

A low score indicates priority for recursion, while DBL_MAX indicates that a node should not be recursed into at all (it should be pruned). This is used when the score has already been calculated, but another recursion may have modified the bounds for pruning. So the old score is checked against the new pruning bound.

Parameters
queryNodeCandidate query node to be recursed into.
referenceNodeCandidate reference node to be recursed into.
oldScoreOld score produced by Score() (or Rescore()).
template<typename KernelType , typename TreeType >
double mlpack::fastmks::FastMKSRules< KernelType, TreeType >::Score ( const size_t  queryIndex,
TreeType &  referenceNode 
)

Get the score for recursion order.

A low score indicates priority for recursion, while DBL_MAX indicates that the node should not be recursed into at all (it should be pruned).

Parameters
queryIndexIndex of query point.
referenceNodeCandidate to be recursed into.
template<typename KernelType , typename TreeType >
double mlpack::fastmks::FastMKSRules< KernelType, TreeType >::Score ( TreeType &  queryNode,
TreeType &  referenceNode 
)

Get the score for recursion order.

A low score indicates priority for recursion, while DBL_MAX indicates that the node should not be recursed into at all (it should be pruned).

Parameters
queryNodeCandidate query node to be recursed into.
referenceNodeCandidate reference node to be recursed into.
template<typename KernelType , typename TreeType >
size_t mlpack::fastmks::FastMKSRules< KernelType, TreeType >::Scores ( ) const
inline

Get the number of times Score() was called.

Definition at line 118 of file fastmks_rules.hpp.

References mlpack::fastmks::FastMKSRules< KernelType, TreeType >::scores.

template<typename KernelType , typename TreeType >
size_t& mlpack::fastmks::FastMKSRules< KernelType, TreeType >::Scores ( )
inline

Modify the number of times Score() was called.

Definition at line 120 of file fastmks_rules.hpp.

References mlpack::fastmks::FastMKSRules< KernelType, TreeType >::scores.

template<typename KernelType , typename TreeType >
const TraversalInfoType& mlpack::fastmks::FastMKSRules< KernelType, TreeType >::TraversalInfo ( ) const
inline
template<typename KernelType , typename TreeType >
TraversalInfoType& mlpack::fastmks::FastMKSRules< KernelType, TreeType >::TraversalInfo ( )
inline

Member Data Documentation

template<typename KernelType , typename TreeType >
size_t mlpack::fastmks::FastMKSRules< KernelType, TreeType >::baseCases
private

For benchmarking.

Definition at line 187 of file fastmks_rules.hpp.

Referenced by mlpack::fastmks::FastMKSRules< KernelType, TreeType >::BaseCases().

template<typename KernelType , typename TreeType >
std::vector<CandidateList> mlpack::fastmks::FastMKSRules< KernelType, TreeType >::candidates
private

Set of candidates for each point.

Definition at line 152 of file fastmks_rules.hpp.

template<typename KernelType , typename TreeType >
const size_t mlpack::fastmks::FastMKSRules< KernelType, TreeType >::k
private

Number of points to search for.

Definition at line 155 of file fastmks_rules.hpp.

template<typename KernelType , typename TreeType >
KernelType& mlpack::fastmks::FastMKSRules< KernelType, TreeType >::kernel
private

The instantiated kernel.

Definition at line 163 of file fastmks_rules.hpp.

template<typename KernelType , typename TreeType >
double mlpack::fastmks::FastMKSRules< KernelType, TreeType >::lastKernel
private

The last kernel evaluation resulting from BaseCase().

Definition at line 170 of file fastmks_rules.hpp.

template<typename KernelType , typename TreeType >
size_t mlpack::fastmks::FastMKSRules< KernelType, TreeType >::lastQueryIndex
private

The last query index BaseCase() was called with.

Definition at line 166 of file fastmks_rules.hpp.

template<typename KernelType , typename TreeType >
size_t mlpack::fastmks::FastMKSRules< KernelType, TreeType >::lastReferenceIndex
private

The last reference index BaseCase() was called with.

Definition at line 168 of file fastmks_rules.hpp.

template<typename KernelType , typename TreeType >
arma::vec mlpack::fastmks::FastMKSRules< KernelType, TreeType >::queryKernels
private

Cached query set self-kernels (|| q || for each q).

Definition at line 158 of file fastmks_rules.hpp.

template<typename KernelType , typename TreeType >
const TreeType::Mat& mlpack::fastmks::FastMKSRules< KernelType, TreeType >::querySet
private

The query dataset.

Definition at line 131 of file fastmks_rules.hpp.

template<typename KernelType , typename TreeType >
arma::vec mlpack::fastmks::FastMKSRules< KernelType, TreeType >::referenceKernels
private

Cached reference set self-kernels (|| r || for each r).

Definition at line 160 of file fastmks_rules.hpp.

template<typename KernelType , typename TreeType >
const TreeType::Mat& mlpack::fastmks::FastMKSRules< KernelType, TreeType >::referenceSet
private

The reference dataset.

Definition at line 129 of file fastmks_rules.hpp.

template<typename KernelType , typename TreeType >
size_t mlpack::fastmks::FastMKSRules< KernelType, TreeType >::scores
private

For benchmarking.

Definition at line 189 of file fastmks_rules.hpp.

Referenced by mlpack::fastmks::FastMKSRules< KernelType, TreeType >::Scores().

template<typename KernelType , typename TreeType >
TraversalInfoType mlpack::fastmks::FastMKSRules< KernelType, TreeType >::traversalInfo
private

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