INAIO Guide Stage 1 5Calculus and Optimisation
5.5 Absolute and squared distances
Apply optimization to choosing a centre: absolute distance leads to a median, while squared distance leads to a mean.
In Module 5.2, optimization meant choosing an input that makes an objective as small or large as possible. This lesson is a direct application: several locations or readings are fixed, and we choose one centre . Our objective is the total distance from to those observations, or the total of their squared distances. We seek the that makes that total smallest.
The choice of objective matters. Minimizing ordinary distance gives a median on a line; minimizing squared distance gives a mean. The first can choose a meeting point that minimizes total travel. The second appears when one constant prediction is chosen to minimize squared error. This is intermediate optimization using absolute value, averages, and derivatives. OpenStax's mean-and-median lesson gives the statistical background.
A basic idea: the penalty changes the centre
Take observations at on a number line. The decision is where to put ; the observations do not move. If we add ordinary distances, costs , while costs . Here is better. If we square each distance first, costs , while costs . Now is better.
The observation at is far from the others. Squaring its gap makes that large error especially costly, so the best squared-distance centre moves towards it. The best ordinary-distance centre stays at the middle observation. We will show below why these are global answers, not merely better than the two points compared here.
A quick tour of the two objectives
For fixed real observations , the variable we may choose is . Two possible loss functions are
For absolute distance , imagine sliding a little to the right without crossing an observation. Each observation to its left becomes that much farther away; each observation to its right becomes that much closer. If more observations lie to the right, the total falls. If more lie to the left, it rises. The switch happens at a median. With an odd number of observations, the middle sorted value minimizes ; with an even number, every point between the two middle values gives the same minimum total.
For squared distance , differentiation from Module 5.1 gives
Set this slope to zero: , the mean. Also , so the loss bends upward and this is the global minimum. A distant observation has a larger effect because its squared error grows faster as the gap grows. For , the mean is , while the median is .
If each observation has a positive weight , use or . The same reasoning gives a weighted median for absolute distance, with no more than half the total weight strictly to either side, and the weighted mean for squared distance.
If a constraint restricts to an interval that excludes the median or mean, use Module 5.4's boundary check. For the observations , requiring makes the best allowed choice for either loss.
The median result here is for distance on a line. For ordinary Euclidean distances to points in a plane, finding the geometric median needs a different method; this introductory module does not solve that general two-dimensional problem. For squared Euclidean distances in a plane, the coordinate-wise mean remains the minimizer.
Application 1: a meeting point on a road
Three teams are at road positions , , and kilometres. Where should they meet to minimize their total travel distance along the road?
- Choose the objective. Total distance to meeting position is .
- Use the middle position. The sorted middle value is . Just to its left, moving right reduces distance for two teams and increases it for one; just to its right, moving farther right increases distance for two teams and reduces it for one. The total is smallest at km.
- Check. Total travel is km. At , it would be km.
The farthest team does not by itself decide the best total-distance meeting point.
Application 2: one constant sensor estimate
Readings are , , , and units. Choose one constant estimate that minimizes total squared error.
- Write the objective. .
- Find the minimum. . Setting it to zero gives units, the mean .
- Check the loss. , so this is a minimum. The squared errors are , , , and , totalling .
The squared penalty makes larger errors count much more than small errors.
Resources
| Source | Title | Why read it |
|---|---|---|
| OpenStax | Measures of the center of the data | Review means, medians, and sensitivity to unusual values. |
Finished this module? Mark it done.
Comments
Stuck on something, spotted a mistake, or found a resource that helped you? Tell us below.
Loading comments