47 #ifndef O2SCL_OOL_MMIN_PGRAD_H 48 #define O2SCL_OOL_MMIN_PGRAD_H 54 #include <gsl/gsl_math.h> 56 #include <o2scl/multi_funct.h> 57 #include <o2scl/mmin_constr.h> 59 #ifndef DOXYGEN_NO_O2NS 87 public mmin_constr<func_t,dfunc_t,ool_hfunct,vec_t> {
89 #ifndef DOXYGEN_INTERNAL 101 size_t ii, n=this->
dim;
103 for(ii=0;ii<n;ii++) {
105 if (xt[ii]<this->
U[ii]) dtmp=xt[ii];
106 else dtmp=this->
U[ii];
107 if (this->
L[ii]>dtmp) xt[ii]=this->
L[ii];
117 double t, tnew, fx, fxx, dif2, gtd;
128 for(
size_t i=0;i<this->
dim;i++) xx[i]-=t*this->
gradient[i];
131 fxx=(*this->
func)(this->dim,xx);
134 for(
size_t i=0;i<this->
dim;i++) this->
dx[i]-=this->
x[i];
137 for(
size_t i=0;i<this->
dim;i++) dif2+=this->
dx[i]*this->
dx[i];
140 for(
size_t i=0;i<this->
dim;i++) {
144 tnew = - t * t * gtd / (2*(fxx - this->
f - gtd));
150 if (arg1>arg2) tnew=arg1;
154 }
while(fxx > fx - (
alpha/t) * dif2 );
212 virtual int set(func_t &fn, dfunc_t &dfn, vec_t &init) {
220 this->
f=(*this->
func)(this->
dim,this->
x);
232 this->
f=(*this->
func)(this->
dim,this->
x);
246 for(
size_t i=0;i<this->
dim;i++) {
250 for(
size_t i=0;i<this->
dim;i++) xx[i]-=this->
x[i];
252 double maxval=fabs(xx[0]);
253 for(
size_t i=1;i<this->
dim;i++) {
254 if (fabs(xx[i])>maxval) {
258 this->
size=fabs(maxval);
265 if (this->
size>tol && this->
f>fmin) {
272 const char *
type() {
return "mmin_constr_pgrad"; }
274 #ifndef DOXYGEN_INTERNAL 281 (
const mmin_constr_pgrad<func_t,dfunc_t,vec_t>&);
287 #ifndef DOXYGEN_NO_O2NS Class for automatically computing gradients [abstract base].
virtual int restart()
Restart the minimizer.
std::function< double(size_t, const boost::numeric::ublas::vector< double > &)> multi_funct
Multi-dimensional function typedef.
double sigma1
Lower bound to the step length reduction.
Constrained minimization by the projected gradient method (OOL)
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.
virtual int is_optimal()
See if we're finished.
std::function< int(size_t, boost::numeric::ublas::vector< double > &, boost::numeric::ublas::vector< double > &)> grad_funct
Array of multi-dimensional functions typedef.
double fmin
Minimum function value (default )
vec_t L
Lower bound constraints.
virtual int iterate()
Perform an iteration.
double sigma2
Upper bound to the step length reduction.
double alpha
Constant for the sufficient decrease condition (default )
int line_search()
Line search.
dfunc_t * dfunc
Gradient function.
iteration has not converged
double f
The current function value.
vec_t x
The current minimum vector.
Constrained multidimensional minimization (OOL) [abstract base].
void vector_copy(const vec_t &src, vec2_t &dest)
Simple vector copy.
virtual int free()
Free previously allocated memory.
vec_t xx
Temporary vector.
func_t * func
User-supplied function.
std::function< int(size_t, const boost::numeric::ublas::vector< double > &, const boost::numeric::ublas::vector< double > &, boost::numeric::ublas::vector< double > &)> ool_hfunct
Hessian product function for o2scl::mmin_constr.
vec_t U
Upper bound constraints.
int proj(vec_t &xt)
Project into feasible region.
virtual int allocate(const size_t n)
Allocate memory.
double tol
Tolerance on infinite norm.
virtual int allocate(const size_t n)
Allocate memory.
const char * type()
Return string denoting type ("mmin_constr_pgrad")
virtual int set(func_t &fn, dfunc_t &dfn, vec_t &init)
Set the function, the gradient, and the initial guess.
ool_hfunct hfunc_t
A convenient typedef for the unused Hessian product type.
int ntrial
Maximum number of iterations.