.. include:: ../../toolkit-substitutions

.. oe:namespace:: OEOpt



.. meta::
   :keywords: OEBFGSOpt, BFGSOpt


.. _OEOpt_OEBFGSOpt:

.. oe:class:: OEBFGSOpt

   .. attention::

      |TWOLANGUAGE|

   .. oe:api::


      class OEBFGSOpt : public OEOptimizer1

   The :ref:`OEBFGSOpt <OEOpt_OEBFGSOpt>` implements the quasi-Newton optimization method with
   updating Hessian according to the scheme of Broyden, Fletcher, Goldfarb and Shanno.
   The convergence criteria in based on  :math:`\sum_i {g_ig_i}`.

   The following methods are publicly inherited from :ref:`OEOptimizer1 <OEOpt_OEOptimizer1>`:
    * :oe:meth:`operator()<OEOpt::OEOptimizer1::operator()>`         
    * :oe:meth:`GetIterLimit<OEOpt::OEOptimizer1::GetIterLimit>` and
      :oe:meth:`SetIterLimit<OEOpt::OEOptimizer1::SetIterLimit>`
    * :oe:meth:`SetLineMinimize<OEOpt::OEOptimizer1::SetLineMinimize>`
    * :oe:meth:`GetTolerance<OEOpt::OEOptimizer1::GetTolerance>` and
      :oe:meth:`SetTolerance<OEOpt::OEOptimizer1::SetTolerance>`

   The :ref:`OEBFGSOpt <OEOpt_OEBFGSOpt>` class defines the following public methods:
    * :oe:meth:`GetHessianDimension<OEOpt::OEBFGSOpt::GetHessianDimension>`         
    * :oe:meth:`GetInverseHessian<OEOpt::OEBFGSOpt::GetInverseHessian>`
    * :oe:meth:`GetKeepHessian<OEOpt::OEBFGSOpt::GetKeepHessian>`
    * :oe:meth:`SetKeepHessian<OEOpt::OEBFGSOpt::SetKeepHessian>`
    * :oe:meth:`UseSavedHessian<OEOpt::OEBFGSOpt::UseSavedHessian>`
   
   .. oe:method:: Constructors

      .. oe:language:: c++ java csharp

         .. oe:api::

            OEBFGSOpt()
            OEBFGSOpt(const OEBFGSOpt &)

      .. oe:language:: python

         .. oe:api:: python

            OEBFGSOpt() -> OEBFGSOpt
            OEBFGSOpt(arg2: OEBFGSOpt) -> OEBFGSOpt

      Default and copy constructors.

   .. oe:method:: operator=
      :language: c++

      .. oe:api::

         OEBFGSOpt &operator=(const OEBFGSOpt &)

      Assignment operator.


   .. oe:method:: GetHessianDimension

      .. oe:language:: c++ java csharp

         .. oe:api::

            unsigned int GetHessianDimension() const

      .. oe:language:: python

         .. oe:api:: python

            GetHessianDimension() -> int

      Returns the dimension of the Hessian matrix.

   .. oe:method:: GetInverseHessian

      .. oe:language:: c++ java csharp

         .. oe:api::

            bool GetInverseHessian(double* h, unsigned int nv) const

      .. oe:language:: python

         .. oe:api:: python

            GetInverseHessian(h: OEDoubleArray, nv: int) -> bool

      Copies the inverted Hessian matrix into the array ``h`` in the form of lower triangle of
      complete Hessian. This function is useful when the Hessian matrix generated during optimization 
      is needed. ``nv`` is the number of optimized variables. 

   .. oe:method:: GetKeepHessian

      .. oe:language:: c++ java csharp

         .. oe:api::

            bool GetKeepHessian() const

      .. oe:language:: python

         .. oe:api:: python

            GetKeepHessian() -> bool

      Returns ``true`` if the :ref:`OEBFGSOpt <OEOpt_OEBFGSOpt>` object is set to keep its Hessian

   .. oe:method:: SetKeepHessian

      .. oe:language:: c++ java csharp

         .. oe:api::

            void SetKeepHessian(bool keep)

      .. oe:language:: python

         .. oe:api:: python

            SetKeepHessian(keep: bool) -> None

      If the value of the argument passed is ``true``, the :ref:`OEBFGSOpt <OEOpt_OEBFGSOpt>` object will
      keep its Hessian when the optimization is done.


   .. oe:method:: UseSavedHessian

      .. oe:language:: c++ java csharp

         .. oe:api::

            void UseSavedHessian(bool ini)

      .. oe:language:: python

         .. oe:api:: python

            UseSavedHessian(ini: bool) -> None

      By default, at the start of the optimization Hessian is initiated as unit matrix.
      In the case when optimization has to repeated, for example starting with different
      values of variables, one can use this method to initiate optimization with the 
      Hessian from the previous run. 

