mlpack  master
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,
126  const;
127 
133  ElemType MinDistance(const HRectBound& other) const;
134 
140  template<typename VecType>
141  ElemType MaxDistance(const VecType& point,
143  const;
144 
150  ElemType MaxDistance(const HRectBound& other) const;
151 
158  math::RangeType<ElemType> RangeDistance(const HRectBound& other) const;
159 
166  template<typename VecType>
167  math::RangeType<ElemType> RangeDistance(
168  const VecType& point,
169  typename std::enable_if_t<IsVector<VecType>::value>* = 0) const;
170 
178  template<typename MatType>
179  HRectBound& operator|=(const MatType& data);
180 
184  HRectBound& operator|=(const HRectBound& other);
185 
189  template<typename VecType>
190  bool Contains(const VecType& point) const;
191 
195  bool Contains(const HRectBound& bound) const;
196 
200  HRectBound operator&(const HRectBound& bound) const;
201 
205  HRectBound& operator&=(const HRectBound& bound);
206 
210  ElemType Overlap(const HRectBound& bound) const;
211 
215  ElemType Diameter() const;
216 
220  template<typename Archive>
221  void Serialize(Archive& ar, const unsigned int version);
222 
223  private:
225  size_t dim;
229  ElemType minWidth;
230 };
231 
232 // A specialization of BoundTraits for this class.
233 template<typename MetricType, typename ElemType>
234 struct BoundTraits<HRectBound<MetricType, ElemType>>
235 {
237  const static bool HasTightBounds = true;
238 };
239 
240 } // namespace bound
241 } // namespace mlpack
242 
243 #include "hrectbound_impl.hpp"
244 
245 #endif // MLPACK_CORE_TREE_HRECTBOUND_HPP
ElemType MinWidth() const
Get the minimum width of the bound.
Definition: hrectbound.hpp:100
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
const math::RangeType< ElemType > & operator[](const size_t i) const
Modify the range for a particular dimension. No bounds checking.
Definition: hrectbound.hpp:96
A class to obtain compile-time traits about BoundType classes.
size_t Dim() const
Gets the dimensionality.
Definition: hrectbound.hpp:90
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
Archive & operator&(Archive &ar, FirstShim< T > t)
Catch when we call operator& with a FirstShim object.
math::RangeType< ElemType > & operator[](const size_t i)
Get the range for a particular dimension.
Definition: hrectbound.hpp:94
math::RangeType< ElemType > * bounds
The bounds for each dimension.
Definition: hrectbound.hpp:227
size_t dim
The dimensionality of the bound.
Definition: hrectbound.hpp:225
Hyper-rectangle bound for an L-metric.
Definition: hrectbound.hpp:54
ElemType minWidth
Cached minimum width of bound.
Definition: hrectbound.hpp:229
ElemType & MinWidth()
Modify the minimum width of the bound.
Definition: hrectbound.hpp:102
bool Contains(const AddressType1 &address, const AddressType2 &loBound, const AddressType3 &hiBound)
Returns true if an address is contained between two other addresses.
Definition: address.hpp:256
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 ...
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:35
typename enable_if< B, T >::type enable_if_t
Definition: prereqs.hpp:59