13 #ifndef MLPACK_METHODS_KDE_RULES_HPP 14 #define MLPACK_METHODS_KDE_RULES_HPP 25 template<
typename MetricType,
typename KernelType,
typename TreeType>
49 KDERules(
const arma::mat& referenceSet,
50 const arma::mat& querySet,
52 const double relError,
53 const double absError,
55 const size_t initialSampleSize,
56 const double mcAccessCoef,
57 const double mcBreakCoef,
60 const bool monteCarlo,
64 double BaseCase(
const size_t queryIndex,
const size_t referenceIndex);
67 double Score(
const size_t queryIndex, TreeType& referenceNode);
70 double Rescore(
const size_t queryIndex,
71 TreeType& referenceNode,
72 const double oldScore)
const;
75 double Score(TreeType& queryNode, TreeType& referenceNode);
78 double Rescore(TreeType& queryNode,
79 TreeType& referenceNode,
80 const double oldScore)
const;
85 const TraversalInfoType&
TraversalInfo()
const {
return traversalInfo; }
94 size_t Scores()
const {
return scores; }
102 double EvaluateKernel(
const size_t queryIndex,
103 const size_t referenceIndex)
const;
106 double EvaluateKernel(
const arma::vec& query,
107 const arma::vec& reference)
const;
110 double CalculateAlpha(TreeType* node);
113 const arma::mat& referenceSet;
116 const arma::mat& querySet;
119 arma::vec& densities;
122 const double absError;
125 const double relError;
132 const size_t initialSampleSize;
137 const double mcAccessCoef;
141 const double mcBreakCoef;
150 const bool monteCarlo;
153 arma::vec accumMCAlpha;
156 arma::vec accumError;
162 constexpr
static bool kernelIsGaussian =
163 std::is_same<KernelType, kernel::GaussianKernel>::value;
166 const double absErrorTol;
169 size_t lastQueryIndex;
172 size_t lastReferenceIndex;
175 TraversalInfoType traversalInfo;
188 template<
typename TreeType>
196 double BaseCase(
const size_t ,
const size_t );
199 double Score(
const size_t , TreeType& referenceNode);
204 const double oldScore)
const {
return oldScore; }
207 double Score(TreeType& queryNode, TreeType& referenceNode);
212 const double oldScore)
const {
return oldScore; }
224 TraversalInfoType traversalInfo;
231 #include "kde_rules_impl.hpp" double Score(const size_t queryIndex, TreeType &referenceNode)
SingleTree Rescore.
const TraversalInfoType & TraversalInfo() const
Get traversal information.
The TraversalInfo class holds traversal information which is used in dual-tree (and single-tree) trav...
Linear algebra utility functions, generally performed on matrices or vectors.
tree::TraversalInfo< TreeType > TraversalInfoType
A dual-tree traversal Rules class for cleaning used trees before performing kernel density estimation...
TraversalInfoType & TraversalInfo()
Modify traversal information.
const TraversalInfoType & TraversalInfo() const
Get traversal information.
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.
size_t MinimumBaseCases() const
Get the minimum number of base cases we need to perform to have acceptable results.
double BaseCase(const size_t queryIndex, const size_t referenceIndex)
Base Case.
double Rescore(TreeType &, TreeType &, const double oldScore) const
Dual-Tree Rescore.
TraversalInfoType & TraversalInfo()
Modify traversal information.
size_t BaseCases() const
Get the number of base cases.
A dual-tree traversal Rules class for kernel density estimation.
tree::TraversalInfo< TreeType > TraversalInfoType
size_t Scores() const
Get the number of scores.
KDECleanRules()
Construct KDECleanRules.
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.