How to find out Geometric Median
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
The geometric median is a central point in a spatial dataset that minimizes the sum of Euclidean distances to all points in the set. Unlike the arithmetic mean, the geometric median is less sensitive to outliers, making it particularly useful in applications such as facility location, robust statistics, and machine learning.
Definition and Mathematical Formulation
The geometric median of a set of points $X = \{ x_1, x_2, ..., x_n \}$ in $\mathbb\{R\}^d$ is defined as the point that minimizes the following objective function:
where represents the Euclidean distance between the point and point .
Properties
• Uniqueness: The geometric median is unique unless all the data points lie on a line, in which case the median is not unique. • Robustness: It is less influenced by extreme values compared to the arithmetic mean. • Dimensionality: The geometric median is defined over any-dimensional Euclidean space.
Algorithms for Finding the Geometric Median
Finding the geometric median is generally more computationally challenging than finding the arithmetic mean. Here are several methods to approximate or compute the geometric median:
1. Weiszfeld's Algorithm
Weiszfeld's algorithm is a popular iterative method for finding the geometric median. It works as follows:
• Initialization: Start with an initial guess , often the arithmetic mean or one of the points from the dataset. • Iteration: Update the estimate using:
• Convergence: Repeat until convergence, which can be defined based on a small change between successive iterations.
Example: Consider three points in : , , . Using Weiszfeld’s algorithm starting with the arithmetic mean as the initial point, you iterate until convergence to find the geometric median.
2. Gradient Descent
The geometric median problem can also be approached using gradient descent by iteratively updating the coordinates in the direction that reduces the total distance:
- Objective: Minimize .
- Gradient Calculation: The subgradient of at is given by:
- Update Rule: Use a learning rate to update :
- Convergence: Adjust the learning rate to ensure convergence.
3. Randomized Algorithms
Randomized algorithms can also be employed, particularly in high-dimensional spaces where deterministic algorithms become inefficient. They typically involve random sampling and expectation maximization techniques to approximate the median.
Applications
• Facility Location: The geometric median can determine the optimal location of a point to minimize transportation costs. • Robust Statistics: Used as a robust estimator of central tendency. • Machine Learning: Enhances k-median clustering, providing a robust alternative to k-means.
Comparison Table
| Method | Pros | Cons | Complexity |
| Weiszfeld's Algorithm | Simple, Iterative | Slow convergence near solutions | |
| Gradient Descent | Convergence Control | Requires careful tuning of learning rate | |
| Randomized Algorithms | Efficient in High Dimensions | Provides Approximate Solution | (approx.) |
Conclusion
The geometric median is a fundamental concept in multivariate data analysis, providing a robust measure of central tendency across various domains. Several computational approaches, each with its strengths and limitations, allow for its effective computation. Understanding these methods provides the flexibility to handle diverse datasets and requirements efficiently.
Further Reading
For additional details, delve into resources specifically focusing on algorithmic optimizations for the geometric median, such as academic papers and textbooks on advanced statistics and machine learning.
Related reading
- How to find out if an item is present in a stdvector?
- How to find pairs with product greater than sum
- How to find patterns lines, circles,... from a list of points?
- How to find pythagorean triplets in an array faster than ON2?
- How to find overall CPU usage in a multi-tenant environment?
- How to find the center of a subset of vertices in a graph?
- How to find probability distribution and parameters for real data?
- How to find the closest point on a right rectangular prism 3d rectangle

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.