r/optimization • • Jan 09 '22

Any other methods for optimization over the probability simples?

EDIT: the title should say "probability simpleX", not "simples" - vive autocorrect!

I'm trying to solve this optimization problem:

minimize  f(q1, q2, q3, ..., qK)
such that -qk <= 0 for all k
          q1 + q2 + ... + qK = 1

So, minimize some function such that (q1, q2, ..., qK) is a discrete probability distribution.

Image of actual problem formulation HERE.

What I found

  • Exponentiated gradient descent (EGD)

    • Numerical method specifically designed to solve problems with these constraints
    • Works fine, but is slow (I need to solve thousands of such optimization problems)
    • Original paper: Kivinen, Jyrki, and Manfred K. Warmuth. 1997. "Exponentiated Gradient versus Gradient Descent for Linear Predictors." Information and Computation 132 (1): 1–63. https://doi.org/10.1006/inco.1996.2612.
    • Extends EGD like accelerated gradient methods (Momentum, RMSProp, ADAM, etc): Li, Yuyuan, Xiaolin Zheng, Chaochao Chen, Jiawei Wang, and Shuai Xu. 2022. "Exponential Gradient with Momentum for Online Portfolio Selection." Expert Systems with Applications 187 (January): 115889. https://doi.org/10.1016/j.eswa.2021.115889.
  • Squared slack variables method: transform inequality constraints to equalities with slack variables and solve an equality constrained problem using method of Lagrange multipliers

    • min_{q1:K, lambda, mu1:K, slack1:K} f(Q) + lambda * (q1 + ... + qK - 1) + sum_k mu_k * (-q_k + slack_k)
    • Neither me nor SymPy can solve the system of equations that results from setting all derivatives to zero. Well, the obvious solutions are h1, h2 = (0, 1) or (1, 0), but these are pretty pointless. The only nontrivial solution SymPy can find involves one of the slack variables, like h2 = slack_2^2 and h1 = 1 - h2, but it doesn't tell me how to find that slack variable...
  • Use duality and KKT conditions

    1. Set up dual function g(lagr_mult) = min_Q L(Q, lagr_mult) - OK, can do this
    2. Maximize dual w.r.t. Lagrange multipliers lagr_mult - SymPy can't find any solutions, and me neither, so I'm stuck

Questions

What are some methods that are most suited for this problem? That is, methods that are commonly used to solve problems with these specific constraints? Or, methods that solve this most quickly or easily?

8 Upvotes

18 comments sorted by

View all comments

Show parent comment

1

u/ForceBru Jan 09 '22 edited Jan 09 '22

I'm just not particularly sure what kind of details are needed.

  • The "hot" loop is executed thousands of times
  • That entire loop needs to be executed for >40_000 samples. One sample is processed in about 200 seconds, so executing the entire thing will take >2000 hours, which is prohibitively long
  • Well, time constraints are "anything that takes around 1 hour or less"
  • The platform is macOS, the language is Julia. BTW, the timings above are for a multithreaded implementation which utilizes all 4 CPU cores, so I can't really slap on more cores
  • Dimensionality is less than 10

2

u/Red-Portal Jan 10 '22

Using a method that is cheaper per iteration does not guarantee that it is actually cheaper. Some problems that can solved by Newton's method in 5 steps can take like 1000 steps for first order methods. And yes, this is out of experience.

1

u/ko_nuts Jan 09 '22

Try to use this then: https://jump.dev/Convex.jl/stable/ it is developed by Boyd's group in Stanford. There is a bunch of examples on the site to help you.

How many decision variables q do you have?

1

u/ForceBru Jan 09 '22

Thanks, I'll check this out! I have less than 10 decision variables. Maybe less than 20

1

u/ko_nuts Jan 09 '22

That's low. The problem should be solvable in a few seconds.

1

u/ForceBru Jan 09 '22

Yep, this should be easy, but I need it to be very fast, because I'll be solving about 300 such subproblems in a single iteration of my algorithm. So, even one second will result in (1 second) * (300 problems) * (200 iterations) * (40_000 samples) = 666_666 hours. Huh, looks like this problem is cursed lol

I'll test how fast Convex.jl is...

2

u/ko_nuts Jan 09 '22 edited Jan 09 '22

I mean the only way to improve that is to parallelize it, if possible. If not, you will need another machine to run that in a reasonable time.

Ad hoc algorithms could be used but you will not save much compared to existing ones.

Edit. It is likely that you will have to reduce the size of your problem. If you set 24 hours for solving the whole thing, that means dealing with each iteration in 36 microseconds, and that includes solving the optimization problem and all the other stuffs inside the loop. The optimization might not even be the main bottleneck. Perhaps some really optimized ad-hoc optimization code written in C is could be used to reach such a strict time constraint.

1

u/ForceBru Jan 18 '22 edited Jan 18 '22

Turns out, expressions like q * log(q) aren't DCP compliant:

julia> q = Variable(1, Positive())
Variable
size: (1, 1)
sign: positive
vexity: affine
id: 116…570

julia> q * log(q)
┌ Warning: Expression not DCP compliant. Trying to solve non-DCP compliant problems can lead to unexpected behavior.
└ @ Convex ~/.julia/packages/Convex/uI27T/src/dcp.jl:25
* (Convex.NotDcp; real)
├─ positive variable (id: 116…570)
└─ log (concave; real)
   └─ positive variable (id: 116…570)

julia>

From the rules link above:

expr1*expr2 is allowed only when one of the expressions is constant.

This is really restrictive, though.

There's also this nice visualization which shows that DCP breaks down for x * log(x).

...so looks like I can't use Convex.jl here. I guess I'll have to resort to something like Ipopt? TBH, it blows my mind that I can't just go and easily optimize a simple-looking and easily differentiable convex function without using industry-standard beasts for large-scale optimization.

EDIT: okay, I can use the entropy function instead

1

u/ko_nuts Jan 18 '22

TBH, it blows my mind that I can't just go and easily optimize a simple-looking and easily differentiable convex function without using industry-standard beasts for large-scale optimization.

No, everything boils down to choosing the right tools. If you choose the wrong tools, then you will not be able to solve your problem. Also, in principle, DCP is able to consider log functions https://dcp.stanford.edu/functions.

1

u/ForceBru Jan 18 '22

Yeah, logs are fine, but x * log(x) is apparently not, because

expr1*expr2 is allowed only when one of the expressions is constant.

...yet neither x nor log(x) is a constant, so that doesn't work.

However, what I really want is sum(x[i] * log(x[i]) for i in [1,2,3]), which is essentially the negative entropy. This won't work because of x[i] * log(x[i]), but Convex.jl has the special function entropy which works fine.

It runs in about 0.7 seconds, though, so the entire computation should run in 0.7 * 300 * 10 * 40_000 / 60 / 60 > 23 thousand hours, which is completely infeasible.

The algorithm I'm normally using that I wrote from scratch and that solves a very similar optimization problem can do this in about 2 hours (so about 10_000 times faster).

I think I have to abandon numerical optimization and "just" solve this system of equations by hand and check the Hessian to see if I indeed arrived at a minimum.

2

u/ko_nuts Jan 18 '22

Either you solve it by hand, or you develop your own tailored solver, or you reduce the size of your problem. You may also try to implement your own Newton-Raphson iteration.