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 
22 namespace mlpack {
23 namespace fastmks {
24 
56 template<
57  typename KernelType,
58  typename MatType = arma::mat,
59  template<typename TreeMetricType,
60  typename TreeStatType,
61  typename TreeMatType> class TreeType = tree::StandardCoverTree
62 >
63 class FastMKS
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; }
288  metric::IPMetric<KernelType>& Metric() { 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
mlpack::fastmks::FastMKS
An implementation of fast exact max-kernel search.
Definition: fastmks.hpp:64
prereqs.hpp
The core includes that mlpack expects; standard C++ includes and Armadillo.
mlpack::fastmks::FastMKS::SingleMode
bool SingleMode() const
Get whether or not single-tree search is used.
Definition: fastmks.hpp:291
mlpack::fastmks::FastMKS::Train
void Train(Tree *referenceTree)
Train the FastMKS model on the given reference tree.
mlpack::fastmks::FastMKS::Metric
metric::IPMetric< KernelType > & Metric()
Modify the inner-product metric induced by the given kernel.
Definition: fastmks.hpp:288
mlpack::fastmks::FastMKS::Search
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,...
mlpack::fastmks::FastMKS::Train
void Train(MatType &&referenceSet)
"Train" the FastMKS model on the given reference set (this will just build a tree,...
mlpack::fastmks::FastMKS::FastMKS
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),...
mlpack::fastmks::FastMKS::SingleMode
bool & SingleMode()
Modify whether or not single-tree search is used.
Definition: fastmks.hpp:293
ip_metric.hpp
mlpack::metric::IPMetric
The inner product metric, IPMetric, takes a given Mercer kernel (KernelType), and when Evaluate() is ...
Definition: ip_metric.hpp:33
mlpack::fastmks::FastMKS::FastMKS
FastMKS(const FastMKS &other)
Copy the parameters of the given model.
mlpack::fastmks::FastMKS::Train
void Train(MatType &&referenceSet, KernelType &kernel)
"Train" the FastMKS model on the given reference set and use the given kernel.
mlpack::fastmks::FastMKS::FastMKS
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...
mlpack
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: add_to_cli11.hpp:21
cover_tree.hpp
mlpack::fastmks::FastMKS::FastMKS
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).
mlpack::fastmks::FastMKS::Train
void Train(const MatType &referenceSet, KernelType &kernel)
"Train" the FastMKS model on the given reference set and use the given kernel.
mlpack::fastmks::FastMKS::Naive
bool Naive() const
Get whether or not brute-force (naive) search is used.
Definition: fastmks.hpp:296
mlpack::fastmks::FastMKS::Search
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 ...
mlpack::fastmks::FastMKS::Metric
const metric::IPMetric< KernelType > & Metric() const
Get the inner-product metric induced by the given kernel.
Definition: fastmks.hpp:286
mlpack::fastmks::FastMKS::FastMKS
FastMKS(FastMKS &&other)
Take ownership of the given model.
mlpack::fastmks::FastMKS::Tree
TreeType< metric::IPMetric< KernelType >, FastMKSStat, MatType > Tree
Convenience typedef.
Definition: fastmks.hpp:67
mlpack::fastmks::FastMKS::serialize
void serialize(Archive &ar, const unsigned int)
Serialize the model.
mlpack::fastmks::FastMKS::operator=
FastMKS & operator=(const FastMKS &other)
Assign this model to be a copy of the given model.
mlpack::fastmks::FastMKS::Search
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 ...
fastmks_stat.hpp
mlpack::fastmks::FastMKS::Naive
bool & Naive()
Modify whether or not brute-force (naive) search is used.
Definition: fastmks.hpp:298
mlpack::fastmks::FastMKS::FastMKS
FastMKS(const bool singleMode=false, const bool naive=false)
Create the FastMKS object with an empty reference set and default kernel.
mlpack::fastmks::FastMKSStat
The statistic used in trees with FastMKS.
Definition: fastmks_stat.hpp:26
mlpack::fastmks::FastMKS::FastMKS
FastMKS(Tree *referenceTree, const bool singleMode=false)
Create the FastMKS object with an already-initialized tree built on the reference points.
mlpack::fastmks::FastMKS::FastMKS
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...
mlpack::tree::CoverTree
A cover tree is a tree specifically designed to speed up nearest-neighbor computation in high-dimensi...
Definition: cover_tree.hpp:100
mlpack::fastmks::FastMKS::Train
void Train(const MatType &referenceSet)
"Train" the FastMKS model on the given reference set (this will just build a tree,...
mlpack::fastmks::FastMKS::~FastMKS
~FastMKS()
Destructor for the FastMKS object.