kde_rules.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_KDE_RULES_HPP
14 #define MLPACK_METHODS_KDE_RULES_HPP
15 
17 
18 namespace mlpack {
19 namespace kde {
20 
25 template<typename MetricType, typename KernelType, typename TreeType>
26 class KDERules
27 {
28  public:
49  KDERules(const arma::mat& referenceSet,
50  const arma::mat& querySet,
51  arma::vec& densities,
52  const double relError,
53  const double absError,
54  const double mcProb,
55  const size_t initialSampleSize,
56  const double mcAccessCoef,
57  const double mcBreakCoef,
58  MetricType& metric,
59  KernelType& kernel,
60  const bool monteCarlo,
61  const bool sameSet);
62 
64  double BaseCase(const size_t queryIndex, const size_t referenceIndex);
65 
67  double Score(const size_t queryIndex, TreeType& referenceNode);
68 
70  double Rescore(const size_t queryIndex,
71  TreeType& referenceNode,
72  const double oldScore) const;
73 
75  double Score(TreeType& queryNode, TreeType& referenceNode);
76 
78  double Rescore(TreeType& queryNode,
79  TreeType& referenceNode,
80  const double oldScore) const;
81 
83 
85  const TraversalInfoType& TraversalInfo() const { return traversalInfo; }
86 
88  TraversalInfoType& TraversalInfo() { return traversalInfo; }
89 
91  size_t BaseCases() const { return baseCases; }
92 
94  size_t Scores() const { return scores; }
95 
96  private:
98  double EvaluateKernel(const size_t queryIndex,
99  const size_t referenceIndex) const;
100 
102  double EvaluateKernel(const arma::vec& query,
103  const arma::vec& reference) const;
104 
106  double CalculateAlpha(TreeType* node);
107 
109  const arma::mat& referenceSet;
110 
112  const arma::mat& querySet;
113 
115  arma::vec& densities;
116 
118  const double absError;
119 
121  const double relError;
122 
125  const double mcBeta;
126 
128  const size_t initialSampleSize;
129 
133  const double mcAccessCoef;
134 
137  const double mcBreakCoef;
138 
140  MetricType& metric;
141 
143  KernelType& kernel;
144 
146  const bool monteCarlo;
147 
149  arma::vec accumMCAlpha;
150 
152  arma::vec accumError;
153 
155  const bool sameSet;
156 
158  constexpr static bool kernelIsGaussian =
159  std::is_same<KernelType, kernel::GaussianKernel>::value;
160 
162  const double absErrorTol;
163 
165  size_t lastQueryIndex;
166 
168  size_t lastReferenceIndex;
169 
171  TraversalInfoType traversalInfo;
172 
174  size_t baseCases;
175 
177  size_t scores;
178 };
179 
184 template<typename TreeType>
186 {
187  public:
189  KDECleanRules() { /* Nothing to do. */ }
190 
192  double BaseCase(const size_t /* queryIndex */, const size_t /* refIndex */);
193 
195  double Score(const size_t /* queryIndex */, TreeType& referenceNode);
196 
198  double Rescore(const size_t /* queryIndex */,
199  TreeType& /* referenceNode */,
200  const double oldScore) const { return oldScore; }
201 
203  double Score(TreeType& queryNode, TreeType& referenceNode);
204 
206  double Rescore(TreeType& /* queryNode */,
207  TreeType& /* referenceNode*/ ,
208  const double oldScore) const { return oldScore; }
209 
211 
213  const TraversalInfoType& TraversalInfo() const { return traversalInfo; }
214 
216  TraversalInfoType& TraversalInfo() { return traversalInfo; }
217 
218  private:
220  TraversalInfoType traversalInfo;
221 };
222 
223 } // namespace kde
224 } // namespace mlpack
225 
226 // Include implementation.
227 #include "kde_rules_impl.hpp"
228 
229 #endif
double Score(const size_t queryIndex, TreeType &referenceNode)
SingleTree Rescore.
const TraversalInfoType & TraversalInfo() const
Get traversal information.
Definition: kde_rules.hpp:85
The TraversalInfo class holds traversal information which is used in dual-tree (and single-tree) trav...
.hpp
Definition: add_to_po.hpp:21
tree::TraversalInfo< TreeType > TraversalInfoType
Definition: kde_rules.hpp:82
A dual-tree traversal Rules class for cleaning used trees before performing kernel density estimation...
Definition: kde_rules.hpp:185
TraversalInfoType & TraversalInfo()
Modify traversal information.
Definition: kde_rules.hpp:216
const TraversalInfoType & TraversalInfo() const
Get traversal information.
Definition: kde_rules.hpp:213
double Rescore(const size_t queryIndex, TreeType &referenceNode, const double oldScore) const
SingleTree Score.
double Rescore(const size_t, TreeType &, const double oldScore) const
SingleTree Rescore.
Definition: kde_rules.hpp:198
double BaseCase(const size_t queryIndex, const size_t referenceIndex)
Base Case.
double Rescore(TreeType &, TreeType &, const double oldScore) const
Dual-Tree Rescore.
Definition: kde_rules.hpp:206
TraversalInfoType & TraversalInfo()
Modify traversal information.
Definition: kde_rules.hpp:88
size_t BaseCases() const
Get the number of base cases.
Definition: kde_rules.hpp:91
A dual-tree traversal Rules class for kernel density estimation.
Definition: kde_rules.hpp:26
tree::TraversalInfo< TreeType > TraversalInfoType
Definition: kde_rules.hpp:210
size_t Scores() const
Get the number of scores.
Definition: kde_rules.hpp:94
KDECleanRules()
Construct KDECleanRules.
Definition: kde_rules.hpp:189
KDERules(const arma::mat &referenceSet, const arma::mat &querySet, arma::vec &densities, const double relError, const double absError, const double mcProb, const size_t initialSampleSize, const double mcAccessCoef, const double mcBreakCoef, MetricType &metric, KernelType &kernel, const bool monteCarlo, const bool sameSet)
Construct KDERules.