I define the same objective function in two ways:
function logit1(α, X, y)
loglike = -sum(y[i]*α'*X[i,:] .- log.(1 .+ exp.(α'*X[i,:])) for i=1:length(y))
return loglike
end
function logit2(α, X, y)
loglike = -sum(y.*(X*α) .- log.(1 .+ exp.(X*α)))
return loglike
end
Then I run optimization using logit1 and logit2 respectively:
optimize(α -> logit(α, X, y), rand(size(X,2)), LBFGS(), Optim.Options(g_tol=1e-6, iterations=100_000, show_trace=true))
While both objectives lead to the same minimizer (as supposed to), the reported output are different. The first one gives “* Status: failure (objective increased between iterations)” but the second one gives " * Status: success".
Why does this happen?