Convex.jl
Convex.jl copied to clipboard
Element-wise logisticloss on Vectors || Column-wise logsumexp on Matrices
I want to apply the function log(1+exp(.)) on a vector element-wise; then take an inner product with another positive vector (making the whole thing convex). I see that the function is called logisticloss and returns the sum of the function mapped to each element. But I want to apply it element-wise. How do I do that?
Here is an ultra simple version of my code:
a = [1. 2 3] # All positive
b = rand(3, 2)
x = Variable(2)
obj = sum(a .* log(1 + exp(b * w))) # May be I can use dot here?
prob = minimize(obj)
solve!(prob)
The problem is that log(1+exp(b*w)) is not “DCP”. I mean it is, but it has not been implemented element wise.
More generally. I think it would help to have logsumexp operate on a matrix returning a row vector where ith element is logsumexp applied to the ithe column of the matrix. Using that I could solve my problem by adding a row or zeros. My specific problem is a sub-problem of this.
That sounds like a great addition to the logsumexp atom. The syntax could be logsumexp(A, 1) and logsumexp(A, 2) for rowwise vs column wise reduction. I'd welcome a PR adding that functionality to the logsumexp atom if you're up to it! See the instructions in the docs on contributing.
On Aug 13, 2016 5:52 PM, "rakeshvar" [email protected] wrote:
I want to apply the function log(1+exp(.)) on a vector element-wise; then take an inner product with another positive vector (making the whole thing convex). I see that the function is called logisticloss https://github.com/JuliaOpt/Convex.jl/blob/master/src/atoms/exp_cone/logsumexp.jl and returns the sum of the function mapped to each element. But I want to apply it element-wise. How do I do that? Here is an ultra simple version of my code:
a = [1. 2 3] # All positive b = rand(3, 2) x = Variable(2) obj = sum(a .* log(1 + exp(b * w))) # May be I can use dot here? prob = minimize(obj) solve!(prob)
The problem is that log(1+exp(b*w)) is not “DCP”. I mean it is, but it has not been implemented element wise.
More generally. I think it would help to have logsumexp operate on a matrix returning a row vector where ith element is logsumexp applied to the ithe column of the matrix. Using that I could solve my problem by adding a row or zeros. My specific problem is a sub-problem of this.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/JuliaOpt/Convex.jl/issues/155, or mute the thread https://github.com/notifications/unsubscribe-auth/AAyp9Io78tDi2nD8X1-B_mZVeb0sa6Ywks5qfYXUgaJpZM4Jjo3k .
Sounds exciting. I will give it a try. While I am at it, I will also try an element-wise logistic loss.