Go to the documentation of this file.
47 #ifndef O2SCL_OOL_MMIN_SPG_H
48 #define O2SCL_OOL_MMIN_SPG_H
54 #include <o2scl/multi_funct.h>
55 #include <o2scl/mmin_constr.h>
56 #include <gsl/gsl_math.h>
58 #ifndef DOXYGEN_NO_O2NS
85 public mmin_constr<func_t,dfunc_t,ool_hfunct,vec_t> {
87 #ifndef DOXYGEN_INTERNAL
121 double lambda, lambdanew;
122 double fmax, faux, fxx, dTg;
123 short armijo_failure;
128 for(
size_t i=0;i<this->
dim;i++) {
132 for(
size_t i=0;i<this->
dim;i++) {
136 for(
size_t i=0;i<this->
dim;i++) {
141 for(
size_t i=0;i<this->
dim;i++) dTg+=
d[i]*this->
gradient[i];
145 while (armijo_failure) {
148 for(
size_t i=0;i<this->
dim;i++)
xx[i]=this->
x[i];
149 for(
size_t i=0;i<this->
dim;i++)
xx[i]+=lambda*
d[i];
150 fxx=(*this->
func)(this->dim,
xx);
153 for(ii=0;ii<
m;ii++) {
155 fmax=GSL_MAX(fmax,faux);
160 lambdanew=-lambda*lambda*dTg/(2*(fxx-this->
f-lambda*dTg));
172 for(
size_t i=0;i<this->
dim;i++)
s[i]=
xx[i];
173 for(
size_t i=0;i<this->
dim;i++)
s[i]-=this->
x[i];
176 for(
size_t i=0;i<this->
dim;i++) this->
x[i]=
xx[i];
181 for(
size_t i=0;i<this->
dim;i++)
d[i]=this->
x[i];
182 for(
size_t i=0;i<this->
dim;i++)
d[i]-=this->
gradient[i];
184 for(
size_t i=0;i<this->
dim;i++)
d[i]-=this->
x[i];
186 double maxval=fabs(
d[0]);
187 for(
size_t i=1;i<this->
dim;i++) {
188 if (fabs(
d[i])>maxval) {
192 this->
size=fabs(maxval);
195 for(
size_t i=0;i<this->
dim;i++)
y[i]-=this->
gradient[i];
208 size_t ii, n=this->
dim;
210 for(ii=0;ii<n;ii++) {
212 if (xt[ii]<this->
U[ii]) dtmp=xt[ii];
213 else dtmp=this->
U[ii];
214 if (this->
L[ii]>dtmp) xt[ii]=this->
L[ii];
288 virtual int set(func_t &fn, dfunc_t &dfn, vec_t &init) {
291 vec_t>
::set(fn,dfn,init);
297 this->
f=(*this->
func)(this->
dim,this->
x);
302 for(
size_t i=0;i<this->
dim;i++) {
306 for(
size_t i=0;i<this->
dim;i++)
d[i]-=this->
x[i];
308 double maxval=fabs(
d[0]);
309 for(
size_t i=1;i<this->
dim;i++) {
310 if (fabs(
d[i])>maxval) {
314 this->
size=fabs(maxval);
318 for(
size_t i=1;i<this->
dim;i++) {
319 if (fabs(this->
gradient[i])>maxval) {
323 alpha=1.0/fabs(maxval);
342 this->
f=(*this->
func)(this->
dim,this->
x);
346 double maxval=fabs(this->
gradient[0]);
347 for(
size_t i=1;i<this->
dim;i++) {
348 if (fabs(this->
gradient[i])>maxval) {
352 alpha=1.0/fabs(maxval);
356 for(
size_t i=0;i<this->
dim;i++) {
360 for(
size_t i=0;i<this->
dim;i++)
d[i]-=this->
x[i];
363 for(
size_t i=1;i<this->
dim;i++) {
364 if (fabs(
d[i])>maxval) {
368 this->
size=fabs(maxval);
384 for(
size_t i=0;i<this->
dim;i++) bk+=
s[i]*
y[i];
390 for(
size_t i=0;i<this->
dim;i++) ak+=
s[i]*
s[i];
405 if (this->
size>tol && this->
f>fmin) {
412 const char *
type() {
return "mmin_constr_spg"; }
414 #ifndef DOXYGEN_INTERNAL
427 #ifndef DOXYGEN_NO_O2NS
Constrained multidimensional minimization (OOL) [abstract base].
Class for automatically computing gradients [abstract base].
virtual int set(func_t &fn, dfunc_t &dfn, vec_t &init)
Set the function, the initial guess, and the parameters.
double fmin
Minimum function value (default )
double gamma
Sufficient decrease parameter (default )
size_t m
Non-monotone parameter.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
double sigma2
Upper bound to the step length reduction (default 0.9)
void vector_copy(const vec_t &src, vec2_t &dest)
Simple vector copy.
size_t dim
Number of parameters.
vec_t xx
Temporary vector.
virtual int free()
Free previously allocated memory.
double sigma1
Lower bound to the step length reduction (default 0.1)
int proj(vec_t &xt)
Project into feasible region.
vec_t fvec
Temporary vector.
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.
std::function< double(size_t, const boost::numeric::ublas::vector< double > &)> multi_funct
Multi-dimensional function typedef in src/base/multi_funct.h.
boost::numeric::ublas::vector< double > x
The current minimum vector.
virtual int allocate(const size_t n)
Allocate memory.
virtual int allocate(const size_t n)
Allocate memory.
ool_hfunct hfunc_t
A convenient typedef for the unused Hessian product type.
multi_funct * func
User-supplied function.
double tol
Tolerance on infinite norm (default )
std::function< int(size_t, boost::numeric::ublas::vector< double > &, boost::numeric::ublas::vector< double > &)> grad_funct
Array of multi-dimensional functions typedef in src/min/mmin.h.
double alpha
Armijo parameter.
double alphamax
Upper bound to spectral step size (default )
boost::numeric::ublas::vector< double > L
Lower bound constraints.
virtual int restart()
Restart the minimizer.
boost::numeric::ublas::vector< double > U
Upper bound constraints.
grad_funct * dfunc
Gradient function.
virtual int iterate()
Perform an iteration.
int line_search()
Line search.
double f
The current function value.
virtual int is_optimal()
See if we're finished.
Constrained minimization by the spectral projected gradient method (OOL)
size_t M
Monotonicity parameter (M=1 forces monotonicity) (default 10)
const char * type()
Return string denoting type ("mmin_constr_spg")
double alphamin
Lower bound to spectral step size (default )
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).