mlpack  master
random_point_selection.hpp
Go to the documentation of this file.
1 
7 #ifndef MLPACK_METHODS_DBSCAN_RANDOM_POINT_SELECTION_HPP
8 #define MLPACK_METHODS_DBSCAN_RANDOM_POINT_SELECTION_HPP
9 
10 #include <mlpack/prereqs.hpp>
11 #include <boost/dynamic_bitset.hpp>
12 
13 namespace mlpack {
14 namespace dbscan {
15 
20 {
21  public:
28  template<typename MatType>
29  static size_t Select(const boost::dynamic_bitset<>& unvisited,
30  const MatType& /* data */)
31  {
32  const size_t max = unvisited.count();
33  const size_t index = math::RandInt(max);
34 
35  // Select the index'th unvisited point.
36  size_t found = 0;
37  for (size_t i = 0; i < unvisited.size(); ++i)
38  {
39  if (unvisited[i])
40  ++found;
41 
42  if (found > index)
43  return i;
44  }
45 
46  return 0; // Not sure if it is possible to get here.
47  }
48 };
49 
50 } // namespace dbscan
51 } // namespace mlpack
52 
53 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
The core includes that mlpack expects; standard C++ includes and Armadillo.
int RandInt(const int hiExclusive)
Generates a uniform random integer.
Definition: random.hpp:71
This class can be used to randomly select the next point to use for DBSCAN.
static size_t Select(const boost::dynamic_bitset<> &unvisited, const MatType &)
Select the next point to use, randomly.