mlpack
master
|
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 TraversalInfoType & | TraversalInfo () const |
TraversalInfoType & | TraversalInfo () |
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< CandidateList > | candidates |
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 |
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.
KernelType | Type of kernel to run FastMKS with. |
TreeType | Type of tree to run FastMKS with; it must satisfy the TreeType policy API. |
Definition at line 34 of file fastmks_rules.hpp.
|
private |
Candidate represents a possible candidate point (value, index).
Definition at line 134 of file fastmks_rules.hpp.
|
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.
typedef tree::TraversalInfo<TreeType> mlpack::fastmks::FastMKSRules< KernelType, TreeType >::TraversalInfoType |
Definition at line 122 of file fastmks_rules.hpp.
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.
referenceSet | Set of reference data. |
querySet | Set of query data. |
k | Number of candidates to search for. |
kernel | Kernel to run FastMKS with. |
double mlpack::fastmks::FastMKSRules< KernelType, TreeType >::BaseCase | ( | const size_t | queryIndex, |
const size_t | referenceIndex | ||
) |
Compute the base case (kernel value) between two points.
|
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.
|
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.
|
private |
Calculate the bound for a given query node.
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.
indices | Matrix storing lists of candidate for each query point. |
products | Matrix storing kernel value for each candidate. |
|
private |
Helper function to insert a point into the list of candidate points.
queryIndex | Index of point whose neighbors we are inserting into. |
index | Index of reference point which is being inserted. |
product | Kernel value for given candidate. |
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.
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.
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).
queryIndex | Index of query point. |
referenceNode | Candidate to be recursed into. |
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).
queryNode | Candidate query node to be recursed into. |
referenceNode | Candidate reference node to be recursed into. |
|
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.
|
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.
|
inline |
Definition at line 124 of file fastmks_rules.hpp.
References mlpack::fastmks::FastMKSRules< KernelType, TreeType >::traversalInfo.
|
inline |
Definition at line 125 of file fastmks_rules.hpp.
References mlpack::fastmks::FastMKSRules< KernelType, TreeType >::traversalInfo.
|
private |
For benchmarking.
Definition at line 187 of file fastmks_rules.hpp.
Referenced by mlpack::fastmks::FastMKSRules< KernelType, TreeType >::BaseCases().
|
private |
Set of candidates for each point.
Definition at line 152 of file fastmks_rules.hpp.
|
private |
Number of points to search for.
Definition at line 155 of file fastmks_rules.hpp.
|
private |
The instantiated kernel.
Definition at line 163 of file fastmks_rules.hpp.
|
private |
The last kernel evaluation resulting from BaseCase().
Definition at line 170 of file fastmks_rules.hpp.
|
private |
The last query index BaseCase() was called with.
Definition at line 166 of file fastmks_rules.hpp.
|
private |
The last reference index BaseCase() was called with.
Definition at line 168 of file fastmks_rules.hpp.
|
private |
Cached query set self-kernels (|| q || for each q).
Definition at line 158 of file fastmks_rules.hpp.
|
private |
The query dataset.
Definition at line 131 of file fastmks_rules.hpp.
|
private |
Cached reference set self-kernels (|| r || for each r).
Definition at line 160 of file fastmks_rules.hpp.
|
private |
The reference dataset.
Definition at line 129 of file fastmks_rules.hpp.
|
private |
For benchmarking.
Definition at line 189 of file fastmks_rules.hpp.
Referenced by mlpack::fastmks::FastMKSRules< KernelType, TreeType >::Scores().
|
private |
Definition at line 191 of file fastmks_rules.hpp.
Referenced by mlpack::fastmks::FastMKSRules< KernelType, TreeType >::TraversalInfo().