# Why these two ways of function definition lead to different optimization statuses?

**URL:** <https://discourse.julialang.org/t/why-these-two-ways-of-function-definition-lead-to-different-optimization-statuses/46272>\
**Category:** New to Julia\
**Created:** [September 8, 2020, 3:35pm UTC](https://discourse.julialang.org/t/why-these-two-ways-of-function-definition-lead-to-different-optimization-statuses/46272 "2020-09-08T15:35:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DShiu](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@DShiu](https://discourse.julialang.org/u/DShiu)\
**Post date:** [September 8, 2020, 3:35pm UTC](https://discourse.julialang.org/t/why-these-two-ways-of-function-definition-lead-to-different-optimization-statuses/46272/1 "2020-09-08T15:35:06Z")

</div>

I define the same objective function in two ways:

```julia
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:

```julia
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?
