Skip to content

Instantly share code, notes, and snippets.

@mosekadmin
Created November 27, 2018 09:07
Show Gist options
  • Save mosekadmin/af6b5aa0a07b2c17d4765dec2428438e to your computer and use it in GitHub Desktop.
Save mosekadmin/af6b5aa0a07b2c17d4765dec2428438e to your computer and use it in GitHub Desktop.
Compact log-sum-exp in MOSEK 9 Fusion
# Models log(sum(exp(Ax+b))) <= 0.
# Each row of [A b] describes one of the exp-terms
def logsumexp(M, A, x, b):
u = M.variable(A.shape[0])
M.constraint( Expr.sum(u), Domain.lessThan(1.0))
M.constraint( Expr.hstack(u,
Expr.constTerm(A.shape[0], 1.0),
Expr.add(Expr.mul(A, x), b)), Domain.inPExpCone())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment