mlpack  2.0.1
ra_search_rules.hpp
Go to the documentation of this file.
1 
16 #ifndef __MLPACK_METHODS_RANN_RA_SEARCH_RULES_HPP
17 #define __MLPACK_METHODS_RANN_RA_SEARCH_RULES_HPP
18 
19 #include "../neighbor_search/ns_traversal_info.hpp"
20 
21 namespace mlpack {
22 namespace neighbor {
23 
24 template<typename SortPolicy, typename MetricType, typename TreeType>
26 {
27  public:
28  RASearchRules(const arma::mat& referenceSet,
29  const arma::mat& querySet,
30  arma::Mat<size_t>& neighbors,
31  arma::mat& distances,
32  MetricType& metric,
33  const double tau = 5,
34  const double alpha = 0.95,
35  const bool naive = false,
36  const bool sampleAtLeaves = false,
37  const bool firstLeafExact = false,
38  const size_t singleSampleLimit = 20,
39  const bool sameSet = false);
40 
41  double BaseCase(const size_t queryIndex, const size_t referenceIndex);
42 
65  double Score(const size_t queryIndex, TreeType& referenceNode);
66 
90  double Score(const size_t queryIndex,
91  TreeType& referenceNode,
92  const double baseCaseResult);
93 
111  double Rescore(const size_t queryIndex,
112  TreeType& referenceNode,
113  const double oldScore);
114 
133  double Score(TreeType& queryNode, TreeType& referenceNode);
134 
155  double Score(TreeType& queryNode,
156  TreeType& referenceNode,
157  const double baseCaseResult);
158 
181  double Rescore(TreeType& queryNode,
182  TreeType& referenceNode,
183  const double oldScore);
184 
185 
188  {
189  if (numSamplesMade.n_elem == 0)
190  return 0;
191  else
192  return arma::sum(numSamplesMade);
193  }
194 
196 
197  const TraversalInfoType& TraversalInfo() const { return traversalInfo; }
198  TraversalInfoType& TraversalInfo() { return traversalInfo; }
199 
200  private:
202  const arma::mat& referenceSet;
203 
205  const arma::mat& querySet;
206 
208  arma::Mat<size_t>& neighbors;
209 
211  arma::mat& distances;
212 
214  MetricType& metric;
215 
218 
221 
224 
227 
229  arma::Col<size_t> numSamplesMade;
230 
233 
234  // TO REMOVE: just for testing
236 
238  bool sameSet;
239 
240  TraversalInfoType traversalInfo;
241 
251  void InsertNeighbor(const size_t queryIndex,
252  const size_t pos,
253  const size_t neighbor,
254  const double distance);
255 
259  double Score(const size_t queryIndex,
260  TreeType& referenceNode,
261  const double distance,
262  const double bestDistance);
263 
267  double Score(TreeType& queryNode,
268  TreeType& referenceNode,
269  const double distance,
270  const double bestDistance);
271 }; // class RASearchRules
272 
273 } // namespace neighbor
274 } // namespace mlpack
275 
276 // Include implementation.
277 #include "ra_search_rules_impl.hpp"
278 
279 #endif // __MLPACK_METHODS_RANN_RA_SEARCH_RULES_HPP
bool firstLeafExact
Whether to do exact computation on the first leaf before any sampling.
RASearchRules(const arma::mat &referenceSet, const arma::mat &querySet, arma::Mat< size_t > &neighbors, arma::mat &distances, MetricType &metric, const double tau=5, const double alpha=0.95, const bool naive=false, const bool sampleAtLeaves=false, const bool firstLeafExact=false, const size_t singleSampleLimit=20, const bool sameSet=false)
double samplingRatio
The sampling ratio.
Linear algebra utility functions, generally performed on matrices or vectors.
size_t numSamplesReqd
The minimum number of samples required per query.
MetricType & metric
The instantiated metric.
double Rescore(const size_t queryIndex, TreeType &referenceNode, const double oldScore)
Re-evaluate the score for recursion order.
arma::mat & distances
The matrix the resultant neighbor distances should be stored in.
double Score(const size_t queryIndex, TreeType &referenceNode)
Get the score for recursion order.
neighbor::NeighborSearchTraversalInfo< TreeType > TraversalInfoType
arma::Col< size_t > numSamplesMade
The number of samples made for every query.
const TraversalInfoType & TraversalInfo() const
Traversal information for NeighborSearch.
const arma::mat & querySet
The query set.
bool sampleAtLeaves
Whether to sample at leaves or just use all of it.
const arma::mat & referenceSet
The reference set.
TraversalInfoType & TraversalInfo()
bool sameSet
If the query and reference set are identical, this is true.
void InsertNeighbor(const size_t queryIndex, const size_t pos, const size_t neighbor, const double distance)
Insert a point into the neighbors and distances matrices; this is a helper function.
see subsection cli_alt_reg_tut Alternate DET regularization The usual regularized error f $R_ alpha(t)\f $of a node\f $t\f $is given by
Definition: det.txt:344
size_t singleSampleLimit
The limit on the largest node that can be approximated by sampling.
double BaseCase(const size_t queryIndex, const size_t referenceIndex)
arma::Mat< size_t > & neighbors
The matrix the resultant neighbor indices should be stored in.