An implementation of fast exact maxkernel search. More...
Public Types  
typedef TreeType< metric::IPMetric< KernelType >, FastMKSStat, MatType >  Tree 
Convenience typedef. More...  
Public Member Functions  
FastMKS (const bool singleMode=false, const bool naive=false)  
Create the FastMKS object with an empty reference set and default kernel. More...  
FastMKS (const MatType &referenceSet, const bool singleMode=false, const bool naive=false)  
Create the FastMKS object with the given reference set (this is the set that is searched). More...  
FastMKS (const MatType &referenceSet, KernelType &kernel, const bool singleMode=false, const bool naive=false)  
Create the FastMKS object using the reference set (this is the set that is searched) with an initialized kernel. More...  
FastMKS (MatType &&referenceSet, const bool singleMode=false, const bool naive=false)  
Create the FastMKS object with the given reference set (this is the set that is searched), taking ownership of the reference set. More...  
FastMKS (MatType &&referenceSet, KernelType &kernel, const bool singleMode=false, const bool naive=false)  
Create the FastMKS object using the reference set (this is the set that is searched) with an initialized kernel, taking ownership of the reference set. More...  
FastMKS (Tree *referenceTree, const bool singleMode=false)  
Create the FastMKS object with an alreadyinitialized tree built on the reference points. More...  
FastMKS (const FastMKS &other)  
Copy the parameters of the given model. More...  
FastMKS (FastMKS &&other)  
Take ownership of the given model. More...  
~FastMKS ()  
Destructor for the FastMKS object. More...  
const metric::IPMetric< KernelType > &  Metric () const 
Get the innerproduct metric induced by the given kernel. More...  
metric::IPMetric< KernelType > &  Metric () 
Modify the innerproduct metric induced by the given kernel. More...  
bool  Naive () const 
Get whether or not bruteforce (naive) search is used. More...  
bool &  Naive () 
Modify whether or not bruteforce (naive) search is used. More...  
FastMKS &  operator= (const FastMKS &other) 
Assign this model to be a copy of the given model. More...  
void  Search (const MatType &querySet, const size_t k, arma::Mat< size_t > &indices, arma::mat &kernels) 
Search for the points in the reference set with maximum kernel evaluation to each point in the given query set. More...  
void  Search (Tree *querySet, const size_t k, arma::Mat< size_t > &indices, arma::mat &kernels) 
Search for the points in the reference set with maximum kernel evaluation to each point in the query set corresponding to the given prebuilt query tree. More...  
void  Search (const size_t k, arma::Mat< size_t > &indices, arma::mat &products) 
Search for the maximum inner products of the query set (or if no query set was passed, the reference set is used). More...  
template < typename Archive >  
void  serialize (Archive &ar, const unsigned int) 
Serialize the model. More...  
bool  SingleMode () const 
Get whether or not singletree search is used. More...  
bool &  SingleMode () 
Modify whether or not singletree search is used. More...  
void  Train (const MatType &referenceSet) 
"Train" the FastMKS model on the given reference set (this will just build a tree, if the current search mode is not naive mode). More...  
void  Train (const MatType &referenceSet, KernelType &kernel) 
"Train" the FastMKS model on the given reference set and use the given kernel. More...  
void  Train (MatType &&referenceSet) 
"Train" the FastMKS model on the given reference set (this will just build a tree, if the current search mode is not naive mode). More...  
void  Train (MatType &&referenceSet, KernelType &kernel) 
"Train" the FastMKS model on the given reference set and use the given kernel. More...  
void  Train (Tree *referenceTree) 
Train the FastMKS model on the given reference tree. More...  
An implementation of fast exact maxkernel search.
Given a query dataset and a reference dataset (or optionally just a reference dataset which is also used as the query dataset), fast exact maxkernel search finds, for each point in the query dataset, the k points in the reference set with maximum kernel value K(p_q, p_r), where k is a specified parameter and K() is a Mercer kernel.
For more information, see the following paper.
This class allows specification of the type of kernel and also of the type of tree. FastMKS can be run on kernels that work on arbitrary objects – however, this only works with cover trees and other trees that are built only on points in the dataset (and not centroids of regions or anything like that).
KernelType  Type of kernel to run FastMKS with. 
MatType  Type of data matrix (usually arma::mat). 
TreeType  Type of tree to run FastMKS with; it must satisfy the TreeType policy API. 
Definition at line 63 of file fastmks.hpp.
typedef TreeType<metric::IPMetric<KernelType>, FastMKSStat, MatType> Tree 
Convenience typedef.
Definition at line 67 of file fastmks.hpp.
FastMKS  (  const bool  singleMode = false , 
const bool  naive = false 

) 
FastMKS  (  const MatType &  referenceSet, 
const bool  singleMode = false , 

const bool  naive = false 

) 
Create the FastMKS object with the given reference set (this is the set that is searched).
Optionally, specify whether or not singletree search or naive (bruteforce) search should be used.
referenceSet  Set of reference data. 
singleMode  Whether or not to run singletree search. 
naive  Whether or not to run bruteforce (naive) search. 
FastMKS  (  const MatType &  referenceSet, 
KernelType &  kernel,  
const bool  singleMode = false , 

const bool  naive = false 

) 
Create the FastMKS object using the reference set (this is the set that is searched) with an initialized kernel.
This is useful for when the kernel stores state. Optionally, specify whether or not singletree search or naive (bruteforce) search should be used.
referenceSet  Reference set of data for FastMKS. 
kernel  Initialized kernel. 
single  Whether or not to run singletree search. 
naive  Whether or not to run bruteforce (naive) search. 
FastMKS  (  MatType &&  referenceSet, 
const bool  singleMode = false , 

const bool  naive = false 

) 
Create the FastMKS object with the given reference set (this is the set that is searched), taking ownership of the reference set.
Optionally, specify whether or not singletree search or naive (bruteforce) search should be used.
referenceSet  Set of reference data. 
singleMode  Whether or not to run singletree search. 
naive  Whether or not to run bruteforce (naive) search. 
FastMKS  (  MatType &&  referenceSet, 
KernelType &  kernel,  
const bool  singleMode = false , 

const bool  naive = false 

) 
Create the FastMKS object using the reference set (this is the set that is searched) with an initialized kernel, taking ownership of the reference set.
This is useful for when the kernel stores state. Optionally, specify whether or not singletree search or naive (bruteforce) search should be used.
referenceSet  Reference set of data for FastMKS. 
kernel  Initialized kernel. 
single  Whether or not to run singletree search. 
naive  Whether or not to run bruteforce (naive) search. 
Create the FastMKS object with an alreadyinitialized tree built on the reference points.
Be sure that the tree is built with the metric type IPMetric<KernelType>. Optionally, whether or not to run singletree search can be specified. Bruteforce search is not available with this constructor since a tree is given (use one of the other constructors).
referenceTree  Tree built on reference data. 
single  Whether or not to run singletree search. 
naive  Whether or not to run bruteforce (naive) search. 
Copy the parameters of the given model.

