function* geometricMedianIterator(
points,
{ P = 1, alpha = 1, precision = 1e-6, x = 0, y = 0 } = {}
) {
let delta,
i = 0;
if (x === undefined) x = y = 0;
do {
let sx = 0;
let sy = 0;
let s = 0;
for (const p of points) {
const d = [x - p[0], y - p[1]];
const n = norm(d);
if (n) {
const np = pow(n, P - 2);
s += np;
sx += p[0] * np;
sy += p[1] * np;
}
}
yield [x, y];
const x_ = x,
y_ = y;
x += alpha * (sx / s - x);
y += alpha * (sy / s - y);
delta = abs(x - x_) + abs(y - y_);
} while (delta > precision && i++ < 1000);
return yield [x, y];
}