mlpack  2.0.1
hrectbound.hpp
Go to the documentation of this file.
1 
16 #ifndef __MLPACK_CORE_TREE_HRECTBOUND_HPP
17 #define __MLPACK_CORE_TREE_HRECTBOUND_HPP
18 
19 #include <mlpack/core.hpp>
22 #include "bound_traits.hpp"
23 
24 namespace mlpack {
25 namespace bound {
26 
27 namespace meta {
28 
31 template<typename MetricType>
32 struct IsLMetric
33 {
34  static const bool Value = false;
35 };
36 
38 template<int Power, bool TakeRoot>
39 struct IsLMetric<metric::LMetric<Power, TakeRoot>>
40 {
41  static const bool Value = true;
42 };
43 
44 } // namespace util
45 
55 template<typename MetricType = metric::LMetric<2, true>>
57 {
58  // It is required that HRectBound have an LMetric as the given MetricType.
59  static_assert(meta::IsLMetric<MetricType>::Value == true,
60  "HRectBound can only be used with the LMetric<> metric type.");
61 
62  public:
66  HRectBound();
67 
72  HRectBound(const size_t dimension);
73 
75  HRectBound(const HRectBound& other);
77  HRectBound& operator=(const HRectBound& other);
78 
80  HRectBound(HRectBound&& other);
81 
83  ~HRectBound();
84 
89  void Clear();
90 
92  size_t Dim() const { return dim; }
93 
96  math::Range& operator[](const size_t i) { return bounds[i]; }
98  const math::Range& operator[](const size_t i) const { return bounds[i]; }
99 
101  double MinWidth() const { return minWidth; }
103  double& MinWidth() { return minWidth; }
104 
110  void Center(arma::vec& center) const;
111 
117  double Volume() const;
118 
124  template<typename VecType>
125  double MinDistance(const VecType& point,
126  typename boost::enable_if<IsVector<VecType> >* = 0) const;
127 
133  double MinDistance(const HRectBound& other) const;
134 
140  template<typename VecType>
141  double MaxDistance(const VecType& point,
142  typename boost::enable_if<IsVector<VecType> >* = 0) const;
143 
149  double MaxDistance(const HRectBound& other) const;
150 
157  math::Range RangeDistance(const HRectBound& other) const;
158 
165  template<typename VecType>
166  math::Range RangeDistance(const VecType& point,
167  typename boost::enable_if<IsVector<VecType> >* = 0)
168  const;
169 
177  template<typename MatType>
178  HRectBound& operator|=(const MatType& data);
179 
183  HRectBound& operator|=(const HRectBound& other);
184 
188  template<typename VecType>
189  bool Contains(const VecType& point) const;
190 
194  double Diameter() const;
195 
199  template<typename Archive>
200  void Serialize(Archive& ar, const unsigned int version);
201 
202  private:
204  size_t dim;
208  double minWidth;
209 };
210 
211 // A specialization of BoundTraits for this class.
212 template<typename MetricType>
213 struct BoundTraits<HRectBound<MetricType>>
214 {
216  const static bool HasTightBounds = true;
217 };
218 
219 } // namespace bound
220 } // namespace mlpack
221 
222 #include "hrectbound_impl.hpp"
223 
224 #endif // __MLPACK_CORE_TREE_HRECTBOUND_HPP
const math::Range & operator[](const size_t i) const
Modify the range for a particular dimension. No bounds checking.
Definition: hrectbound.hpp:98
double minWidth
Cached minimum width of bound.
Definition: hrectbound.hpp:208
Linear algebra utility functions, generally performed on matrices or vectors.
A class to obtain compile-time traits about BoundType classes.
size_t Dim() const
Gets the dimensionality.
Definition: hrectbound.hpp:92
Utility struct where Value is true if and only if the argument is of type LMetric.
Definition: hrectbound.hpp:32
math::Range & operator[](const size_t i)
Get the range for a particular dimension.
Definition: hrectbound.hpp:96
double MinWidth() const
Get the minimum width of the bound.
Definition: hrectbound.hpp:101
math::Range * bounds
The bounds for each dimension.
Definition: hrectbound.hpp:206
Hyper-rectangle bound for an L-metric.
Definition: hrectbound.hpp:56
Simple real-valued range.
Definition: range.hpp:21
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
Definition of the Range class, which represents a simple range with a lower and upper bound...
void Center(const arma::mat &x, arma::mat &xCentered)
Creates a centered matrix, where centering is done by subtracting the sum over the columns (a column ...
double & MinWidth()
Modify the minimum width of the bound.
Definition: hrectbound.hpp:103
size_t dim
The dimensionality of the bound.
Definition: hrectbound.hpp:204
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:37