mlpack  2.2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
random_point_selection.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_DBSCAN_RANDOM_POINT_SELECTION_HPP
13 #define MLPACK_METHODS_DBSCAN_RANDOM_POINT_SELECTION_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 #include <boost/dynamic_bitset.hpp>
17 
18 namespace mlpack {
19 namespace dbscan {
20 
25 {
26  public:
33  template<typename MatType>
34  static size_t Select(const boost::dynamic_bitset<>& unvisited,
35  const MatType& /* data */)
36  {
37  const size_t max = unvisited.count();
38  const size_t index = math::RandInt(max);
39 
40  // Select the index'th unvisited point.
41  size_t found = 0;
42  for (size_t i = 0; i < unvisited.size(); ++i)
43  {
44  if (unvisited[i])
45  ++found;
46 
47  if (found > index)
48  return i;
49  }
50 
51  return 0; // Not sure if it is possible to get here.
52  }
53 };
54 
55 } // namespace dbscan
56 } // namespace mlpack
57 
58 #endif
The core includes that mlpack expects; standard C++ includes and Armadillo.
static size_t Select(const boost::dynamic_bitset<> &unvisited, const MatType &)
Select the next point to use, randomly.
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.