mlpack  3.4.2
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 meta
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:
65 
72  HRectBound(const size_t dimension);
73 
75  HRectBound(const HRectBound& other);
78 
81 
84 
89  void Clear();
90 
92  size_t Dim() const { return dim; }
93 
96  math::RangeType<ElemType>& operator[](const size_t i) { return bounds[i]; }
98  const math::RangeType<ElemType>& operator[](const size_t i) const
99  { return bounds[i]; }
100 
102  ElemType MinWidth() const { return minWidth; }
104  ElemType& MinWidth() { return minWidth; }
105 
107  const MetricType& Metric() const { return metric; }
109  MetricType& Metric() { return metric; }
110 
116  void Center(arma::Col<ElemType>& center) const;
117 
123  ElemType Volume() const;
124 
130  template<typename VecType>
131  ElemType MinDistance(const VecType& point,
133  const;
134 
140  ElemType MinDistance(const HRectBound& other) const;
141 
147  template<typename VecType>
148  ElemType MaxDistance(const VecType& point,
150  const;
151 
157  ElemType MaxDistance(const HRectBound& other) const;
158 
166 
173  template<typename VecType>
175  const VecType& point,
176  typename std::enable_if_t<IsVector<VecType>::value>* = 0) const;
177 
185  template<typename MatType>
186  HRectBound& operator|=(const MatType& data);
187 
192 
198  template<typename VecType>
199  bool Contains(const VecType& point) const;
200 
206  bool Contains(const HRectBound& bound) const;
207 
211  HRectBound operator&(const HRectBound& bound) const;
212 
217 
221  ElemType Overlap(const HRectBound& bound) const;
222 
226  ElemType Diameter() const;
227 
231  template<typename Archive>
232  void serialize(Archive& ar, const unsigned int version);
233 
234  private:
236  size_t dim;
240  ElemType minWidth;
242  MetricType metric;
243 };
244 
245 // A specialization of BoundTraits for this class.
246 template<typename MetricType, typename ElemType>
247 struct BoundTraits<HRectBound<MetricType, ElemType>>
248 {
250  const static bool HasTightBounds = true;
251 };
252 
253 } // namespace bound
254 } // namespace mlpack
255 
256 #include "hrectbound_impl.hpp"
257 
258 #endif // MLPACK_CORE_TREE_HRECTBOUND_HPP
Hyper-rectangle bound for an L-metric.
Definition: hrectbound.hpp:55
HRectBound()
Empty constructor; creates a bound of dimensionality 0.
HRectBound(const HRectBound &other)
Copy constructor; necessary to prevent memory leaks.
HRectBound & operator&=(const HRectBound &bound)
Intersects this bound with another.
ElemType & MinWidth()
Modify the minimum width of the bound.
Definition: hrectbound.hpp:104
ElemType Overlap(const HRectBound &bound) const
Returns the volume of overlap of this bound and another.
math::RangeType< ElemType > RangeDistance(const HRectBound &other) const
Calculates minimum and maximum bound-to-bound distance.
bool Contains(const VecType &point) const
Determines if a point is within this bound.
math::RangeType< ElemType > & operator[](const size_t i)
Get the range for a particular dimension.
Definition: hrectbound.hpp:96
const math::RangeType< ElemType > & operator[](const size_t i) const
Modify the range for a particular dimension. No bounds checking.
Definition: hrectbound.hpp:98
HRectBound(HRectBound &&other)
Move constructor: take possession of another bound's information.
math::RangeType< ElemType > RangeDistance(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Calculates minimum and maximum bound-to-point distance.
ElemType Diameter() const
Returns the diameter of the hyperrectangle (that is, the longest diagonal).
HRectBound(const size_t dimension)
Initializes to specified dimensionality with each dimension the empty set.
~HRectBound()
Destructor: clean up memory.
void serialize(Archive &ar, const unsigned int version)
Serialize the bound object.
HRectBound operator&(const HRectBound &bound) const
Returns the intersection of this bound and another.
ElemType MinDistance(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Calculates minimum bound-to-point distance.
HRectBound & operator|=(const HRectBound &other)
Expands this region to encompass another bound.
size_t Dim() const
Gets the dimensionality.
Definition: hrectbound.hpp:92
HRectBound & operator|=(const MatType &data)
Expands this region to include new points.
void Clear()
Resets all dimensions to the empty set (so that this bound contains nothing).
const MetricType & Metric() const
Get the instantiated metric associated with the bound.
Definition: hrectbound.hpp:107
ElemType MinWidth() const
Get the minimum width of the bound.
Definition: hrectbound.hpp:102
ElemType Volume() const
Calculate the volume of the hyperrectangle.
void Center(arma::Col< ElemType > &center) const
Calculates the center of the range, placing it into the given vector.
MetricType & Metric()
Modify the instantiated metric associated with the bound.
Definition: hrectbound.hpp:109
bool Contains(const HRectBound &bound) const
Determines if this bound partially contains a bound.
HRectBound & operator=(const HRectBound &other)
Same as copy constructor; necessary to prevent memory leaks.
ElemType MaxDistance(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Calculates maximum bound-to-point squared distance.
ElemType MinDistance(const HRectBound &other) const
Calculates minimum bound-to-bound distance.
ElemType MaxDistance(const HRectBound &other) const
Computes maximum distance.
Simple real-valued range.
Definition: range.hpp:35
Linear algebra utility functions, generally performed on matrices or vectors.
typename enable_if< B, T >::type enable_if_t
Definition: prereqs.hpp:70
The core includes that mlpack expects; standard C++ includes and Armadillo.
Definition of the Range class, which represents a simple range with a lower and upper bound.
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:36
A class to obtain compile-time traits about BoundType classes.
static const bool HasTightBounds
If true, then the bounds for each dimension are tight.
Utility struct where Value is true if and only if the argument is of type LMetric.
Definition: hrectbound.hpp:31