37 #ifndef OMPL_DATASTRUCTURES_GREEDY_K_CENTERS_
38 #define OMPL_DATASTRUCTURES_GREEDY_K_CENTERS_
40 #include "ompl/util/RandomNumbers.h"
49 template <
typename _T>
56 using Matrix = Eigen::MatrixXd;
58 GreedyKCenters() =
default;
60 virtual ~GreedyKCenters() =
default;
82 void kcenters(
const std::vector<_T> &data,
unsigned int k, std::vector<unsigned int> ¢ers,
Matrix &dists)
86 std::vector<double> minDist(data.size(), std::numeric_limits<double>::infinity());
90 if ((std::size_t)dists.rows() < data.size() || (std::size_t)dists.cols() < k)
91 dists.resize(std::max(2u * (std::size_t)dists.rows() + 1u, data.size()), k);
94 for (
unsigned i = 1; i < k; ++i)
97 const _T ¢er = data[centers[i - 1]];
98 double maxDist = -std::numeric_limits<double>::infinity();
99 for (
unsigned j = 0; j < data.size(); ++j)
101 if ((dists(j, i - 1) =
distFun_(data[j], center)) < minDist[j])
102 minDist[j] = dists(j, i - 1);
104 if (minDist[j] > maxDist)
107 maxDist = minDist[j];
111 if (maxDist < std::numeric_limits<double>::epsilon())
113 centers.push_back(ind);
116 const _T ¢er = data[centers.back()];
117 unsigned i = centers.size() - 1;
118 for (
unsigned j = 0; j < data.size(); ++j)
119 dists(j, i) =
distFun_(data[j], center);
Random number generation. An instance of this class cannot be used by multiple threads at once (membe...
Eigen::MatrixXd Matrix
A matrix type for storing distances between points and centers.
const DistanceFunction & getDistanceFunction() const
Get the distance function used.
void setDistanceFunction(const DistanceFunction &distFun)
Set the distance function to use.
void kcenters(const std::vector< _T > &data, unsigned int k, std::vector< unsigned int > ¢ers, Matrix &dists)
Greedy algorithm for selecting k centers.
int uniformInt(int lower_bound, int upper_bound)
Generate a random integer within given bounds: [lower_bound, upper_bound].
std::function< double(const _T &, const _T &)> DistanceFunction
The definition of a distance function.
DistanceFunction distFun_
The used distance function.
Main namespace. Contains everything in this library.