mlpack  master
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,
160  const;
161 
167  ElemType MinDistance(const CellBound& other) const;
168 
174  template<typename VecType>
175  ElemType MaxDistance(const VecType& point,
177  const;
178 
184  ElemType MaxDistance(const CellBound& other) const;
185 
192  math::RangeType<ElemType> RangeDistance(const CellBound& other) const;
193 
200  template<typename VecType>
201  math::RangeType<ElemType> RangeDistance(
202  const VecType& point,
203  typename std::enable_if_t<IsVector<VecType>::value>* = 0) const;
204 
212  template<typename MatType>
213  CellBound& operator|=(const MatType& data);
214 
218  CellBound& operator|=(const CellBound& other);
219 
223  template<typename VecType>
224  bool Contains(const VecType& point) const;
225 
232  template<typename MatType>
233  void UpdateAddressBounds(const MatType& data);
234 
238  ElemType Diameter() const;
239 
243  template<typename Archive>
244  void Serialize(Archive& ar, const unsigned int version);
245 
246  private:
248  static constexpr size_t order = sizeof(AddressElemType) * CHAR_BIT;
250  const size_t maxNumBounds = 10;
252  size_t dim;
256  arma::Mat<ElemType> loBound;
258  arma::Mat<ElemType> hiBound;
260  size_t numBounds;
262  arma::Col<AddressElemType> loAddress;
264  arma::Col<AddressElemType> hiAddress;
266  ElemType minWidth;
267 
275  template<typename MatType>
276  void AddBound(const arma::Col<ElemType>& loCorner,
277  const arma::Col<ElemType>& hiCorner,
278  const MatType& data);
287  template<typename MatType>
288  void InitHighBound(size_t numEqualBits, const MatType& data);
289 
298  template<typename MatType>
299  void InitLowerBound(size_t numEqualBits, const MatType& data);
300 };
301 
302 // A specialization of BoundTraits for this class.
303 template<typename MetricType, typename ElemType>
304 struct BoundTraits<CellBound<MetricType, ElemType>>
305 {
307  const static bool HasTightBounds = true;
308 };
309 
310 } // namespace bound
311 } // namespace mlpack
312 
313 #include "cellbound_impl.hpp"
314 
315 #endif // MLPACK_CORE_TREE_CELLBOUND_HPP
316 
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
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 ...
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:35
typename enable_if< B, T >::type enable_if_t
Definition: prereqs.hpp:59