mlpack 3.4.2
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
43namespace mlpack {
44namespace bound {
45
73template<typename MetricType = metric::LMetric<2, true>,
74 typename ElemType = double>
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
95 CellBound(const size_t dimension);
96
98 CellBound(const CellBound& other);
100 CellBound& operator=(const CellBound& other);
101
103 CellBound(CellBound&& other);
104
106 ~CellBound();
107
112 void Clear();
113
115 size_t Dim() const { return dim; }
116
119 math::RangeType<ElemType>& operator[](const size_t i) { return bounds[i]; }
121 const math::RangeType<ElemType>& operator[](const size_t i) const
122 { return bounds[i]; }
123
125 arma::Col<AddressElemType>& LoAddress() { return loAddress; }
127 const arma::Col<AddressElemType>& LoAddress() const {return loAddress; }
128
130 arma::Col<AddressElemType>& HiAddress() { return hiAddress; }
132 const arma::Col<AddressElemType>& HiAddress() const {return hiAddress; }
133
135 const arma::Mat<ElemType>& LoBound() const { return loBound; }
137 const arma::Mat<ElemType>& HiBound() const { return hiBound; }
138
140 size_t NumBounds() const { return numBounds; }
141
143 ElemType MinWidth() const { return minWidth; }
145 ElemType& MinWidth() { return minWidth; }
146
148 const MetricType& Metric() const { return metric; }
150 MetricType& Metric() { return metric; }
151
157 void Center(arma::Col<ElemType>& center) const;
158
164 template<typename VecType>
165 ElemType MinDistance(const VecType& point,
167 const;
168
174 ElemType MinDistance(const CellBound& other) const;
175
181 template<typename VecType>
182 ElemType MaxDistance(const VecType& point,
184 const;
185
191 ElemType MaxDistance(const CellBound& other) const;
192
199 math::RangeType<ElemType> RangeDistance(const CellBound& other) const;
200
207 template<typename VecType>
208 math::RangeType<ElemType> RangeDistance(
209 const VecType& point,
210 typename std::enable_if_t<IsVector<VecType>::value>* = 0) const;
211
219 template<typename MatType>
220 CellBound& operator|=(const MatType& data);
221
227 CellBound& operator|=(const CellBound& other);
228
234 template<typename VecType>
235 bool Contains(const VecType& point) const;
236
243 template<typename MatType>
244 void UpdateAddressBounds(const MatType& data);
245
249 ElemType Diameter() const;
250
254 template<typename Archive>
255 void serialize(Archive& ar, const unsigned int version);
256
257 private:
259 static constexpr size_t order = sizeof(AddressElemType) * CHAR_BIT;
261 const size_t maxNumBounds = 10;
263 size_t dim;
267 arma::Mat<ElemType> loBound;
269 arma::Mat<ElemType> hiBound;
271 size_t numBounds;
273 arma::Col<AddressElemType> loAddress;
275 arma::Col<AddressElemType> hiAddress;
277 ElemType minWidth;
279 MetricType metric;
280
288 template<typename MatType>
289 void AddBound(const arma::Col<ElemType>& loCorner,
290 const arma::Col<ElemType>& hiCorner,
291 const MatType& data);
300 template<typename MatType>
301 void InitHighBound(size_t numEqualBits, const MatType& data);
302
311 template<typename MatType>
312 void InitLowerBound(size_t numEqualBits, const MatType& data);
313};
314
315// A specialization of BoundTraits for this class.
316template<typename MetricType, typename ElemType>
317struct BoundTraits<CellBound<MetricType, ElemType>>
318{
320 const static bool HasTightBounds = true;
321};
322
323} // namespace bound
324} // namespace mlpack
325
326#include "cellbound_impl.hpp"
327
328#endif // MLPACK_CORE_TREE_CELLBOUND_HPP
329
The CellBound class describes a bound that consists of a number of hyperrectangles.
Definition: cellbound.hpp:76
Simple real-valued range.
Definition: range.hpp:35
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
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 ...
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
typename enable_if< B, T >::type enable_if_t
Definition: prereqs.hpp:70
The core includes that mlpack expects; standard C++ includes and Armadillo.
Definition of the Range class, which represents a simple range with a lower and upper bound.
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:36
A class to obtain compile-time traits about BoundType classes.
static const bool HasTightBounds
If true, then the bounds for each dimension are tight.