Template Class GreedyKCenters

Class Documentation

template<typename _T>
class GreedyKCenters

An instance of this class can be used to greedily select a given number of representatives from a set of data points that are all far apart from each other.

Public Types

using DistanceFunction = std::function<double(const _T&, const _T&)>

The definition of a distance function.

using Matrix = Eigen::MatrixXd

A matrix type for storing distances between points and centers.

Public Functions

GreedyKCenters() = default
virtual ~GreedyKCenters() = default
inline void setDistanceFunction(const DistanceFunction &distFun)

Set the distance function to use.

inline const DistanceFunction &getDistanceFunction() const

Get the distance function used.

inline void kcenters(const std::vector<_T> &data, unsigned int k, std::vector<unsigned int> &centers, Matrix &dists)

Greedy algorithm for selecting k centers.

Parameters:
  • data – a vector of data points

  • k – the desired number of centers

  • centers – a vector of length k containing the indices into data of the k centers

  • dists – a matrix such that dists(i,j) is the distance between data[i] and data[center[j]]

Protected Attributes

DistanceFunction distFun_

The used distance function.

RNG rng_

Random number generator used to select first center