inline 
Get the innerproduct metric induced by the given kernel.
Definition at line 287 of file fastmks.hpp.

inline 
Modify the innerproduct metric induced by the given kernel.
Definition at line 289 of file fastmks.hpp.

inline 
Get whether or not bruteforce (naive) search is used.
Definition at line 297 of file fastmks.hpp.

inline 
Modify whether or not bruteforce (naive) search is used.
Definition at line 299 of file fastmks.hpp.
Assign this model to be a copy of the given model.
void Search  (  const MatType &  querySet, 
const size_t  k,  
arma::Mat< size_t > &  indices,  
arma::mat &  kernels  
) 
Search for the points in the reference set with maximum kernel evaluation to each point in the given query set.
The resulting kernel evaluations are stored in the kernels matrix, and the corresponding point indices are stored in the indices matrix. The results for each point in the query set are stored in the corresponding column of the kernels and products matrices; for instance, the index of the point with maximum kernel evaluation to point 4 in the query set will be stored in row 0 and column 4 of the indices matrix.
If querySet only contains a few points, the extra overhead of building a tree to perform dualtree search may not be warranted, and it may be faster to use singletree search, either by setting singleMode to false in the constructor or with SingleMode().
querySet  Set of query points (can be a single point). 
k  The number of maximum kernels to find. 
indices  Matrix to store resulting indices of maxkernel search in. 
kernels  Matrix to store resulting maxkernel values in. 
void Search  (  Tree *  querySet, 
const size_t  k,  
arma::Mat< size_t > &  indices,  
arma::mat &  kernels  
) 
Search for the points in the reference set with maximum kernel evaluation to each point in the query set corresponding to the given prebuilt query tree.
The resulting kernel evaluations are stored in the kernels matrix, and the corresponding point indices are stored in the indices matrix. The results for each point in the query set are stored in the corresponding column of the kernels and products matrices; for instance, the index of the point with maximum kernel evaluation to point 4 in the query set will be stored in row 0 and column 4 of the indices matrix.
This will throw an exception if called while the FastMKS object has 'single' set to true.
Be aware that if your tree modifies the original input matrix, the results here are with respect to the modified input matrix (that is, queryTree>Dataset()).
queryTree  Tree built on query points. 
k  The number of maximum kernels to find. 
indices  Matrix to store resulting indices of maxkernel search in. 
kernels  Matrix to store resulting maxkernel values in. 
void Search  (  const size_t  k, 
arma::Mat< size_t > &  indices,  
arma::mat &  products  
) 
Search for the maximum inner products of the query set (or if no query set was passed, the reference set is used).
The resulting maximum inner products are stored in the products matrix and the corresponding point indices are stores in the indices matrix. The results for each point in the query set are stored in the corresponding column of the indices and products matrices; for instance, the index of the point with maximum inner product to point 4 in the query set will be stored in row 0 and column 4 of the indices matrix.
k  The number of maximum kernels to find. 
indices  Matrix to store resulting indices of maxkernel search in. 
products  Matrix to store resulting maxkernel values in. 
void serialize  (  Archive &  ar, 
const unsigned  int  
) 
Serialize the model.
Referenced by FastMKS< mlpack::kernel::CosineDistance >::Naive().

inline 
Get whether or not singletree search is used.
Definition at line 292 of file fastmks.hpp.

inline 
Modify whether or not singletree search is used.
Definition at line 294 of file fastmks.hpp.
void Train  (  const MatType &  referenceSet  ) 
"Train" the FastMKS model on the given reference set (this will just build a tree, if the current search mode is not naive mode).
referenceSet  Set of reference points. 
void Train  (  const MatType &  referenceSet, 
KernelType &  kernel  
) 
"Train" the FastMKS model on the given reference set and use the given kernel.
This will just build a tree and replace the metric, if the current search mode is not naive mode.
referenceSet  Set of reference points. 
kernel  Kernel to use for search. 
void Train  (  MatType &&  referenceSet  ) 
"Train" the FastMKS model on the given reference set (this will just build a tree, if the current search mode is not naive mode).
This takes ownership of the reference set.
referenceSet  Set of reference points. 
void Train  (  MatType &&  referenceSet, 
KernelType &  kernel  
) 
"Train" the FastMKS model on the given reference set and use the given kernel.
This will just build a tree and replace the metric, if the current search mode is not naive mode. This takes ownership of the reference set.
referenceSet  Set of reference points. 
kernel  Kernel to use for search. 
void Train  (  Tree *  referenceTree  ) 