Class mroot_hybrids (o2scl)¶
-
template<class
func_t
= mm_funct, classvec_t
= boost::numeric::ublas::vector<double>, classmat_t
= boost::numeric::ublas::matrix<double>, classjfunc_t
= jac_funct>
classo2scl
::
mroot_hybrids
: public o2scl::mroot<mm_funct, boost::numeric::ublas::vector<double>, jac_funct>, private o2scl::mroot_hybrids_base¶ Multidimensional root-finding algorithm using Powell’s Hybrid method (GSL)
This is a recasted version of the GSL routines which use a modified version of Powell’s Hybrid method as implemented in the HYBRJ algorithm in MINPACK [Garbow80].
Both the scaled and unscaled options are available by setting int_scaling (the scaled version is the default). If derivatives are not provided, they will be computed automatically. This class provides the GSL-like interface using allocate(), set() (or set_de() in case where derivatives are available), iterate(), and the higher-level interfaces, msolve() and msolve_de(), which perform the solution and the memory allocation automatically. Some additional checking is performed in case the user calls the functions out of order (i.e. set() without allocate()).
The functions msolve() and msolve_de() use the condition \( \sum_i |f_i|<\) mroot::tol_rel to determine if the solver has succeeded.
See the multisolve_subsect section of the User’s guide for general information about solvers. There is an example for the usage of the multidimensional solver classes given in
examples/ex_mroot.cpp
, see the ex_mroot_sect .The original GSL algorithm has been modified to shrink the stepsize if a proposed step causes the function to return a non-zero value. This allows the routine to automatically try to avoid regions where the function is not defined. The algorithm is also modified to check that it is not sending non-finite values to the user-specified function. To return to the default GSL behavior, set
shrink_step and extra_finite_check to false.- Note
The set() and set_de() functions store a pointer to the function object and the user must ensure that the object is still valid for a later call to iterate().
The default method for numerically computing the Jacobian is from jacobian_gsl. This default is identical to the GSL approach, except that the default value of jacobian_gsl::epsmin is non-zero. See jacobian_gsl for more details.
By default convergence failures result in calling the exception handler, but this can be turned off by setting mroot::err_nonconv to false. If mroot::err_nonconv is false, then the functions iterate(), msolve() and msolve_de() will return a non-zero value if convergence fails. Note that the default Jacobian object, def_jac also has a data member jacobian_gsl::err_nonconv which separately handles the case where the one row of the Jacobian is all zero.
- Idea for Future:
Is all the setting of vectors and matrices to zero really necessary? Do they need to be executed even if memory hasn’t been recently allocated?
- Idea for Future:
Convert more ubvectors to vec_t.
- Idea for Future:
Some more of the element-wise vector manipulation could be converted to BLAS routines.
- Idea for Future:
It’s kind of strange that set() sets jac_given to false and set_de() has to reset it to true. Can this be simplified?
- Idea for Future:
Many of these minpack functions could be put in their own “minpack_tools” class, or possibly moved to be linear algebra routines instead.
- Idea for Future:
There are still some numbers in here which the user could have control over, for example, the
nslow2
threshold which indicates failure.
Subclassed by o2scl::mroot_hybrids_arma_qr_econ< func_t, vec_t, mat_t, jfunc_t >, o2scl::mroot_hybrids_eigen< func_t, vec_t, mat_t, jfunc_t >
Public Functions
-
mroot_hybrids
()¶
-
~mroot_hybrids
()¶
-
int
iterate
()¶ Perform an iteration.
At the end of the iteration, the current value of the solution is stored in x.
-
void
allocate
(size_t n)¶ Allocate the memory.
-
const char *
type
()¶ Return the type,
"mroot_hybrids"
.
-
int
msolve_de
(size_t nn, vec_t &xx, func_t &ufunc, jfunc_t &dfunc)¶ Solve
func
with derivativesdfunc
usingx
as an initial guess, returningx
.
-
int
msolve
(size_t nn, vec_t &xx, func_t &ufunc)¶ Solve
ufunc
usingxx
as an initial guess, returningxx
.
Public Members
-
bool
shrink_step
¶ If true, iterate() will shrink the step-size automatically if the function returns a non-zero value (default true)
The original GSL behavior can be obtained by setting this to
false
.
-
bool
extra_finite_check
¶ If true, double check that the input function values are finite (default true)
-
bool
int_scaling
¶ If true, use the internal scaling method (default true)
-
jacobian_gsl<func_t, vec_t, mat_t>
def_jac
¶ Default automatic Jacobian object.
Protected Functions
Protected Attributes
-
int
iter
¶ Number of iterations.
-
size_t
ncfail
¶ Compute the number of failures.
-
size_t
ncsuc
¶ Compute the number of successes.
-
size_t
nslow1
¶ The number of times the actual reduction is less than 0.001.
-
size_t
nslow2
¶ The number of times the actual reduction is less than 0.1.
-
double
fnorm
¶ The norm of the current function value.
-
double
delta
¶ The limit of the Nuclidean norm.
-
ubvector
diag
¶ The diagonal elements.
-
ubvector
qtf
¶ The value of \( Q^T f \).
-
ubvector
newton
¶ The Newton direction.
-
ubvector
gradient
¶ The gradient direction.
-
ubvector
df
¶ The change in the function value.
-
ubvector
qtdf
¶ The value of \( Q^T \cdot \mathrm{df} \).
-
ubvector
rdx
¶ The value of \( R \cdot \mathrm{dx} \).
-
ubvector
w
¶ The value of \( w=(Q^T df-R dx)/|dx| \).
-
ubvector
v
¶ The value of \( v=D^2 dx/|dx| \).
-
size_t
dim
¶ The number of equations and unknowns.
-
bool
jac_given
¶ True if the jacobian has been given.
-
bool
set_called
¶ True if “set” has been called.