MLPACK  1.0.7
dtb.hpp
Go to the documentation of this file.
1 
35 #ifndef __MLPACK_METHODS_EMST_DTB_HPP
36 #define __MLPACK_METHODS_EMST_DTB_HPP
37 
38 #include "edge_pair.hpp"
39 
40 #include <mlpack/core.hpp>
42 
44 
45 namespace mlpack {
46 namespace emst {
47 
52 class DTBStat
53 {
54  private:
58 
62 
64  double bound;
65 
71 
72  public:
77  DTBStat();
78 
86  template<typename TreeType>
87  DTBStat(const TreeType& node);
88 
90  double MaxNeighborDistance() const { return maxNeighborDistance; }
93 
95  double MinNeighborDistance() const { return minNeighborDistance; }
98 
100  double Bound() const { return bound; }
102  double& Bound() { return bound; }
103 
105  int ComponentMembership() const { return componentMembership; }
108 
109 }; // class DTBStat
110 
149 template<
150  typename MetricType = metric::EuclideanDistance,
151  typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, DTBStat>
152 >
154 {
155  private:
157  typename TreeType::Mat dataCopy;
159  typename TreeType::Mat& data;
160 
162  TreeType* tree;
164  bool ownTree;
165 
167  bool naive;
168 
170  std::vector<EdgePair> edges; // We must use vector with non-numerical types.
171 
174 
176  std::vector<size_t> oldFromNew;
178  arma::Col<size_t> neighborsInComponent;
180  arma::Col<size_t> neighborsOutComponent;
183 
185  double totalDist;
186 
188  MetricType metric;
189 
192  {
193  bool operator()(const EdgePair& pairA, const EdgePair& pairB)
194  {
195  return (pairA.Distance() < pairB.Distance());
196  }
197  } SortFun;
198 
199  public:
208  DualTreeBoruvka(const typename TreeType::Mat& dataset,
209  const bool naive = false,
210  const size_t leafSize = 1,
211  const MetricType metric = MetricType());
212 
230  DualTreeBoruvka(TreeType* tree, const typename TreeType::Mat& dataset,
231  const MetricType metric = MetricType());
232 
237 
247  void ComputeMST(arma::mat& results);
248 
249  private:
253  void AddEdge(const size_t e1, const size_t e2, const double distance);
254 
258  void AddAllEdges();
259 
263  void EmitResults(arma::mat& results);
264 
269  void CleanupHelper(TreeType* tree);
270 
274  void Cleanup();
275 
276 }; // class DualTreeBoruvka
277 
278 }; // namespace emst
279 }; // namespace mlpack
280 
281 #include "dtb_impl.hpp"
282 
283 #endif // __MLPACK_METHODS_EMST_DTB_HPP