mlpack  2.2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cellbound.hpp
Go to the documentation of this file.
1 
34 #ifndef MLPACK_CORE_TREE_CELLBOUND_HPP
35 #define MLPACK_CORE_TREE_CELLBOUND_HPP
36 
37 #include <mlpack/prereqs.hpp>
40 #include "bound_traits.hpp"
41 #include "address.hpp"
42 
43 namespace mlpack {
44 namespace bound {
45 
73 template<typename MetricType = metric::LMetric<2, true>,
74  typename ElemType = double>
75 class CellBound
76 {
77  public:
80  typedef typename std::conditional<sizeof(ElemType) * CHAR_BIT <= 32,
81  uint32_t,
82  uint64_t>::type AddressElemType;
83 
87  CellBound();
88 
93  CellBound(const size_t dimension);
94 
96  CellBound(const CellBound& other);
98  CellBound& operator=(const CellBound& other);
99 
101  CellBound(CellBound&& other);
102 
104  ~CellBound();
105 
110  void Clear();
111 
113  size_t Dim() const { return dim; }
114 
117  math::RangeType<ElemType>& operator[](const size_t i) { return bounds[i]; }
119  const math::RangeType<ElemType>& operator[](const size_t i) const
120  { return bounds[i]; }
121 
123  arma::Col<AddressElemType>& LoAddress() { return loAddress; }
125  const arma::Col<AddressElemType>& LoAddress() const {return loAddress; }
126 
128  arma::Col<AddressElemType>& HiAddress() { return hiAddress; }
130  const arma::Col<AddressElemType>& HiAddress() const {return hiAddress; }
131 
133  const arma::Mat<ElemType>& LoBound() const { return loBound; }
135  const arma::Mat<ElemType>& HiBound() const { return hiBound; }
136 
138  size_t NumBounds() const { return numBounds; }
139 
141  ElemType MinWidth() const { return minWidth; }
143  ElemType& MinWidth() { return minWidth; }
144 
150  void Center(arma::Col<ElemType>& center) const;
151 
157  template<typename VecType>
158  ElemType MinDistance(const VecType& point,
159  typename boost::enable_if<IsVector<VecType>>* = 0) const;
160 
166  ElemType MinDistance(const CellBound& other) const;
167 
173  template<typename VecType>
174  ElemType MaxDistance(const VecType& point,
175  typename boost::enable_if<IsVector<VecType>>* = 0) const;
176 
182  ElemType MaxDistance(const CellBound& other) const;
183 
190  math::RangeType<ElemType> RangeDistance(const CellBound& other) const;
191 
198  template<typename VecType>
199  math::RangeType<ElemType> RangeDistance(
200  const VecType& point,
201  typename boost::enable_if<IsVector<VecType>>* = 0) const;
202 
210  template<typename MatType>
211  CellBound& operator|=(const MatType& data);
212 
216  CellBound& operator|=(const CellBound& other);
217 
221  template<typename VecType>
222  bool Contains(const VecType& point) const;
223 
230  template<typename MatType>
231  void UpdateAddressBounds(const MatType& data);
232 
236  ElemType Diameter() const;
237 
241  template<typename Archive>
242  void Serialize(Archive& ar, const unsigned int version);
243 
244  private:
246  static constexpr size_t order = sizeof(AddressElemType) * CHAR_BIT;
248  const size_t maxNumBounds = 10;
250  size_t dim;
254  arma::Mat<ElemType> loBound;
256  arma::Mat<ElemType> hiBound;
258  size_t numBounds;
260  arma::Col<AddressElemType> loAddress;
262  arma::Col<AddressElemType> hiAddress;
264  ElemType minWidth;
265 
273  template<typename MatType>
274  void AddBound(const arma::Col<ElemType>& loCorner,
275  const arma::Col<ElemType>& hiCorner,
276  const MatType& data);
285  template<typename MatType>
286  void InitHighBound(size_t numEqualBits, const MatType& data);
287 
296  template<typename MatType>
297  void InitLowerBound(size_t numEqualBits, const MatType& data);
298 };
299 
300 // A specialization of BoundTraits for this class.
301 template<typename MetricType, typename ElemType>
302 struct BoundTraits<CellBound<MetricType, ElemType>>
303 {
305  const static bool HasTightBounds = true;
306 };
307 
308 } // namespace bound
309 } // namespace mlpack
310 
311 #include "cellbound_impl.hpp"
312 
313 #endif // MLPACK_CORE_TREE_CELLBOUND_HPP
314 
A class to obtain compile-time traits about BoundType classes.
The CellBound class describes a bound that consists of a number of hyperrectangles.
Definition: cellbound.hpp:75
The core includes that mlpack expects; standard C++ includes and Armadillo.
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 ...
static const bool HasTightBounds
If true, then the bounds for each dimension are tight.
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:35