Let x_1, ..., x_i,..., x_p be p real numbers such that 0 <= x_i <= b for all i. That is, each x_i can take any value between 0 and b. I'd like to find the values of {x_i}'s that maximize the variance among them.
Do you have any hints? I'd like to use this result for my example code. Or, isn't this question well-defined?
At first I thought of something like x_1=0, x_2=...=x_p=b, but then I found this does not maximize the variance when p is a little bit large.
Thanks
After comments, I did some trials on a numerical prove for your problem. There's still some work to do, but I hope it puts you in the right track. Besides, I've used
python
, and I have no idea if this is ok for you or not. You can surely find equivalent ways to do it inmatlab
andR
.I use the well-known property of the variance = E[X^2] - E[X]^2, to make the derivatives easier. (If you have doubts, check wiki).
The
python
packagescipy.optimize
has a methodminimize
to minimize numerically a function. You can select an algorithm for solving the problem; I'm not so familiar with the possible algorithms and I was looking for the well-known plain gradient descent (well, at least I hope you know it), and I think a closed one could be SLSQP, but honestly I'm not 100% sure on the details.And finally, I didn't make sure that the function you're minimizing is convex, or figured out whether it has local minima, but the results look fine.
I give you the code in python below, in case it is useful, but the bottomline is that I'd suggest you:
Code below. Hope it helps.
I'm not going to post the algebra for the derivatives, I hope you can make them yourself. And you must take into account that you are maximizing and not minimizing, so you have to multiply by -1, as explained I hope quite clearly here (look for "maximizing").
Setup,
The function you are maximizing, that is the variance (remember the the trick E[X^2] - E[X]^2, and the -1),
The derivative of that function for each of the
xi
of the vectorx
, (I hope you can derivate and get to the same result),Actually, I made quite a few mistakes when writing this function, both in the derivative and the python implementation. But there is a trick that helps a lot, which is to check the derivative in a numeric way, by adding and subtracting a small epsilon in every dimension and calculating the slope of the curve see wiki. This would the function that approximates the derivative,
And then I've checked
func_deriv_approx
versusfunc_deriv
for a bunch of values.And the minimizing itself. If I initialize the values to the solution we suspect is right, it works ok, it only iterates once and gives the expected results,
(Note that you could use the length you wanted, since
func
andfunc_deriv
are written in a way that accept any length).You could initialize randomly like this,
And then the maximization is,
Or finally for length = 100,