A somewhat odd (to me) question was asked on a forum recently. Assume
that you have continuous variables x1,…,xNx1,…,xN that are subject
to some constraints. For simplicity, I'll just write x=(x1,…,xN)∈Xx=(x1,…,xN)∈X.
I'm going to assume that XX is compact, and so in particular
the xixi are bounded. The questioner wanted to know how to model
the problem of minimizing the median of the values x1,…,xNx1,…,xN.
I don't know why that was the goal, but the formulation is mildly
interesting and fairly straightforward, with one wrinkle.
The wrinkle has to do with whether NN is odd or even. Suppose that
we sort the components of some solution xx, resulting in what
is sometimes called the "order statistic": x(1)≤x(2)≤…x(N)x(1)≤x(2)≤…x(N).
For odd NN, the median is x(N+12).x(N+12).For even NN,
it is usually defined as (x(N2)+x(N2+1))/2.(x(N2)+x(N2+1))/2.
The odd case is easier, so we'll start there. Introduce NN new binary
variables z1,…,zNz1,…,zN and a new continuous variable yy,
which represents the median xx value. The objective will be to minimize
yy. In addition to the constraint x∈Xx∈X, we use "big-M"
constraints to force yy to be at least as large as half the sample
(rounding "half" up). Those constraints are:
y≥xi−Mizi, i=1,…,NN∑i=1zi=N−12
with the Mi sufficiently large positive constants. The last
constraint forces zi=0 for exactly N+12 of the indices
i, which in turn forces y≥xi for N+12 of the
xi. Since the objective minimizes y, zi will be 0 for
the N+12 smallest of the xi and y will be no
larger than the smallest of them. In other words, we are guaranteed
that in the optimal solution y=x(N+12), i.e., it
is the median of the optimal x.
If N is even and if we are going to use the standard definition
of median, we need twice as many added variables (or at least that's
the formulation that comes to mind). In addition to the zi,
let w1,…,wN also be binary variables, and replace y
with a pair of continuous variables y1, y2. The objective
becomes minimization of their average (y1+y2)/2 subject to
the constraints
y1≥xi−Mizi ∀iy2≥xi−Miwi ∀iN∑i=1zi=N2−1N∑i=1wi=N2
where the Mi are as before. The constraints force y1 to
be at least as large as N2+1 of the xi and y2
to be at least as large as N2 of them. The minimum objective
value will occur when y1=x(N2+1) and y2=x(N2).
Friday, September 1, 2017
2 comments:
Due to intermittent spamming, comments are being moderated. If this is your first time commenting on the blog, please read the Ground Rules for Comments. In particular, if you want to ask an operations research-related question not relevant to this post, consider asking it on Operations Research Stack Exchange.
Subscribe to:
Post Comments (Atom)
In the big leagues, median is not unique with even number of data points. If the problem is to minimize "a" median, i.e., find the smallest median, not "the" (what you call standard definition of) median, I think for N even you could minimize y_2, and forget about y_1 ... or something to that effect.
ReplyDeleteI agree that, with a "liberal" (nonpolitical sense) interpretation of median you could just minimize y2, and with a "conservative" interpretation you might want to minimize y1. I'm pretty sure that statisticians view the definition of the sample median of an even number of observations to be the mean of the two middle ones, and I suspect they consider themselves the "big leagues" when it comes to stats. ("Data scientists" might disagree. Statisticians would view their disagreement as an outlier.)
Delete