kde_stat.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_KDE_STAT_HPP
13 #define MLPACK_METHODS_KDE_STAT_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace kde {
19 
24 class KDEStat
25 {
26  public:
28  KDEStat() :
29  mcBeta(0),
30  mcAlpha(0),
31  accumAlpha(0),
32  accumError(0)
33  { /* Nothing to do.*/ }
34 
36  template<typename TreeType>
37  KDEStat(TreeType& /* node */) :
38  mcBeta(0),
39  mcAlpha(0),
40  accumAlpha(0),
41  accumError(0)
42  { /* Nothing to do. */ }
43 
45  inline double MCBeta() const { return mcBeta; }
46 
48  inline double& MCBeta() { return mcBeta; }
49 
51  inline double AccumAlpha() const { return accumAlpha; }
52 
54  inline double& AccumAlpha() { return accumAlpha; }
55 
57  inline double AccumError() const { return accumError; }
58 
60  inline double& AccumError() { return accumError; }
61 
63  inline double MCAlpha() const { return mcAlpha; }
64 
66  inline double& MCAlpha() { return mcAlpha; }
67 
69  template<typename Archive>
70  void serialize(Archive& ar, const unsigned int version)
71  {
72  // Backward compatibility: Old versions of KDEStat needed to handle obsolete
73  // values.
74  if (version == 0 && Archive::is_loading::value)
75  {
76  // Placeholders.
77  arma::vec centroid;
78  bool validCentroid;
79 
80  ar & BOOST_SERIALIZATION_NVP(centroid);
81  ar & BOOST_SERIALIZATION_NVP(validCentroid);
82  }
83 
84  // Backward compatibility: Old versions of KDEStat did not need to handle
85  // alpha values.
86  if (version > 0)
87  {
88  ar & BOOST_SERIALIZATION_NVP(mcBeta);
89  ar & BOOST_SERIALIZATION_NVP(mcAlpha);
90  ar & BOOST_SERIALIZATION_NVP(accumAlpha);
91  ar & BOOST_SERIALIZATION_NVP(accumError);
92  }
93  else if (Archive::is_loading::value)
94  {
95  mcBeta = -1;
96  mcAlpha = -1;
97  accumAlpha = -1;
98  accumError = -1;
99  }
100  }
101 
102  private:
104  double mcBeta;
105 
107  double mcAlpha;
108 
110  double accumAlpha;
111 
113  double accumError;
114 };
115 
116 } // namespace kde
117 } // namespace mlpack
118 
121 
122 #endif
double AccumAlpha() const
Get accumulated Monte Carlo alpha of the node.
Definition: kde_stat.hpp:51
strip_type.hpp
Definition: add_to_po.hpp:21
double MCBeta() const
Get accumulated Monte Carlo alpha of the node.
Definition: kde_stat.hpp:45
The core includes that mlpack expects; standard C++ includes and Armadillo.
double & MCBeta()
Modify accumulated Monte Carlo alpha of the node.
Definition: kde_stat.hpp:48
double & AccumAlpha()
Modify accumulated Monte Carlo alpha of the node.
Definition: kde_stat.hpp:54
Extra data for each node in the tree for the task of kernel density estimation.
Definition: kde_stat.hpp:24
void serialize(Archive &ar, const unsigned int version)
Serialize the statistic to/from an archive.
Definition: kde_stat.hpp:70
KDEStat(TreeType &)
Initialization for a fully initialized node.
Definition: kde_stat.hpp:37
double & MCAlpha()
Modify Monte Carlo alpha of the node.
Definition: kde_stat.hpp:66
double & AccumError()
Modify accumulated error tolerance of the node.
Definition: kde_stat.hpp:60
double MCAlpha() const
Get Monte Carlo alpha of the node.
Definition: kde_stat.hpp:63
KDEStat()
Initialize the statistic.
Definition: kde_stat.hpp:28
double AccumError() const
Get accumulated error tolerance of the node.
Definition: kde_stat.hpp:57
BOOST_TEMPLATE_CLASS_VERSION(template<>, mlpack::kde::KDEStat, 1)
Set the serialization version of the KDEStat class.