26 template<
typename ForwardIterator>
33 template<
typename ForwardIterator>
37 double eps = std::numeric_limits<double>::epsilon();
38 int dimension = begin->getDimension();
43 for (ForwardIterator it = begin; it != end; ++it)
46 weight += it->getWeight();
47 cog += weight * (*it);
49 cog = (1.0 / weight) * cog;
58 double lastDist = std::numeric_limits<double>::infinity();
60 while (running && iteration < max_iteration)
64 Point numerator(dimension);
65 double denominator = 0;
66 for (ForwardIterator it = begin; it != end; ++it)
68 double dist = metric->distance(*it, y);
74 double invdist = (1.0 / dist);
75 numerator += it->getWeight() * invdist * (*it);
76 denominator += it->getWeight() * invdist;
78 Point newPoint((1.0 / denominator) * numerator);
81 double currentDist = metric->distance(y, newPoint);
82 if (currentDist / lastDist > 0.10 || currentDist <= eps)
86 lastDist = currentDist;