46 #ifndef O2SCL_OOL_CONSTR_MMIN_H 47 #define O2SCL_OOL_CONSTR_MMIN_H 53 #include <o2scl/multi_funct.h> 54 #include <o2scl/mmin.h> 55 #include <o2scl/vector.h> 57 #ifndef DOXYGEN_NO_O2NS 63 typedef std::function<int
76 template<
class func_t,
class dfunc_t=func_t,
82 #ifndef DOXYGEN_INTERNAL 125 void shrink(
const size_t nind, gsl_vector_uint *Ind,
129 for( ii = 0; ii < nind; ii++ ) {
130 indii = gsl_vector_uint_get(Ind,ii);
139 void expand(
const size_t nind, gsl_vector_uint *Ind,
142 size_t jj, ii, indii;
145 for( jj = 0; jj < nind; jj++ ) {
147 indii = gsl_vector_uint_get( Ind, ii );
156 double calc_f(
const size_t nind, gsl_vector_uint *Ind,
157 vec_t &X, vec_t &Xc) {
159 const size_t missing=this->dim-nind;
165 for(
size_t i=nind;i<nind+missing;i++) {
185 int calc_g(
const size_t nind, gsl_vector_uint *Ind, vec_t &X,
186 vec_t &Xc, vec_t &G) {
188 const size_t missing=this->dim-nind;
193 for(
size_t i=nind;i<nind+missing;i++) {
214 int calc_Hv(
const size_t nind, gsl_vector_uint *Ind,
215 vec_t &X, vec_t &Xc, vec_t &V, vec_t &Hv) {
217 const size_t missing=this->ndim-nind;
221 for(
size_t i=nind;i<nind+missing;i++) {
231 hfunc(this->dim,X,V,Hv);
265 for(
size_t i=0;i<n;i++) {
278 for(
size_t i=0;i<
dim;i++) dx[i]=0.0;
289 virtual int set(func_t &fn, dfunc_t &dfn, vec_t &init) {
292 for(
size_t i=0;i<
dim;i++) dx[i]=0.0;
308 virtual int set_hess(func_t &fn, dfunc_t &dfn, hfunc_t &hfn,
312 for(
size_t i=0;i<
dim;i++) dx[i]=0.0;
347 virtual int mmin(
size_t nvar, vec_t &xx,
double &fmin,
350 O2SCL_ERR(
"Not yet implemented mmin_constr::mmin().",
359 virtual int mmin_hess(
size_t nvar, vec_t &xx,
double &fmin,
360 func_t &ff, dfunc_t &df, hfunc_t &hf)
365 if (requires_hess)
set_hess(ff,df,hf,xx);
374 for(
size_t i=0;i<nvar;i++) xx[i]=this->x[i];
385 virtual int mmin_de(
size_t nvar, vec_t &xx,
double &fmin,
386 func_t &ff, dfunc_t &df) {
398 for(
size_t i=0;i<nvar;i++) xx[i]=this->x[i];
406 const char *
type() {
return "mmin_constr"; }
408 #ifndef DOXYGEN_INTERNAL 415 (
const mmin_constr<func_t,dfunc_t,hfunc_t,vec_t>&);
421 #ifndef DOXYGEN_NO_O2NS virtual int mmin_hess(size_t nvar, vec_t &xx, double &fmin, func_t &ff, dfunc_t &df, hfunc_t &hf)
Calculate the minimum min of ff w.r.t. the array x of size nvar with gradient df and hessian vector p...
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
size_t dim
Number of parameters.
const char * type()
Return string denoting type ("mmin_constr")
virtual int is_optimal()=0
See if we're finished.
vec_t L
Lower bound constraints.
virtual int restart()
Restart the minimizer.
dfunc_t * dfunc
Gradient function.
iteration has not converged
double f
The current function value.
requested feature not (yet) implemented
size_t gcount
Number of gradient evaluations.
double calc_f(const size_t nind, gsl_vector_uint *Ind, vec_t &X, vec_t &Xc)
Evaluate the objective function from the reduced space.
virtual int mmin(size_t nvar, vec_t &xx, double &fmin, func_t &ff)
Calculate the minimum min of func w.r.t. the array x of size nvar.
vec_t x
The current minimum vector.
Constrained multidimensional minimization (OOL) [abstract base].
virtual int iterate()=0
Perform an iteration.
void vector_copy(const vec_t &src, vec2_t &dest)
Simple vector copy.
Multidimensional minimization [abstract base].
size_t fcount
Number of function evaluations.
virtual int set_constraints(size_t nc, vec_t &lower, vec_t &upper)
Set the constraints.
func_t * func
User-supplied function.
void shrink(const size_t nind, gsl_vector_uint *Ind, const vec_t &V)
Shrink vector V from the full to the reduced space.
void expand(const size_t nind, gsl_vector_uint *Ind, const vec_t &V)
Expand vector V from the reduced to the full space.
size_t nconstr
Number of constraints.
hfunc_t * hfunc
Hessian function.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
int last_ntrial
The number of iterations for in the most recent minimization.
bool requires_hess
If true, the algorithm requires the hessian vector product.
virtual int set_hess(func_t &fn, dfunc_t &dfn, hfunc_t &hfn, vec_t &init)
Set the function, the gradient, the Hessian product, and the initial guess.
vec_t U
Upper bound constraints.
int calc_Hv(const size_t nind, gsl_vector_uint *Ind, vec_t &X, vec_t &Xc, vec_t &V, vec_t &Hv)
Evaluate a hessian times a vector from the reduced space.
std::function< int(size_t, const boost::numeric::ublas::vector< double > &, const boost::numeric::ublas::vector< double > &, boost::numeric::ublas::vector< double > &)> ool_hfunct11
Hessian product function for o2scl::mmin_constr.
virtual int allocate(const size_t n)
Allocate memory.
int calc_g(const size_t nind, gsl_vector_uint *Ind, vec_t &X, vec_t &Xc, vec_t &G)
Compute gradient in the reduced space.
virtual int mmin_de(size_t nvar, vec_t &xx, double &fmin, func_t &ff, dfunc_t &df)
Calculate the minimum min of func w.r.t. the array x of size nvar with gradient dfunc.
size_t hcount
Number of Hessian evaluations.
vec_t gradient
The current gradient vector.
int ntrial
Maximum number of iterations.