Project I - Geometric medians
Motivation: Assume you want to build a drone tower from where to deliver parcels to costumers, and you know the destinations (points) where to deliver parcels. What is the optimal placement of the tower, if each drone can at most carry one parcel and needs to return to the tower between each delivery?
The geometric median of a point set S = {p1, …, pn} in the plane is a point q (not necessarily a point in S), that minimizes the sum of distances to the points, i.e. minimizes ∑i=1..n |pi - q|, where |p - q| = ((px - qx)2 + (py - qy)2)0.5.
-
Create a function
geometric_median
that given a list of points computes the geometric median of the point set.
Hint. Use theminimize
function from the modulescipy.optimize
. -
Make representative visualizations that show both the input point sets and the computed geometric medians. Examples should include point sets with two and three points, and a random point set.
-
Use the
matplotlib
plotting functioncontour
to plot a contour map to illustrate that it is the correct minimum that mas been found (the z-value for a point (x, y) in the contour map is the sum of the distances from (x, y) to all input points).
Next we want to find two points q1 and q2 such that the perpendicular bisector of q1 and q2 partitions the point set into the points closest to q1 and those closest to q2. We want to find two points q1 and q2 such that the sum of distances to the nearest point of q1 and q2 is minimized, i.e. ∑i=1..n min(|pi - q1|, |pi - q2|) is minimized.
To solve this problem one essentially has to consider all possible bisection lines, and to find the geometric median on both sides of the bisector, e.g. using the algorithm from the first question. Assuming no three points are on a line, it is sufficient to consider all n(n-1)/2 bisector lines that go through two input points, and for each bisector line to consider the two cases where the two points on the line both are considered to be to the left or to the right of the line.
-
Create a function
two_geometric_medians
that give a list of points p1, …, pn computes two points q1 and q2 minimizing ∑i=1..n min(|pi - q1|, |pi - q2|). It can be assumed that no three points are on a line. -
Visualize your solution, showing imput points, q1 and q2, and the perpendicular bisector between q1 and q2.
-
Optional. Extend your solution to handle the case where three or more points can be on a line. E.g. what is your solution if you have four points on a line?