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++) {
154 faux=fvec[ii]+
gamma*lambda*dTg;
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 421 (
const mmin_constr_spg<func_t,dfunc_t,vec_t>&);
427 #ifndef DOXYGEN_NO_O2NS Class for automatically computing gradients [abstract base].
virtual int free()
Free previously allocated memory.
std::function< double(size_t, const boost::numeric::ublas::vector< double > &)> multi_funct
Multi-dimensional function typedef.
vec_t xx
Temporary vector.
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 iterate()
Perform an iteration.
const char * type()
Return string denoting type ("mmin_constr_spg")
std::function< int(size_t, boost::numeric::ublas::vector< double > &, boost::numeric::ublas::vector< double > &)> grad_funct
Array of multi-dimensional functions typedef.
vec_t L
Lower bound constraints.
dfunc_t * dfunc
Gradient function.
size_t m
Non-monotone parameter.
double tol
Tolerance on infinite norm (default )
double f
The current function value.
int line_search()
Line search.
double gamma
Sufficient decrease parameter (default )
double sigma2
Upper bound to the step length reduction (default 0.9)
vec_t x
The current minimum vector.
Constrained multidimensional minimization (OOL) [abstract base].
virtual int restart()
Restart the minimizer.
void vector_copy(const vec_t &src, vec2_t &dest)
Simple vector copy.
virtual int is_optimal()
See if we're finished.
func_t * func
User-supplied function.
size_t M
Monotonicity parameter (M=1 forces monotonicity) (default 10)
double alphamin
Lower bound to spectral step size (default )
virtual int allocate(const size_t n)
Allocate memory.
virtual int set(func_t &fn, dfunc_t &dfn, vec_t &init)
Set the function, the initial guess, and the parameters.
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.
double fmin
Minimum function value (default )
double alphamax
Upper bound to spectral step size (default )
vec_t U
Upper bound constraints.
virtual int allocate(const size_t n)
Allocate memory.
double sigma1
Lower bound to the step length reduction (default 0.1)
int proj(vec_t &xt)
Project into feasible region.
Constrained minimization by the spectral projected gradient method (OOL)
ool_hfunct hfunc_t
A convenient typedef for the unused Hessian product type.
vec_t fvec
Temporary vector.
double alpha
Armijo parameter.