15 #ifndef PAAL_K_CENTER_HPP
16 #define PAAL_K_CENTER_HPP
41 template <
typename Metric,
class OutputIterator,
typename ItemIterator>
42 typename data_structures::metric_traits<Metric>::DistanceType
43 kCenter(
const Metric &metric,
unsigned int numberOfClusters,
44 const ItemIterator iBegin,
const ItemIterator iEnd,
45 OutputIterator result) {
48 std::vector<Dist> distance_from_closest_center(
49 std::distance(iBegin, iEnd), std::numeric_limits<Dist>::max());
50 ItemIterator last_centre = iBegin;
51 ItemIterator farthest_centre = iBegin;
53 assert(numberOfClusters > 0);
55 *result = *farthest_centre;
57 radius = std::numeric_limits<Dist>::min();
58 auto it = distance_from_closest_center.begin();
59 for (
auto i = iBegin; i != iEnd; ++i) {
67 last_centre = farthest_centre;
68 }
while (--numberOfClusters);
75 #endif // PAAL_K_CENTER_HPP
data_structures::metric_traits< Metric >::DistanceType kCenter(const Metric &metric, unsigned int numberOfClusters, const ItemIterator iBegin, const ItemIterator iEnd, OutputIterator result)
this is solve K Center problem and return radius example:
void assign_min(T &t, const T &u)