Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scalar indexing in logisticloss #682

Closed
ericphanson opened this issue May 21, 2024 · 1 comment · Fixed by #692
Closed

Scalar indexing in logisticloss #682

ericphanson opened this issue May 21, 2024 · 1 comment · Fixed by #692

Comments

@ericphanson
Copy link
Collaborator

return sum(logsumexp([e[i]; 0]) for i in 1:length(e))

I guess I missed this one in #614

@ericphanson
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant