mlpack 3.4.2
fastmks.hpp
Go to the documentation of this file.
1
13#ifndef MLPACK_METHODS_FASTMKS_FASTMKS_HPP
14#define MLPACK_METHODS_FASTMKS_FASTMKS_HPP
15
16#include <mlpack/prereqs.hpp>
18#include "fastmks_stat.hpp"
20#include <queue>
21
22namespace mlpack {
23namespace fastmks {
24
56template<
57 typename KernelType,
58 typename MatType = arma::mat,
59 template<typename TreeMetricType,
60 typename TreeStatType,
61 typename TreeMatType> class TreeType = tree::StandardCoverTree
62>
64{
65 public:
67 typedef TreeType<metric::IPMetric<KernelType>, FastMKSStat, MatType> Tree;
68
76 FastMKS(const bool singleMode = false, const bool naive = false);
77
87 FastMKS(const MatType& referenceSet,
88 const bool singleMode = false,
89 const bool naive = false);
90
102 FastMKS(const MatType& referenceSet,
103 KernelType& kernel,
104 const bool singleMode = false,
105 const bool naive = false);
106
117 FastMKS(MatType&& referenceSet,
118 const bool singleMode = false,
119 const bool naive = false);
120
133 FastMKS(MatType&& referenceSet,
134 KernelType& kernel,
135 const bool singleMode = false,
136 const bool naive = false);
137
148 FastMKS(Tree* referenceTree,
149 const bool singleMode = false);
150
154 FastMKS(const FastMKS& other);
155
159 FastMKS(FastMKS&& other);
160
164 FastMKS& operator=(const FastMKS& other);
165
168
175 void Train(const MatType& referenceSet);
176
185 void Train(const MatType& referenceSet, KernelType& kernel);
186
194 void Train(MatType&& referenceSet);
195
204 void Train(MatType&& referenceSet, KernelType& kernel);
205
213 void Train(Tree* referenceTree);
214
235 void Search(const MatType& querySet,
236 const size_t k,
237 arma::Mat<size_t>& indices,
238 arma::mat& kernels);
239
262 void Search(Tree* querySet,
263 const size_t k,
264 arma::Mat<size_t>& indices,
265 arma::mat& kernels);
266
281 void Search(const size_t k,
282 arma::Mat<size_t>& indices,
283 arma::mat& products);
284
286 const metric::IPMetric<KernelType>& Metric() const { return metric; }
289
291 bool SingleMode() const { return singleMode; }
293 bool& SingleMode() { return singleMode; }
294
296 bool Naive() const { return naive; }
298 bool& Naive() { return naive; }
299
301 template<typename Archive>
302 void serialize(Archive& ar, const unsigned int /* version */);
303
304 private:
307 const MatType* referenceSet;
309 Tree* referenceTree;
311 bool treeOwner;
313 bool setOwner;
314
316 bool singleMode;
318 bool naive;
319
322
324 typedef std::pair<double, size_t> Candidate;
325
327 struct CandidateCmp {
328 bool operator()(const Candidate& c1, const Candidate& c2)
329 {
330 return c1.first > c2.first;
331 };
332 };
333
335 typedef std::priority_queue<Candidate, std::vector<Candidate>,
336 CandidateCmp> CandidateList;
337};
338
339} // namespace fastmks
340} // namespace mlpack
341
342// Include implementation.
343#include "fastmks_impl.hpp"
344
345#endif
The statistic used in trees with FastMKS.
An implementation of fast exact max-kernel search.
Definition: fastmks.hpp:64
metric::IPMetric< KernelType > & Metric()
Modify the inner-product metric induced by the given kernel.
Definition: fastmks.hpp:288
bool Naive() const
Get whether or not brute-force (naive) search is used.
Definition: fastmks.hpp:296
FastMKS & operator=(const FastMKS &other)
Assign this model to be a copy of the given model.
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 initiali...
void Train(Tree *referenceTree)
Train the FastMKS model on the given reference tree.
~FastMKS()
Destructor for the FastMKS object.
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 ...
bool SingleMode() const
Get whether or not single-tree search is used.
Definition: fastmks.hpp:291
FastMKS(Tree *referenceTree, const bool singleMode=false)
Create the FastMKS object with an already-initialized tree built on the reference points.
FastMKS(const bool singleMode=false, const bool naive=false)
Create the FastMKS object with an empty reference set and default kernel.
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 initiali...
const metric::IPMetric< KernelType > & Metric() const
Get the inner-product metric induced by the given kernel.
Definition: fastmks.hpp:286
bool & Naive()
Modify whether or not brute-force (naive) search is used.
Definition: fastmks.hpp:298
void Train(const MatType &referenceSet, KernelType &kernel)
"Train" the FastMKS model on the given reference set and use the given kernel.
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,...
void Train(MatType &&referenceSet)
"Train" the FastMKS model on the given reference set (this will just build a tree,...
void Train(MatType &&referenceSet, KernelType &kernel)
"Train" the FastMKS model on the given reference set and use the given kernel.
bool & SingleMode()
Modify whether or not single-tree search is used.
Definition: fastmks.hpp:293
void Train(const MatType &referenceSet)
"Train" the FastMKS model on the given reference set (this will just build a tree,...
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),...
FastMKS(FastMKS &&other)
Take ownership of the given model.
FastMKS(const FastMKS &other)
Copy the parameters of the given model.
TreeType< metric::IPMetric< KernelType >, FastMKSStat, MatType > Tree
Convenience typedef.
Definition: fastmks.hpp:67
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 ...
void serialize(Archive &ar, const unsigned int)
Serialize the model.
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).
The inner product metric, IPMetric, takes a given Mercer kernel (KernelType), and when Evaluate() is ...
Definition: ip_metric.hpp:33
A cover tree is a tree specifically designed to speed up nearest-neighbor computation in high-dimensi...
Definition: cover_tree.hpp:100
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.