# LBFGS optimizer

**URL:** <https://discourse.itk.org/t/lbfgs-optimizer/3658>\
**Category:** Algorithms\
**Created:** [November 26, 2020, 1:12pm UTC](https://discourse.itk.org/t/lbfgs-optimizer/3658 "2020-11-26T13:12:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pierrectl](https://discourse.itk.org/user_avatar/discourse.itk.org/pierrectl/32/1420_2.png) [@pierrectl](https://discourse.itk.org/u/pierrectl)\
**Post date:** [November 26, 2020, 1:12pm UTC](https://discourse.itk.org/t/lbfgs-optimizer/3658/1 "2020-11-26T13:12:38Z")

</div>

hello everyone,  
I was wondering if itk developers provided a registration example between two 3d images using LBFGS optimizer ? I already checked test examples and program throws the following exception when computing registration process:

```
*************************************************
  N=6 NUMBER OF CORRECTIONS=5 INITIAL VALUES F= 0 GNORM= 0
*************************************************
   I NFN FUNC GNORM STEPLENGTH
  THE SEARCH DIRECTION IS NOT A DESCENT DIRECTION
 IFLAG= -1 LINE SEARCH FAILED. SEE DOCUMENTATION OF ROUTINE MCSRCH ERROR RETURN OF LINE SEARCH: INFO= 0 POSSIBLE CAUSES: FUNCTION OR GRADIENT ARE INCORRECT OR INCORRECT TOLERANCESvnl_lbfgs: Error. Netlib routine lbfgs failed.

```

Thank you

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [November 26, 2020, 4:51pm UTC](https://discourse.itk.org/t/lbfgs-optimizer/3658/2 "2020-11-26T16:51:38Z")

</div>

Which test is that? Do the rest of the tests run fine?

---

<div class="post-metadata">

**Author:** ![pierrectl](https://discourse.itk.org/user_avatar/discourse.itk.org/pierrectl/32/1420_2.png) [@pierrectl](https://discourse.itk.org/u/pierrectl)\
**Post date:** [November 30, 2020, 1:41pm UTC](https://discourse.itk.org/t/lbfgs-optimizer/3658/3 "2020-11-30T13:41:09Z")

</div>

hello @dzenanz,  
in fact, I looked through unit tests in order to know how to use LBFGS optimizer.  
This is how I set its parameters:

```auto
    optimizer->SetTrace( false );
    optimizer->SetMaximumNumberOfFunctionEvaluations( 1000 );
    optimizer->SetGradientConvergenceTolerance( 0.001 );
    optimizer->SetLineSearchAccuracy( 0.9 );
    optimizer->SetDefaultStepLength( 0.1 );

```

And I get the exception above. So I was wondering if anyone knows how to raise this exception… I mean, does this exception come from optimizer parameters? Or maybe the cost function? Or the metric that I use?

---

<div class="post-metadata">

**Author:** ![pierrectl](https://discourse.itk.org/user_avatar/discourse.itk.org/pierrectl/32/1420_2.png) [@pierrectl](https://discourse.itk.org/u/pierrectl)\
**Post date:** [December 1, 2020, 9:24am UTC](https://discourse.itk.org/t/lbfgs-optimizer/3658/4 "2020-12-01T09:24:47Z")

</div>

okay, never mind, my problem came from this line:

```auto
optimizer->SetGradientConvergenceTolerance( 0.001 );

```

I relaxed this parameter and set it to 0.1. My program runs perfectly fine now.
