1

Find $y$ such that it makes $\sum_{i=1}^{n}n_i |y-i|$ takes the minimum value. In the above expression, $n_i\ge1$, $i\gt0$.

I can tell you the answer of $y$ might be the weighted median of $i's$, however I don't know how to prove it.

First example: $1,1,2,2,2$, median is $2$, $y=2$, min is $2$.

Second example: $1,1,2,2,3,3,3,3$, median is $2.5$, min is $6$.

Edit

From the comment, here is the proof for $n_i=1$, and it is for real numbers.

It lead me to think maybe my problem can also extended to real number case.

fizis
  • 953
  • Have you looked at the proof that the regular median is the answer when all the $n_i = 1$? I haven't checked if that will work, but it's where I would start. – JonathanZ Dec 14 '16 at 16:15
  • @user275313 you mean $n_i=1$? – fizis Dec 14 '16 at 16:16
  • @user275313 This part is not hard. – fizis Dec 14 '16 at 16:18
  • And here's a StackExchange post with some proofs for the "regular" version: http://math.stackexchange.com/questions/113270/the-median-minimizes-the-sum-of-absolute-deviations – JonathanZ Dec 14 '16 at 16:18
  • @user275313 I never thought this question is so hard! Maybe mine can also be extended to the real numbers. – fizis Dec 14 '16 at 16:22

1 Answers1

3

Let $f(y) = \sum_{i=1}^{i=n}n_i |y-i|$. As the sum of continuous functions, $f$ is continuous. Note that on the intervals $(i,i+1), f(y)$ is linear. Where the slope is negative, $f$ is decreasing and where it is positive, $f$ is increasing. So what you need to do is locate the value $y = i$ where the slope of $f$ switches sign.

For a particular value of $y$, that slope is $\sum_{i<y}n_i - \sum_{i>y}n_i$. Thus the minimum will be at the value of $i$ where that difference switches from negative to positive.

Paul Sinclair
  • 43,643
  • will this true for the real number case, substitute $i\to y_i$ – fizis Dec 15 '16 at 00:37
  • If you order the $y_i$ to be increasing, then yes. The minimum will occur at $y = y_k$, where $k$ is the lowest index for which $\sum_{i\le k}n_i - \sum_{i>k}n_i$ is positive. – Paul Sinclair Dec 15 '16 at 19:22
  • I found the argument may not be complete, since there is a second term of f(y) which will decrease with the value y, when $y\to y+1$. – fizis Feb 25 '19 at 00:10
  • Can you give an example of what you are talking about? Or at least explain it? Minimums occur where the slope changes from negative to positive, and the slope calculation is correct – Paul Sinclair Feb 25 '19 at 00:28