# Optim.jl: bracketing with Newton()

**URL:** <https://discourse.julialang.org/t/optim-jl-bracketing-with-newton/30332>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [October 26, 2019, 12:47pm UTC](https://discourse.julialang.org/t/optim-jl-bracketing-with-newton/30332 "2019-10-26T12:47:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)\
**Post date:** [October 26, 2019, 12:47pm UTC](https://discourse.julialang.org/t/optim-jl-bracketing-with-newton/30332/1 "2019-10-26T12:47:26Z")

</div>

Is it possible to use Newton() methods with limiting some variables? Like FMinbox?

---

<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:** [October 26, 2019, 1:44pm UTC](https://discourse.julialang.org/t/optim-jl-bracketing-with-newton/30332/2 "2019-10-26T13:44:25Z")

</div>

please start with the manual, eg

> **[Optim.jl](https://julianlsolvers.github.io/Optim.jl/stable/#user/minimization/%23box-constrained-optimization)**
>
> Pure Julia implementations of optimization algorithms.

---

<div class="post-metadata">

**Author:** ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)\
**Post date:** [October 26, 2019, 3:15pm UTC](https://discourse.julialang.org/t/optim-jl-bracketing-with-newton/30332/3 "2019-10-26T15:15:52Z")

</div>

Thank you, I read the manual. I think I know how Fminbox() works, but it doesn’t work with Newton(). (L)BFGS() works fine with Fminbox(), but I hope to have some solution for Newton().

---

<div class="post-metadata">

**Author:** ![dpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpo/32/3335_2.png) [@dpo](https://discourse.julialang.org/u/dpo)\
**Post date:** [October 26, 2019, 3:43pm UTC](https://discourse.julialang.org/t/optim-jl-bracketing-with-newton/30332/4 "2019-10-26T15:43:58Z")

</div>

We have a Newton method for bound-constrained problems here: [Solvers · JSOSolvers.jl](https://juliasmoothoptimizers.github.io/JSOSolvers.jl/latest/solvers/#JSOSolvers.tron)

---

<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:** [October 26, 2019, 4:17pm UTC](https://discourse.julialang.org/t/optim-jl-bracketing-with-newton/30332/5 "2019-10-26T16:17:11Z")

</div>

See this issue you may be running into, and particularly this comment:

[https://github.com/JuliaNLSolvers/Optim.jl/issues/600#issuecomment-420946414](https://github.com/JuliaNLSolvers/Optim.jl/issues/600#issuecomment-420946414)

---

<div class="post-metadata">

**Author:** ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)\
**Post date:** [October 28, 2019, 9:12am UTC](https://discourse.julialang.org/t/optim-jl-bracketing-with-newton/30332/6 "2019-10-28T09:12:24Z")

</div>

Thanks, i will try!

---

<div class="post-metadata">

**Author:** ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)\
**Post date:** [October 28, 2019, 9:32am UTC](https://discourse.julialang.org/t/optim-jl-bracketing-with-newton/30332/7 "2019-10-28T09:32:06Z")

</div>

Thanks, this issue is wery close to my project. I also need to maximize likelihood function and one of parameter of covariance matrix - rho - changing in limits 0 - 1.0, and when i use LBFGS - it’s works fine, but to slow. Newton() works fast, but i need to do things like this: `if rho > 1 rho = 1 end` and this is not good, because last step of optimization some time \> 1.0 end it can leads to “stuck” in value 1.0 when real value close to 1.0 ( f.e. 0.988). I try to use “link function” like sigmoid, but at marginal values it works not good: `1/(1+exp(x))` not works correctly, `1/(1+x^4)` works nearly good, but not not better when rho “force limited”. Now i use LBFGS till rho is stable and then use Newton(), or Newton() at first step and then LBFGS, but i think there must be a better way.

---

<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:** [October 28, 2019, 9:47am UTC](https://discourse.julialang.org/t/optim-jl-bracketing-with-newton/30332/8 "2019-10-28T09:47:15Z")

</div>

It is hard to say more about this without an MWE (eg do you provide derivatives manually or use AD, what is rho [stepsize correction?], …).

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)\
**Post date:** [October 28, 2019, 9:59am UTC](https://discourse.julialang.org/t/optim-jl-bracketing-with-newton/30332/9 "2019-10-28T09:59:21Z")

</div>

Hi! I use AD, and likelihood function based on derivation of variance-covariance matrix. For example 2x2 matrix (ρ, σ₁, σ₂ - should be found)

```julia
σ²₁ ρσ₁σ₂ 
ρσ₁σ₂ σ²₂

```

where ρ covariation coefficient that should be also found - and it can be in the range 0 - 1.

---

<div class="post-metadata">

**Author:** ![aaowens](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aaowens/32/12101_2.png) [@aaowens](https://discourse.julialang.org/u/aaowens)\
**Post date:** [October 28, 2019, 2:54pm UTC](https://discourse.julialang.org/t/optim-jl-bracketing-with-newton/30332/10 "2019-10-28T14:54:20Z")

</div>

You might have better luck transforming your variables, as done here: [Optim.jl](https://julianlsolvers.github.io/Optim.jl/stable/#examples/generated/maxlikenlm/) . They work with the log variance which can take on any value. For ρ you could use tanh and atanh to go back and forth between `(-1, 1)` and `(-inf, inf)`
