# Convergence in Optim questions

**URL:** <https://discourse.julialang.org/t/convergence-in-optim-questions/65139>\
**Category:** Optimization (Mathematical)\
**Tags:** optim, optimization\
**Created:** [July 22, 2021, 9:41pm UTC](https://discourse.julialang.org/t/convergence-in-optim-questions/65139 "2021-07-22T21:41:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Barmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/michael_barmann/32/20389_2.png) [@Michael\_Barmann](https://discourse.julialang.org/u/Michael_Barmann)\
**Post date:** [July 22, 2021, 9:41pm UTC](https://discourse.julialang.org/t/convergence-in-optim-questions/65139/1 "2021-07-22T21:41:17Z")

</div>

I have a few questions regarding convergence in Optim:

1. When an optimization finishes and prints the convergence report, at the top it says either “success” or “failure”. Does this refer to whether or not the algorithm converged (within the specified time, iteration, and function call limits) ?

My next two questions concern the following example using the Rosenbrock function:

```julia
f(x) = (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2
once_diff = OnceDifferentiable(f, [1.98,-1.95]; autodiff = :forward);
res = Optim.optimize(once_diff, [1.25, -2.1], [Inf, Inf], [2.0, 2.0], Fminbox(ConjugateGradient()),
                     Optim.Options(x_abstol = 1e-3, x_reltol = 1e-3, f_abstol = 1e-3, f_reltol = 
                                   1e-3, g_tol = 1e-3))

```

This gives the following convergence report:

```julia
 Status: failure

 * Candidate solution
    Final objective value: 9.339344e-01

 * Found with
    Algorithm: Fminbox with Conjugate Gradient

 * Convergence measures
    |x - x'| = 4.73e-04 ≤ 1.0e-03
    |x - x'|/|x'| = 1.09e-04 ≤ 1.0e-03
    |f(x) - f(x')| = 0.00e+00 ≤ 1.0e-03
    |f(x) - f(x')|/|f(x')| = 0.00e+00 ≤ 1.0e-03
    |g(x)| = 5.05e-01 ≰ 1.0e-03

 * Work counters
    Seconds run: 0 (vs limit Inf)
    Iterations: 1000
    f(x) calls: 2033
    ∇f(x) calls: 1021

```

1. Why does it not indicate the _reason_ for the failure?

I was looking at the Optim source [code](https://github.com/JuliaNLSolvers/Optim.jl/blob/master/src/types.jl/) and it appears to me, based on the function `Base.show(io::IO, r::MultivariateOptimizationResults)` whose definition starts on line 223, that it’s supposed to print a “failure string” which indicates the reason for the failure. In the case of the above example, why didn’t it print “failure (reached maximum number of iterations)”?

1. I then checked the convergence:

```julia
println(res.x_converged)
println(res.f_converged)
println(res.g_converged)

```

and got `false` for all three. The third false makes sense, but why are `res.x_converged` and `res.f_converged` both false? In the convergence report, it clearly shows that all convergence criteria except for |g(x)| are met…I also checked `res.x_abschange`, `res.x_relchange`, `res.f_abschange`, and `res.f_relchange`, just to be sure, and indeed they are all the same value as shown in the report…So I’m pretty confused by this…

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 23, 2021, 8:37am UTC](https://discourse.julialang.org/t/convergence-in-optim-questions/65139/2 "2021-07-23T08:37:32Z")

</div>

It may be better to make these comments in an [issue](https://github.com/JuliaNLSolvers/Optim.jl/issues) so that they are not lost.

---

<div class="post-metadata">

**Author:** ![Michael\_Barmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/michael_barmann/32/20389_2.png) [@Michael\_Barmann](https://discourse.julialang.org/u/Michael_Barmann)\
**Post date:** [July 23, 2021, 7:37pm UTC](https://discourse.julialang.org/t/convergence-in-optim-questions/65139/3 "2021-07-23T19:37:53Z")

</div>

@Tamas_Papp Thanks, I just opened an [issue.](https://github.com/JuliaNLSolvers/Optim.jl/issues/934)

Also, this is the first issue I’ve ever opened and I was wondering if there are some general guidelines for how to write an issue. I couldn’t find any on this site, so I made a post here: [Guidelines for writing an issue? - Meta Discussion - JuliaLang](https://discourse.julialang.org/t/guidelines-for-writing-an-issue/65204)

Lastly, my first question isn’t an issue…any clarification on Optim’s definition of"success"/“failure” would be helpful!

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [July 23, 2021, 7:56pm UTC](https://discourse.julialang.org/t/convergence-in-optim-questions/65139/4 "2021-07-23T19:56:52Z")

</div>

@Michael_Barmann,

The general rules for an issue are the same as Discourse: explain what you did (with a reproducible example), what happened, and what you expected to happen.

The distinction is that the Github issues are generally left for bug reports or feature requests, rather than “help, how do I do X”.

In this case, it seems like a feature request for improved clarity on the reason for failures.

> why didn’t it print “failure (reached maximum number of iterations)”

Your suggestion seems like it would be a big improvement.
