mlpack  2.2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
hrectbound.hpp
Go to the documentation of this file.
1 
14 #ifndef MLPACK_CORE_TREE_HRECTBOUND_HPP
15 #define MLPACK_CORE_TREE_HRECTBOUND_HPP
16 
17 #include <mlpack/prereqs.hpp>
20 #include "bound_traits.hpp"
21 
22 namespace mlpack {
23 namespace bound {
24 
25 namespace meta {
26 
29 template<typename MetricType>
30 struct IsLMetric
31 {
32  static const bool Value = false;
33 };
34 
36 template<int Power, bool TakeRoot>
37 struct IsLMetric<metric::LMetric<Power, TakeRoot>>
38 {
39  static const bool Value = true;
40 };
41 
42 } // namespace util
43 
52 template<typename MetricType = metric::LMetric<2, true>,
53  typename ElemType = double>
55 {
56  // It is required that HRectBound have an LMetric as the given MetricType.
57  static_assert(meta::IsLMetric<MetricType>::Value == true,
58  "HRectBound can only be used with the LMetric<> metric type.");
59 
60  public:
64  HRectBound();
65 
70  HRectBound(const size_t dimension);
71 
73  HRectBound(const HRectBound& other);
75  HRectBound& operator=(const HRectBound& other);
76 
78  HRectBound(HRectBound&& other);
79 
81  ~HRectBound();
82 
87  void Clear();
88 
90  size_t Dim() const { return dim; }
91 
94  math::RangeType<ElemType>& operator[](const size_t i) { return bounds[i]; }
96  const math::RangeType<ElemType>& operator[](const size_t i) const
97  { return bounds[i]; }
98 
100  ElemType MinWidth() const { return minWidth; }
102  ElemType& MinWidth() { return minWidth; }
103 
109  void Center(arma::Col<ElemType>& center) const;
110 
116  ElemType Volume() const;
117 
123  template<typename VecType>
124  ElemType MinDistance(const VecType& point,
125  typename boost::enable_if<IsVector<VecType>>* = 0) const;
126 
132  ElemType MinDistance(const HRectBound& other) const;
133 
139  template<typename VecType>
140  ElemType MaxDistance(const VecType& point,
141  typename boost::enable_if<IsVector<VecType>>* = 0) const;
142 
148  ElemType MaxDistance(const HRectBound& other) const;
149 
157 
164  template<typename VecType>
166  const VecType& point,
167  typename boost::enable_if<IsVector<VecType>>* = 0) const;
168 
176  template<typename MatType>
177  HRectBound& operator|=(const MatType& data);
178 
182  HRectBound& operator|=(const HRectBound& other);
183 
187  template<typename VecType>
188  bool Contains(const VecType& point) const;
189 
193  bool Contains(const HRectBound& bound) const;
194 
198  HRectBound operator&(const HRectBound& bound) const;
199 
203  HRectBound& operator&=(const HRectBound& bound);
204 
208  ElemType Overlap(const HRectBound& bound) const;
209 
213  ElemType Diameter() const;
214 
218  template<typename Archive>
219  void Serialize(Archive& ar, const unsigned int version);
220 
221  private:
223  size_t dim;
227  ElemType minWidth;
228 };
229 
230 // A specialization of BoundTraits for this class.
231 template<typename MetricType, typename ElemType>
232 struct BoundTraits<HRectBound<MetricType, ElemType>>
233 {
235  const static bool HasTightBounds = true;
236 };
237 
238 } // namespace bound
239 } // namespace mlpack
240 
241 #include "hrectbound_impl.hpp"
242 
243 #endif // MLPACK_CORE_TREE_HRECTBOUND_HPP
size_t Dim() const
Gets the dimensionality.
Definition: hrectbound.hpp:90
A class to obtain compile-time traits about BoundType classes.
ElemType MinWidth() const
Get the minimum width of the bound.
Definition: hrectbound.hpp:100
The core includes that mlpack expects; standard C++ includes and Armadillo.
Utility struct where Value is true if and only if the argument is of type LMetric.
Definition: hrectbound.hpp:30
ElemType Diameter() const
Returns the diameter of the hyperrectangle (that is, the longest diagonal).
bool Contains(const VecType &point) const
Determines if a point is within this bound.
HRectBound & operator|=(const MatType &data)
Expands this region to include new points.
ElemType Overlap(const HRectBound &bound) const
Returns the volume of overlap of this bound and another.
HRectBound operator&(const HRectBound &bound) const
Returns the intersection of this bound and another.
math::RangeType< ElemType > & operator[](const size_t i)
Get the range for a particular dimension.
Definition: hrectbound.hpp:94
void Center(arma::Col< ElemType > &center) const
Calculates the center of the range, placing it into the given vector.
Hyper-rectangle bound for an L-metric.
Definition: hrectbound.hpp:54
HRectBound & operator=(const HRectBound &other)
Same as copy constructor; necessary to prevent memory leaks.
ElemType MaxDistance(const VecType &point, typename boost::enable_if< IsVector< VecType >> *=0) const
Calculates maximum bound-to-point squared distance.
const math::RangeType< ElemType > & operator[](const size_t i) const
Modify the range for a particular dimension. No bounds checking.
Definition: hrectbound.hpp:96
Definition of the Range class, which represents a simple range with a lower and upper bound...
ElemType Volume() const
Calculate the volume of the hyperrectangle.
HRectBound & operator&=(const HRectBound &bound)
Intersects this bound with another.
~HRectBound()
Destructor: clean up memory.
static const bool HasTightBounds
If true, then the bounds for each dimension are tight.
void Serialize(Archive &ar, const unsigned int version)
Serialize the bound object.
ElemType MinDistance(const VecType &point, typename boost::enable_if< IsVector< VecType >> *=0) const
Calculates minimum bound-to-point distance.
ElemType & MinWidth()
Modify the minimum width of the bound.
Definition: hrectbound.hpp:102
void Clear()
Resets all dimensions to the empty set (so that this bound contains nothing).
math::RangeType< ElemType > RangeDistance(const HRectBound &other) const
Calculates minimum and maximum bound-to-bound distance.
HRectBound()
Empty constructor; creates a bound of dimensionality 0.
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:35