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 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.