# geo_median: Geometric Median In pracma: Practical Numerical Math Functions

## Description

Compute the “geometric median” of points in n-dimensional space, that is the point with the least sum of (Euclidean) distances to all these points.

## Usage

 `1` ```geo_median(P, tol = 1e-07, maxiter = 200) ```

## Arguments

 `P` matrix of points, `x_i`-coordinates in the ith column. `tol` relative tolerance. `maxiter` maximum number of iterations.

## Details

The task is solved applying an iterative process, known as Weiszfeld's algorithm. The solution is unique whenever the points are not collinear.

If the dimension is 1 (one column), the median will be returned.

## Value

Returns a list with components `p` the coordinates of the solution point, `d` the sum of distances to all the sample points, `reltol` the relative tolerance of the iterative process, and `niter` the number of iterations.

## Note

This is also known as the “1-median problem” and can be generalized to the “k-median problem” for k cluster centers; see `kcca` in the ‘flexclust’ package.

## References

See Wikipedia's entry on “Geometric median”.

`L1linreg`

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13``` ```# Generate 100 points on the unit sphere in the 10-dim. space set.seed(1001) P <- rands(n=100, N=9) ( sol <- geo_median(P) ) # \$p # [1] -0.009481361 -0.007643410 -0.001252910 0.006437703 -0.019982885 -0.045337987 # [7] 0.036249563 0.003232175 0.035040592 0.046713023 # \$d # [1] 99.6638 # \$reltol # [1] 3.069063e-08 # \$niter # [1] 10 ```

### Example output

```\$p
[1] -0.009481361 -0.007643410 -0.001252910  0.006437703 -0.019982885
[6] -0.045337987  0.036249563  0.003232175  0.035040592  0.046713023

\$d
[1] 99.6638

\$reltol
[1] 3.069063e-08

\$niter
[1] 10
```

pracma documentation built on Dec. 11, 2021, 9:57 a.m.