Closed ericphanson closed 1 month ago
A quick fix is
function mylogisticloss(expr)
n = length(expr)
e = hcat(expr, zeros(n))
# log(sum(exp(x))) <= t <=> sum(exp(x)) <= exp(t) <=> sum(exp(x - t)) <= 1
t = Variable(n)
z = sum(exp(e - t .* ones(size(e))))
add_constraint!(t, 1 >= z)
return sum(t)
end
but that subverts DCP since the extended formulation is only valid in a convex context, but the resulting sum(t)
is affine
. The proper fix therefore is probably to have a vectorized version of logsumexp
as a new atom and use it here.
https://github.com/jump-dev/Convex.jl/blob/2978c32c0fcc3abc1cf10704980367cc23f8e1df/src/atoms/LogSumExpAtom.jl#L48
I guess I missed this one in #614