geometric_median#

skfda.exploratory.stats.geometric_median(X, *, tol=1e-08, metric=LpDistance(p=2, vector_norm=None))[source]#

Compute the geometric median.

The sample geometric median is the point that minimizes the \(L_1\) norm of the vector of distances to all observations:

\[\underset{y \in L(\mathcal{T})}{\arg \min} \sum_{i=1}^N \left \| x_i-y \right \|\]

The geometric median in the functional case is also described in [1]. Instead of the proposed algorithm, however, the current implementation uses the corrected Weiszfeld algorithm to compute the median.

Parameters:
  • X (T) – Object containing different samples of a functional variable.

  • tol (float) – tolerance used to check convergence.

  • metric (Metric[T]) – metric used to compute the vector of distances. By default is the \(L_2\) distance.

Returns:

Object containing the computed geometric median.

Return type:

T

Example

>>> from skfda import FDataGrid
>>> data_matrix = [[0.5, 1, 2, .5], [1.5, 1, 4, .5]]
>>> X = FDataGrid(data_matrix)
>>> median = geometric_median(X)
>>> median.data_matrix[0, ..., 0]
array([ 1. ,  1. ,  3. ,  0.5])

References