mlpack  2.2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
21 namespace mlpack {
22 namespace fastmks {
23 
55 template<
56  typename KernelType,
57  typename MatType = arma::mat,
58  template<typename TreeMetricType,
59  typename TreeStatType,
60  typename TreeMatType> class TreeType = tree::StandardCoverTree
61 >
62 class FastMKS
63 {
64  public:
66  typedef TreeType<metric::IPMetric<KernelType>, FastMKSStat, MatType> Tree;
67 
75  FastMKS(const bool singleMode = false, const bool naive = false);
76 
86  FastMKS(const MatType& referenceSet,
87  const bool singleMode = false,
88  const bool naive = false);
89 
101  FastMKS(const MatType& referenceSet,
102  KernelType& kernel,
103  const bool singleMode = false,
104  const bool naive = false);
105 
117  FastMKS(Tree* referenceTree,
118  const bool singleMode = false);
119 
121  ~FastMKS();
122 
129  void Train(const MatType& referenceSet);
130 
139  void Train(const MatType& referenceSet, KernelType& kernel);
140 
148  void Train(Tree* referenceTree);
149 
170  void Search(const MatType& querySet,
171  const size_t k,
172  arma::Mat<size_t>& indices,
173  arma::mat& kernels);
174 
197  void Search(Tree* querySet,
198  const size_t k,
199  arma::Mat<size_t>& indices,
200  arma::mat& kernels);
201 
216  void Search(const size_t k,
217  arma::Mat<size_t>& indices,
218  arma::mat& products);
219 
221  const metric::IPMetric<KernelType>& Metric() const { return metric; }
223  metric::IPMetric<KernelType>& Metric() { return metric; }
224 
226  bool SingleMode() const { return singleMode; }
228  bool& SingleMode() { return singleMode; }
229 
231  bool Naive() const { return naive; }
233  bool& Naive() { return naive; }
234 
236  template<typename Archive>
237  void Serialize(Archive& ar, const unsigned int /* version */);
238 
239  private:
242  const MatType* referenceSet;
244  Tree* referenceTree;
246  bool treeOwner;
248  bool setOwner;
249 
251  bool singleMode;
253  bool naive;
254 
257 
259  typedef std::pair<double, size_t> Candidate;
260 
262  struct CandidateCmp {
263  bool operator()(const Candidate& c1, const Candidate& c2)
264  {
265  return c1.first > c2.first;
266  };
267  };
268 
270  typedef std::priority_queue<Candidate, std::vector<Candidate>,
271  CandidateCmp> CandidateList;
272 };
273 
274 } // namespace fastmks
275 } // namespace mlpack
276 
277 // Include implementation.
278 #include "fastmks_impl.hpp"
279 
280 #endif
bool SingleMode() const
Get whether or not single-tree search is used.
Definition: fastmks.hpp:226
const metric::IPMetric< KernelType > & Metric() const
Get the inner-product metric induced by the given kernel.
Definition: fastmks.hpp:221
The core includes that mlpack expects; standard C++ includes and Armadillo.
bool & Naive()
Modify whether or not brute-force (naive) search is used.
Definition: fastmks.hpp:233
The inner product metric, IPMetric, takes a given Mercer kernel (KernelType), and when Evaluate() is ...
Definition: ip_metric.hpp:32
FastMKS(const bool singleMode=false, const bool naive=false)
Create the FastMKS object with an empty reference set and default kernel.
void Serialize(Archive &ar, const unsigned int)
Serialize the model.
~FastMKS()
Destructor for the FastMKS object.
metric::IPMetric< KernelType > & Metric()
Modify the inner-product metric induced by the given kernel.
Definition: fastmks.hpp:223
bool & SingleMode()
Modify whether or not single-tree search is used.
Definition: fastmks.hpp:228
TreeType< metric::IPMetric< KernelType >, FastMKSStat, MatType > Tree
Convenience typedef.
Definition: fastmks.hpp:66
bool Naive() const
Get whether or not brute-force (naive) search is used.
Definition: fastmks.hpp:231
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 ...
The statistic used in trees with FastMKS.
void Train(const MatType &referenceSet)
&quot;Train&quot; the FastMKS model on the given reference set (this will just build a tree, if the current search mode is not naive mode).
An implementation of fast exact max-kernel search.
Definition: fastmks.hpp:62
A cover tree is a tree specifically designed to speed up nearest-neighbor computation in high-dimensi...
Definition: cover_tree.hpp:99