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:
64  HRectBound();
65 
72  HRectBound(const size_t dimension);
73 
75  HRectBound(const HRectBound& other);
76 
78  HRectBound& operator=(const HRectBound& other);
79 
81  HRectBound(HRectBound&& other);
82 
84  HRectBound& operator=(HRectBound&& other);
85 
87  ~HRectBound();
88 
93  void Clear();
94 
96  size_t Dim() const { return dim; }
97 
100  math::RangeType<ElemType>& operator[](const size_t i) { return bounds[i]; }
102  const math::RangeType<ElemType>& operator[](const size_t i) const
103  { return bounds[i]; }
104 
106  ElemType MinWidth() const { return minWidth; }
108  ElemType& MinWidth() { return minWidth; }
109 
111  const MetricType& Metric() const { return metric; }
113  MetricType& Metric() { return metric; }
114 
120  void Center(arma::Col<ElemType>& center) const;
121 
127  ElemType Volume() const;
128 
134  template<typename VecType>
135  ElemType MinDistance(const VecType& point,
137  const;
138 
144  ElemType MinDistance(const HRectBound& other) const;
145 
151  template<typename VecType>
152  ElemType MaxDistance(const VecType& point,
154  const;
155 
161  ElemType MaxDistance(const HRectBound& other) const;
162 
169  math::RangeType<ElemType> RangeDistance(const HRectBound& other) const;
170 
177  template<typename VecType>
178  math::RangeType<ElemType> RangeDistance(
179  const VecType& point,
180  typename std::enable_if_t<IsVector<VecType>::value>* = 0) const;
181 
189  template<typename MatType>
190  HRectBound& operator|=(const MatType& data);
191 
195  HRectBound& operator|=(const HRectBound& other);
196 
202  template<typename VecType>
203  bool Contains(const VecType& point) const;
204 
210  bool Contains(const HRectBound& bound) const;
211 
215  HRectBound operator&(const HRectBound& bound) const;
216 
220  HRectBound& operator&=(const HRectBound& bound);
221 
225  ElemType Overlap(const HRectBound& bound) const;
226 
230  ElemType Diameter() const;
231 
235  template<typename Archive>
236  void serialize(Archive& ar, const uint32_t version);
237 
238  private:
240  size_t dim;
244  ElemType minWidth;
246  MetricType metric;
247 };
248 
249 // A specialization of BoundTraits for this class.
250 template<typename MetricType, typename ElemType>
251 struct BoundTraits<HRectBound<MetricType, ElemType>>
252 {
254  const static bool HasTightBounds = true;
255 };
256 
257 } // namespace bound
258 } // namespace mlpack
259 
260 #include "hrectbound_impl.hpp"
261 
262 #endif // MLPACK_CORE_TREE_HRECTBOUND_HPP
typename enable_if< B, T >::type enable_if_t
Definition: prereqs.hpp:70
Linear algebra utility functions, generally performed on matrices or vectors.
A class to obtain compile-time traits about BoundType classes.
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 MinWidth() const
Get the minimum width of the bound.
Definition: hrectbound.hpp:106
const math::RangeType< ElemType > & operator[](const size_t i) const
Modify the range for a particular dimension. No bounds checking.
Definition: hrectbound.hpp:102
math::RangeType< ElemType > & operator[](const size_t i)
Get the range for a particular dimension.
Definition: hrectbound.hpp:100
Hyper-rectangle bound for an L-metric.
Definition: hrectbound.hpp:54
MetricType & Metric()
Modify the instantiated metric associated with the bound.
Definition: hrectbound.hpp:113
size_t Dim() const
Gets the dimensionality.
Definition: hrectbound.hpp:96
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
const MetricType & Metric() const
Get the instantiated metric associated with the bound.
Definition: hrectbound.hpp:111
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 ...
ElemType & MinWidth()
Modify the minimum width of the bound.
Definition: hrectbound.hpp:108
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:35