mlpack  1.0.12
ballbound.hpp
Go to the documentation of this file.
1 
15 #ifndef __MLPACK_CORE_TREE_BALLBOUND_HPP
16 #define __MLPACK_CORE_TREE_BALLBOUND_HPP
17 
18 #include <mlpack/core.hpp>
20 
21 namespace mlpack {
22 namespace bound {
23 
32 template<typename VecType = arma::vec,
33  typename TMetricType = metric::LMetric<2, true> >
34 class BallBound
35 {
36  public:
37  typedef VecType Vec;
39  typedef TMetricType MetricType;
40 
41  private:
42 
44  double radius;
45 
47  VecType center;
48 
50  TMetricType* metric;
51 
58  bool ownsMetric;
59 
60  public:
61 
63  BallBound();
64 
70  BallBound(const size_t dimension);
71 
78  BallBound(const double radius, const VecType& center);
79 
81  BallBound(const BallBound& other);
82 
84  BallBound& operator=(const BallBound& other);
85 
87  ~BallBound();
88 
90  double Radius() const { return radius; }
92  double& Radius() { return radius; }
93 
95  const VecType& Center() const { return center; }
97  VecType& Center() { return center; }
98 
100  double Dim() const { return center.n_elem; }
101 
106  double MinWidth() const { return radius * 2.0; }
107 
109  math::Range operator[](const size_t i) const;
110 
114  bool Contains(const VecType& point) const;
115 
121  void Centroid(VecType& centroid) const { centroid = center; }
122 
126  template<typename OtherVecType>
127  double MinDistance(const OtherVecType& point,
128  typename boost::enable_if<IsVector<OtherVecType> >* = 0)
129  const;
130 
134  double MinDistance(const BallBound& other) const;
135 
139  template<typename OtherVecType>
140  double MaxDistance(const OtherVecType& point,
141  typename boost::enable_if<IsVector<OtherVecType> >* = 0)
142  const;
143 
147  double MaxDistance(const BallBound& other) const;
148 
152  template<typename OtherVecType>
154  const OtherVecType& other,
155  typename boost::enable_if<IsVector<OtherVecType> >* = 0) const;
156 
162  math::Range RangeDistance(const BallBound& other) const;
163 
167  const BallBound& operator|=(const BallBound& other);
168 
177  template<typename MatType>
178  const BallBound& operator|=(const MatType& data);
179 
183  double Diameter() const { return 2 * radius; }
184 
188  TMetricType Metric() const { return *metric; }
189 
193  std::string ToString() const;
194 
195 };
196 
197 }; // namespace bound
198 }; // namespace mlpack
199 
200 #include "ballbound_impl.hpp"
201 
202 #endif // __MLPACK_CORE_TREE_DBALLBOUND_HPP
bool Contains(const VecType &point) const
Determines if a point is within this bound.
BallBound()
Empty Constructor.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:23
const BallBound & operator|=(const BallBound &other)
Expand the bound to include the given node.
std::string ToString() const
Returns a string representation of this object.
void Centroid(VecType &centroid) const
Place the centroid of BallBound into the given vector.
Definition: ballbound.hpp:121
double MaxDistance(const OtherVecType &point, typename boost::enable_if< IsVector< OtherVecType > > *=0) const
Computes maximum distance.
math::Range operator[](const size_t i) const
Get the range in a certain dimension.
const VecType & Center() const
Get the center point of the ball.
Definition: ballbound.hpp:95
double Dim() const
Get the dimensionality of the ball.
Definition: ballbound.hpp:100
Ball bound encloses a set of points at a specific distance (radius) from a specific point (center)...
Definition: ballbound.hpp:34
BallBound & operator=(const BallBound &other)
For the same reason as the Copy Constructor. To prevent memory leaks.
bool ownsMetric
To know whether this object allocated memory to the metric member variable.
Definition: ballbound.hpp:58
double MinDistance(const OtherVecType &point, typename boost::enable_if< IsVector< OtherVecType > > *=0) const
Calculates minimum bound-to-point squared distance.
double Diameter() const
Returns the diameter of the ballbound.
Definition: ballbound.hpp:183
VecType & Center()
Modify the center point of the ball.
Definition: ballbound.hpp:97
TMetricType MetricType
Need this for Binary Space Partion Tree.
Definition: ballbound.hpp:39
math::Range RangeDistance(const OtherVecType &other, typename boost::enable_if< IsVector< OtherVecType > > *=0) const
Calculates minimum and maximum bound-to-point distance.
double radius
The radius of the ball bound.
Definition: ballbound.hpp:44
The L_p metric for arbitrary integer p, with an option to take the root.
Definition: lmetric.hpp:65
double MinWidth() const
Get the minimum width of the bound (this is same as the diameter).
Definition: ballbound.hpp:106
~BallBound()
Destructor to release allocated memory.
TMetricType * metric
The metric used in this bound.
Definition: ballbound.hpp:50
TMetricType Metric() const
Returns the distance metric used in this bound.
Definition: ballbound.hpp:188
VecType center
The center of the ball bound.
Definition: ballbound.hpp:47
double & Radius()
Modify the radius of the ball.
Definition: ballbound.hpp:92
double Radius() const
Get the radius of the ball.
Definition: ballbound.hpp:90
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:37
Simple real-valued range.
Definition: range.hpp:23