mlpack  master
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:
58 
61 
67  HollowBallBound(const size_t dimension);
68 
76  template<typename VecType>
77  HollowBallBound(const ElemType innerRadius,
78  const ElemType outerRadius,
79  const VecType& center);
80 
82  HollowBallBound(const HollowBallBound& other);
83 
86 
89 
92 
94  ElemType OuterRadius() const { return radii.Hi(); }
96  ElemType& OuterRadius() { return radii.Hi(); }
97 
99  ElemType InnerRadius() const { return radii.Lo(); }
101  ElemType& InnerRadius() { return radii.Lo(); }
102 
104  const arma::Col<ElemType>& Center() const { return center; }
106  arma::Col<ElemType>& Center() { return center; }
107 
109  const arma::Col<ElemType>& HollowCenter() const { return hollowCenter; }
111  arma::Col<ElemType>& HollowCenter() { return hollowCenter; }
112 
114  size_t Dim() const { return center.n_elem; }
115 
120  ElemType MinWidth() const { return radii.Hi() * 2.0; }
121 
123  math::RangeType<ElemType> operator[](const size_t i) const;
124 
128  template<typename VecType>
129  bool Contains(const VecType& point) const;
130 
134  bool Contains(const HollowBallBound& other) const;
135 
141  template<typename VecType>
142  void Center(VecType& center) const { center = this->center; }
143 
147  template<typename VecType>
148  ElemType MinDistance(const VecType& point,
150  const;
151 
155  ElemType MinDistance(const HollowBallBound& other) const;
156 
160  template<typename VecType>
161  ElemType MaxDistance(const VecType& point,
163  const;
164 
168  ElemType MaxDistance(const HollowBallBound& other) const;
169 
173  template<typename VecType>
175  const VecType& other,
176  typename std::enable_if_t<IsVector<VecType>::value>* = 0) const;
177 
184 
193  template<typename MatType>
194  const HollowBallBound& operator|=(const MatType& data);
195 
204  const HollowBallBound& operator|=(const HollowBallBound& other);
205 
209  ElemType Diameter() const { return 2 * radii.Hi(); }
210 
212  const MetricType& Metric() const { return *metric; }
214  MetricType& Metric() { return *metric; }
215 
217  template<typename Archive>
218  void Serialize(Archive& ar, const unsigned int version);
219 };
220 
222 template<typename MetricType, typename ElemType>
224 {
226  const static bool HasTightBounds = false;
227 };
228 
229 } // namespace bound
230 } // namespace mlpack
231 
232 #include "hollow_ball_bound_impl.hpp"
233 
234 #endif // MLPACK_CORE_TREE_HOLLOW_BALL_BOUND_HPP
arma::Col< ElemType > center
The center of the ball bound.
size_t Dim() const
Get the dimensionality of the ball.
arma::Col< ElemType > & HollowCenter()
Modify the center point of the hollow.
MetricType & Metric()
Modify the distance metric used in this bound.
HollowBallBound & operator=(const HollowBallBound &other)
For the same reason as the copy constructor: to prevent memory leaks.
math::RangeType< ElemType > operator[](const size_t i) const
Get the range in a certain dimension.
bool Contains(const VecType &point) const
Determines if a point is within this bound.
ElemType MaxDistance(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Computes maximum distance.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
A class to obtain compile-time traits about BoundType classes.
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.
arma::Col< ElemType > hollowCenter
The center of the hollow.
The core includes that mlpack expects; standard C++ includes and Armadillo.
const MetricType & Metric() const
Returns the distance metric used in this bound.
TMetricType MetricType
A public version of the metric type.
arma::Col< ElemType > & Center()
Modify the center point of the ball.
ElemType InnerRadius() const
Get the innner radius of the ball.
ElemType MinDistance(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Calculates minimum bound-to-point squared distance.
ElemType & OuterRadius()
Modify the outer radius of the ball.
void Center(VecType &center) const
Place the center of BallBound into the given vector.
HollowBallBound()
Empty Constructor.
const HollowBallBound & operator|=(const MatType &data)
Expand the bound to include the given point.
ElemType & InnerRadius()
Modify the inner radius of the ball.
T Lo() const
Get the lower bound.
Definition: range.hpp:61
~HollowBallBound()
Destructor to release allocated memory.
math::RangeType< ElemType > radii
The inner and the outer radii of the bound.
MetricType * metric
The metric used in this bound.
ElemType Diameter() const
Returns the diameter of the ballbound.
ElemType MinWidth() const
Get the minimum width of the bound (this is same as the diameter).
bool ownsMetric
To know whether this object allocated memory to the metric member variable.
void Serialize(Archive &ar, const unsigned int version)
Serialize the bound.
ElemType OuterRadius() const
Get the outer radius of the ball.
T Hi() const
Get the upper bound.
Definition: range.hpp:66
Hollow ball bound encloses a set of points at a specific distance (radius) from a specific point (cen...
const arma::Col< ElemType > & Center() const
Get the center point of the ball.
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:35
const arma::Col< ElemType > & HollowCenter() const
Get the center point of the hollow.
typename enable_if< B, T >::type enable_if_t
Definition: prereqs.hpp:59