.. index:: single: barzilai_borwein(Problem)
.. _barzilai_borwein/1:

.. rst-class:: right

**object**

``barzilai_borwein(Problem)``
=============================

* ``Problem`` - Problem object implementing ``local_optimization_problem_protocol`` and defining ``gradient/2``.


Barzilai-Borwein (BB) gradient method with adaptive step sizes. Requires the problem to define ``gradient/2``. Supports box constraints via projection, minimization and maximization, and BB1 / BB2 / alternating formulas.

| **Availability:** 
|    ``logtalk_load(local_optimization(loader))``

| **Author:** Paulo Moura
| **Version:** 1:0:0
| **Date:** 2026-09-03

| **Compilation flags:**
|    ``static, context_switching_calls``


| **Imports:**
|    ``public`` :ref:`local_optimization_solver(Problem) <local_optimization_solver/1>`
| **Uses:**
|    :ref:`linear_algebra <linear_algebra/0>`
|    :ref:`list <list/0>`

| **Remarks:**

   - Step formulas: ``formula(bb1)`` uses ``alpha = (s*s)/(s*y)`` (long step). ``formula(bb2)`` uses ``alpha = (s*y)/(y*y)`` (short step). ``formula(alternate)`` (default) switches between BB1 and BB2 each iteration.
   - Safeguards: When the denominator is near zero or the computed step is outside ``[step_min, step_max]``, the previous accepted step (or ``step_size`` on the first iteration) is reused.
   - Line search: Optional non-monotone Armijo acceptance controlled by ``line_search(none|armijo)``. The default ``none`` accepts the pure BB step.
   - Bounds: When the problem defines ``position_bounds/1``, trial points are projected onto the box after each step.

| **Inherited public predicates:**
|     :ref:`options_protocol/0::check_option/1`  :ref:`options_protocol/0::check_options/1`  :ref:`options_protocol/0::default_option/1`  :ref:`options_protocol/0::default_options/1`  :ref:`options_protocol/0::option/2`  :ref:`options_protocol/0::option/3`  :ref:`local_optimization_solver/1::run/2`  :ref:`local_optimization_solver/1::run/3`  :ref:`local_optimization_solver/1::run/4`  :ref:`options_protocol/0::valid_option/1`  :ref:`options_protocol/0::valid_options/1`  

.. contents::
   :local:
   :backlinks: top

Public predicates
-----------------

(no local declarations; see entity ancestors if any)

Protected predicates
--------------------

(no local declarations; see entity ancestors if any)

Private predicates
------------------

(no local declarations; see entity ancestors if any)

Operators
---------

(none)

.. seealso::

   :ref:`local_optimization_problem_protocol <local_optimization_problem_protocol/0>`, :ref:`local_optimization_solver(Problem) <local_optimization_solver/1>`, :ref:`gradient_descent(Problem) <gradient_descent/1>`, :ref:`conjugate_gradient(Problem) <conjugate_gradient/1>`, :ref:`nelder_mead(Problem) <nelder_mead/1>`

