mlpack
hollow_ball_bound.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_TREE_HOLLOW_BALL_BOUND_HPP
13 #define MLPACK_CORE_TREE_HOLLOW_BALL_BOUND_HPP
14 
15 #include <mlpack/prereqs.hpp>
17 #include "bound_traits.hpp"
18 
19 namespace mlpack {
20 namespace bound {
21 
31 template<typename TMetricType = metric::LMetric<2, true>,
32  typename ElemType = double>
34 {
35  public:
37  typedef TMetricType MetricType;
38 
39  private:
43  arma::Col<ElemType> center;
45  arma::Col<ElemType> hollowCenter;
47  MetricType* metric;
48 
55  bool ownsMetric;
56 
57  public:
60 
66  HollowBallBound(const size_t dimension);
67 
75  template<typename VecType>
76  HollowBallBound(const ElemType innerRadius,
77  const ElemType outerRadius,
78  const VecType& center);
79 
81  HollowBallBound(const HollowBallBound& other);
82 
85 
88 
91 
94 
96  ElemType OuterRadius() const { return radii.Hi(); }
98  ElemType& OuterRadius() { return radii.Hi(); }
99 
101  ElemType InnerRadius() const { return radii.Lo(); }
103  ElemType& InnerRadius() { return radii.Lo(); }
104 
106  const arma::Col<ElemType>& Center() const { return center; }
108  arma::Col<ElemType>& Center() { return center; }
109 
111  const arma::Col<ElemType>& HollowCenter() const { return hollowCenter; }
113  arma::Col<ElemType>& HollowCenter() { return hollowCenter; }
114 
116  size_t Dim() const { return center.n_elem; }
117 
122  ElemType MinWidth() const { return radii.Hi() * 2.0; }
123 
125  math::RangeType<ElemType> operator[](const size_t i) const;
126 
132  template<typename VecType>
133  bool Contains(const VecType& point) const;
134 
140  bool Contains(const HollowBallBound& other) const;
141 
147  template<typename VecType>
148  void Center(VecType& center) const { center = this->center; }
149 
155  template<typename VecType>
156  ElemType MinDistance(const VecType& point,
157  typename std::enable_if_t<IsVector<VecType>::value>* = 0)
158  const;
159 
165  ElemType MinDistance(const HollowBallBound& other) const;
166 
172  template<typename VecType>
173  ElemType MaxDistance(const VecType& point,
174  typename std::enable_if_t<IsVector<VecType>::value>* = 0)
175  const;
176 
182  ElemType MaxDistance(const HollowBallBound& other) const;
183 
190  template<typename VecType>
192  const VecType& other,
193  typename std::enable_if_t<IsVector<VecType>::value>* = 0) const;
194 
204 
213  template<typename MatType>
214  const HollowBallBound& operator|=(const MatType& data);
215 
224  const HollowBallBound& operator|=(const HollowBallBound& other);
225 
229  ElemType Diameter() const { return 2 * radii.Hi(); }
230 
232  const MetricType& Metric() const { return *metric; }
234  MetricType& Metric() { return *metric; }
235 
237  template<typename Archive>
238  void serialize(Archive& ar, const uint32_t version);
239 };
240 
242 template<typename MetricType, typename ElemType>
244 {
246  const static bool HasTightBounds = false;
247 };
248 
249 } // namespace bound
250 } // namespace mlpack
251 
253 
254 #endif // MLPACK_CORE_TREE_HOLLOW_BALL_BOUND_HPP
T Lo() const
Get the lower bound.
Definition: range.hpp:61
arma::Col< ElemType > & HollowCenter()
Modify the center point of the hollow.
Definition: hollow_ball_bound.hpp:113
MetricType & Metric()
Modify the distance metric used in this bound.
Definition: hollow_ball_bound.hpp:234
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
A class to obtain compile-time traits about BoundType classes.
Definition: bound_traits.hpp:26
bool Contains(const VecType &point) const
Determines if a point is within this bound.
Definition: hollow_ball_bound_impl.hpp:163
Bounds that are useful for binary space partitioning trees.
The core includes that mlpack expects; standard C++ includes and Armadillo.
TMetricType MetricType
A public version of the metric type.
Definition: hollow_ball_bound.hpp:37
arma::Col< ElemType > & Center()
Modify the center point of the ball.
Definition: hollow_ball_bound.hpp:108
const arma::Col< ElemType > & HollowCenter() const
Get the center point of the hollow.
Definition: hollow_ball_bound.hpp:111
ElemType & OuterRadius()
Modify the outer radius of the ball.
Definition: hollow_ball_bound.hpp:98
HollowBallBound()
Empty Constructor.
Definition: hollow_ball_bound_impl.hpp:23
const arma::Col< ElemType > & Center() const
Get the center point of the ball.
Definition: hollow_ball_bound.hpp:106
const HollowBallBound & operator|=(const MatType &data)
Expand the bound to include the given point.
ElemType & InnerRadius()
Modify the inner radius of the ball.
Definition: hollow_ball_bound.hpp:103
ElemType OuterRadius() const
Get the outer radius of the ball.
Definition: hollow_ball_bound.hpp:96
~HollowBallBound()
Destructor to release allocated memory.
Definition: hollow_ball_bound_impl.hpp:141
ElemType MinWidth() const
Get the minimum width of the bound (this is same as the diameter).
Definition: hollow_ball_bound.hpp:122
math::RangeType< ElemType > operator[](const size_t i) const
Get the range in a certain dimension.
Definition: hollow_ball_bound_impl.hpp:149
void serialize(Archive &ar, const uint32_t version)
Serialize the bound.
Definition: hollow_ball_bound_impl.hpp:453
const MetricType & Metric() const
Returns the distance metric used in this bound.
Definition: hollow_ball_bound.hpp:232
HollowBallBound & operator=(const HollowBallBound &other)
For the same reason as the copy constructor: to prevent memory leaks.
Definition: hollow_ball_bound_impl.hpp:81
T Hi() const
Get the upper bound.
Definition: range.hpp:66
ElemType Diameter() const
Returns the diameter of the ballbound.
Definition: hollow_ball_bound.hpp:229
ElemType MaxDistance(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Computes maximum distance.
Definition: hollow_ball_bound_impl.hpp:280
ElemType InnerRadius() const
Get the innner radius of the ball.
Definition: hollow_ball_bound.hpp:101
ElemType MinDistance(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Calculates minimum bound-to-point squared distance.
Definition: hollow_ball_bound_impl.hpp:221
Hollow ball bound encloses a set of points at a specific distance (radius) from a specific point (cen...
Definition: hollow_ball_bound.hpp:33
math::RangeType< ElemType > RangeDistance(const VecType &other, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Calculates minimum and maximum bound-to-point distance.
Definition: hollow_ball_bound_impl.hpp:312
void Center(VecType &center) const
Place the center of BallBound into the given vector.
Definition: hollow_ball_bound.hpp:148
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:35
size_t Dim() const
Get the dimensionality of the ball.
Definition: hollow_ball_bound.hpp:116