23 #ifndef O2SCL_JACOBIAN_H 24 #define O2SCL_JACOBIAN_H 31 #include <o2scl/mm_funct.h> 32 #include <o2scl/deriv_gsl.h> 33 #include <o2scl/columnify.h> 34 #include <o2scl/vector.h> 36 #ifndef DOXYGEN_NO_O2NS 41 typedef std::function<
85 virtual int operator()(
size_t nx, vec_t &x,
size_t ny, vec_t &y,
88 #ifndef DOXYGEN_INTERNAL 146 #ifndef DOXYGEN_INTERNAL 180 epsrel=sqrt(std::numeric_limits<double>::epsilon());
203 O2SCL_ERR2(
"Negative or zero value specified in ",
214 O2SCL_ERR(
"Negative value specified in jacobian_gsl::set_epsmin().",
224 if (l_shrink_fact<0.0) {
225 O2SCL_ERR(
"Negative value specified in jacobian_gsl::set_shrink_fact().",
228 shrink_fact=l_shrink_fact;
241 virtual int operator()(
size_t nx, vec_t &x,
size_t ny, vec_t &y,
248 if (mem_size_x!=nx || mem_size_y!=ny) {
261 if (h<epsmin) h=epsmin;
262 if (h==0.0) h=epsrel;
265 int ret=(this->
func)(nx,xx,f);
270 while (ret!=0 && h>=epsmin && it<max_shrink_iters) {
275 ret=(this->
func)(nx,xx,f);
285 ret=(this->
func)(nx,xx,f);
306 if (temp!=0.0) nonzero=
true;
309 if (nonzero==
false) success=
false;
313 if (success==
false) {
315 "in jacobian_gsl::operator().",
exc_esing,
341 public jacobian<func_t,vec_t,mat_t> {
387 virtual int operator()(
size_t nx, vec_t &x,
size_t ny, vec_t &y,
404 this,std::placeholders::_1,std::ref(ejp));
406 for (
size_t j=0;j<nx;j++) {
408 for (
size_t i=0;i<ny;i++) {
410 double tmp=(*ejp.
x)[j];
411 int dret=dptr->deriv_err(tmp,dfnp,jac(i,j),err);
414 O2SCL_ERR2(
"Derivative object tailed in jacobian_exact::",
429 virtual int jac_err(
size_t nx, vec_t &x,
size_t ny, vec_t &y,
430 mat_t &jac, mat_t &err) {
443 this,std::placeholders::_1,std::ref(ejp));
445 for (
size_t j=0;j<nx;j++) {
447 for (
size_t i=0;i<ny;i++) {
449 double tmp=(*ejp.
x)[j];
450 int dret=dptr->deriv_err(tmp,dfnp,jac(i,j),err(i,j));
453 O2SCL_ERR2(
"Derivative object tailed in jacobian_exact::",
465 #ifndef DOXYGEN_INTERNAL 475 (this->func)(ejp.
nx,*ejp.
x,*ejp.
y);
476 return (*ejp.
y)[ejp.
yi];
483 #ifndef DOXYGEN_NO_O2NS
virtual int operator()(size_t nx, vec_t &x, size_t ny, vec_t &y, mat_t &j)=0
Evaluate the Jacobian j at point y(x)
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
virtual int set_function(func_t &f)
Set the function to compute the Jacobian of.
size_t xj
The current x value.
std::function< double(double)> funct11
One-dimensional function typedef.
virtual int operator()(size_t nx, vec_t &x, size_t ny, vec_t &y, mat_t &jac)
The operator()
invalid argument supplied by user
std::function< int(size_t, const boost::numeric::ublas::vector< double > &, boost::numeric::ublas::vector< double > &) > mm_funct11
Array of multi-dimensional functions typedef.
apparent singularity detected
#define O2SCL_CONV2_RET(d, d2, n, b)
Set an error and return the error value, two-string version.
size_t mem_size_x
Size of allocated memory in x.
double get_epsrel()
Get the relative stepsize (default )
size_t yi
The current y value.
double epsrel
The relative stepsize for finite-differencing.
double dfn(double x, ej_parms &ejp)
Function for the derivative object.
void vector_copy(const vec_t &src, vec2_t &dest)
Simple vector copy.
virtual int operator()(size_t nx, vec_t &x, size_t ny, vec_t &y, mat_t &jac)
The operator()
bool err_nonconv
If true, call the error handler if the routine does not converge.
void set_epsmin(double l_epsmin)
Set the minimum stepsize (must be )
Numerical differentiation base [abstract base].
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
size_t ny
The number of variables.
double get_epsmin()
Get the minimum stepsize (default )
std::function< int(size_t, boost::numeric::ublas::vector< double > &, size_t, boost::numeric::ublas::vector< double > &, boost::numeric::ublas::matrix< double > &) > jac_funct11
Jacobian function (not necessarily square)
vec_t xx
Function arguments.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
void set_epsrel(double l_epsrel)
Set the relative stepsize (must be )
deriv_base * dptr
Pointer to the derivative object.
size_t max_shrink_iters
Maximum number of times to shrink the step size.
Numerical differentiation (GSL)
int set_deriv(deriv_base<> &de)
Set the derivative object.
void set_shrink_fact(double l_shrink_fact)
Set shrink factor for decreasing step size.
void set_max_shrink_iters(size_t it)
Set number of times to decrease step size.
func_t func
A pointer to the user-specified function.
problem with user-supplied function
size_t nx
The number of variables.
double epsmin
The minimum stepsize.
deriv_gsl def_deriv
The default derivative object.
double shrink_fact
Factor to shrink stepsize by.
virtual int jac_err(size_t nx, vec_t &x, size_t ny, vec_t &y, mat_t &jac, mat_t &err)
Compute the Jacobian and its uncertainty from the numerical differentiation.
size_t mem_size_y
Size of allocated memory in y.
Parameter structure for passing information.
Simple automatic Jacobian.
Base for providing a numerical jacobian [abstract base].
A direct calculation of the jacobian using a deriv_base object.