mlpack  1.0.12
fastmks.hpp
Go to the documentation of this file.
1 
15 #ifndef __MLPACK_METHODS_FASTMKS_FASTMKS_HPP
16 #define __MLPACK_METHODS_FASTMKS_FASTMKS_HPP
17 
18 #include <mlpack/core.hpp>
20 #include "fastmks_stat.hpp"
22 
23 namespace mlpack {
24 namespace fastmks {
25 
56 template<
57  typename KernelType,
60 >
61 class FastMKS
62 {
63  public:
73  FastMKS(const arma::mat& referenceSet,
74  const bool single = false,
75  const bool naive = false);
76 
87  FastMKS(const arma::mat& referenceSet,
88  const arma::mat& querySet,
89  const bool single = false,
90  const bool naive = false);
91 
103  FastMKS(const arma::mat& referenceSet,
104  KernelType& kernel,
105  const bool single = false,
106  const bool naive = false);
107 
120  FastMKS(const arma::mat& referenceSet,
121  const arma::mat& querySet,
122  KernelType& kernel,
123  const bool single = false,
124  const bool naive = false);
125 
138  FastMKS(const arma::mat& referenceSet,
139  TreeType* referenceTree,
140  const bool single = false,
141  const bool naive = false);
142 
156  FastMKS(const arma::mat& referenceSet,
157  TreeType* referenceTree,
158  const arma::mat& querySet,
159  TreeType* queryTree,
160  const bool single = false,
161  const bool naive = false);
162 
164  ~FastMKS();
165 
180  void Search(const size_t k,
181  arma::Mat<size_t>& indices,
182  arma::mat& products);
183 
185  const metric::IPMetric<KernelType>& Metric() const { return metric; }
188 
192  std::string ToString() const;
193 
194  private:
196  const arma::mat& referenceSet;
198  const arma::mat& querySet;
199 
201  TreeType* referenceTree;
204  TreeType* queryTree;
205 
207  bool treeOwner;
208 
210  bool single;
212  bool naive;
213 
216 
218  void InsertNeighbor(arma::Mat<size_t>& indices,
219  arma::mat& products,
220  const size_t queryIndex,
221  const size_t pos,
222  const size_t neighbor,
223  const double distance);
224 };
225 
226 }; // namespace fastmks
227 }; // namespace mlpack
228 
229 // Include implementation.
230 #include "fastmks_impl.hpp"
231 
232 #endif
FastMKS(const arma::mat &referenceSet, const bool single=false, const bool naive=false)
Create the FastMKS object using the reference set as the query set.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:23
void InsertNeighbor(arma::Mat< size_t > &indices, arma::mat &products, const size_t queryIndex, const size_t pos, const size_t neighbor, const double distance)
Utility function. Copied too many times from too many places.
const arma::mat & referenceSet
The reference dataset.
Definition: fastmks.hpp:196
const metric::IPMetric< KernelType > & Metric() const
Get the inner-product metric induced by the given kernel.
Definition: fastmks.hpp:185
bool treeOwner
If true, this object created the trees and is responsible for them.
Definition: fastmks.hpp:207
TreeType * queryTree
The tree built on the query dataset.
Definition: fastmks.hpp:204
TreeType * referenceTree
The tree built on the reference dataset.
Definition: fastmks.hpp:201
const arma::mat & querySet
The query dataset.
Definition: fastmks.hpp:198
metric::IPMetric< KernelType > & Metric()
Modify the inner-product metric induced by the given kernel.
Definition: fastmks.hpp:187
bool single
If true, single-tree search is used.
Definition: fastmks.hpp:210
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).
bool naive
If true, naive (brute-force) search is used.
Definition: fastmks.hpp:212
The statistic used in trees with FastMKS.
~FastMKS()
Destructor for the FastMKS object.
This class is meant to be used as a choice for the policy class RootPointPolicy of the CoverTree clas...
An implementation of fast exact max-kernel search.
Definition: fastmks.hpp:61
A cover tree is a tree specifically designed to speed up nearest-neighbor computation in high-dimensi...
Definition: cover_tree.hpp:95
metric::IPMetric< KernelType > metric
The instantiated inner-product metric induced by the given kernel.
Definition: fastmks.hpp:215
std::string ToString() const
Returns a string representation of this object.