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
double MinWidth() const
Get the minimum width of the bound.
Definition: hrectbound.hpp:101
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.
~HRectBound()
Destructor: clean up memory.
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
math::Range RangeDistance(const HRectBound &other) const
Calculates minimum and maximum bound-to-bound distance.
size_t Dim() const
Gets the dimensionality.
Definition: hrectbound.hpp:92
void Serialize(Archive &ar, const unsigned int version)
Serialize the bound object.
double Diameter() const
Returns the diameter of the hyperrectangle (that is, the longest diagonal).
math::Range * bounds
The bounds for each dimension.
Definition: hrectbound.hpp:206
Hyper-rectangle bound for an L-metric.
Definition: hrectbound.hpp:56
void Clear()
Resets all dimensions to the empty set (so that this bound contains nothing).
HRectBound()
Empty constructor; creates a bound of dimensionality 0.
Simple real-valued range.
Definition: range.hpp:21
HRectBound & operator|=(const MatType &data)
Expands this region to include new points.
double MaxDistance(const VecType &point, typename boost::enable_if< IsVector< VecType > > *=0) const
Calculates maximum bound-to-point squared distance.
double MinDistance(const VecType &point, typename boost::enable_if< IsVector< VecType > > *=0) const
Calculates minimum bound-to-point distance.
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
double Volume() const
Calculate the volume of the hyperrectangle.
void Center(arma::vec &center) const
Calculates the center of the range, placing it into the given vector.
Definition of the Range class, which represents a simple range with a lower and upper bound...
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
bool Contains(const VecType &point) const
Determines if a point is within this bound.
static const bool HasTightBounds
If true, then the bounds for each dimension are tight.
HRectBound & operator=(const HRectBound &other)
Same as copy constructor; necessary to prevent memory leaks.
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:37