ool_mmin_gencan.h

00001 /*
00002   -------------------------------------------------------------------
00003   
00004   Copyright (C) 2006, 2007, 2008, Andrew W. Steiner
00005   
00006   This file is part of O2scl.
00007   
00008   Some of the source code in this file has been adapted from OOL
00009   library written by Sergio Drumond Ventura, Luis Alberto D'Afonseca,
00010   and Ricardo Biloti available from http://ool.sourceforge.net.
00011   
00012   O2scl is free software; you can redistribute it and/or modify
00013   it under the terms of the GNU General Public License as published by
00014   the Free Software Foundation; either version 3 of the License, or
00015   (at your option) any later version.
00016   
00017   O2scl is distributed in the hope that it will be useful,
00018   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020   GNU General Public License for more details.
00021   
00022   You should have received a copy of the GNU General Public License
00023   along with O2scl. If not, see <http://www.gnu.org/licenses/>.
00024 
00025   -------------------------------------------------------------------
00026 */
00027 #ifndef O2SCL_OOL_MMIN_GENCAN_H
00028 #define O2SCL_OOL_MMIN_GENCAN_H
00029 
00030 #include <o2scl/text_file.h>
00031 #include <o2scl/ovector_tlate.h>
00032 #include <o2scl/multi_funct.h>
00033 #include <o2int/ool_constr_min.h>
00034 #include <gsl/gsl_math.h>
00035 
00036 #ifndef DOXYGENP
00037 namespace o2scl {
00038 #endif
00039 
00040   /**
00041      \brief Constrained minimization by the "GENCAN" method (OOL)
00042      
00043      \note Not working yet
00044   */
00045   template<class param_t, class func_t, class dfunc_t=func_t, 
00046     class hfunc_t=func_t, class vec_t=ovector_view, class alloc_vec_t=ovector,
00047     class alloc_t=ovector_alloc> class ool_mmin_gencan : 
00048   public ool_constr_min<param_t,func_t,dfunc_t,hfunc_t,vec_t,
00049     alloc_vec_t,alloc_t> {
00050 
00051 #ifndef DOXYGEN_INTERNAL
00052 
00053     protected:
00054 
00055     /// Desc (default 1.0)
00056     double cg_src;
00057 
00058     /// Temporary vector
00059     alloc_vec_t S;
00060     /// Temporary vector
00061     alloc_vec_t Y;
00062     /// Temporary vector
00063     alloc_vec_t D;
00064     /// Temporary vector
00065     alloc_vec_t cg_W;
00066     /// Temporary vector
00067     alloc_vec_t cg_R;
00068     /// Temporary vector
00069     alloc_vec_t cg_D;
00070     /// Temporary vector
00071     alloc_vec_t cg_Sprev;
00072     /// Temporary vector
00073     alloc_vec_t Xtrial;
00074     /// Temporary vector
00075     alloc_vec_t tnls_Xtemp;
00076     /// Temporary vector
00077     alloc_vec_t near_l;
00078     /// Temporary vector
00079     alloc_vec_t near_u;
00080     
00081     /// Desc
00082     int *Ind;
00083     
00084     /// Line search
00085     int line_search() {
00086 
00087       return 0;
00088     }
00089     
00090     /// Project into feasible region
00091     int proj(vec_t &xt) {
00092       size_t ii, n=this->dim;
00093       
00094       for(ii=0;ii<n;ii++) {
00095         xt[ii]=GSL_MAX(this->L[ii],GSL_MIN(xt[ii],this->U[ii]));
00096       }
00097       return 0;
00098     }
00099 
00100 #endif
00101 
00102     public:
00103 
00104     ool_mmin_gencan() {
00105       epsgpen=1.0e-5;
00106       epsgpsn=1.0e-5;
00107       fmin=-1.0e99;
00108       udelta0=-1.0;
00109       ucgmia=-1.0;
00110       ucgmib=-1.0;
00111       cg_src=1.0;
00112       cg_scre=1.0;
00113       cg_gpnf=1.0e-5;
00114       cg_epsi=1.0e-1;
00115       cg_epsf=1.0e-5;
00116       cg_epsnqmp=1.0e-4;
00117       cg_maxitnqmp=5;
00118       nearlyq=0;
00119       nint=2.0;
00120       next=2.0;
00121       mininterp=4;
00122       maxextrap=100;
00123       trtype=0;
00124       eta=0.9;
00125       delmin=0.1;
00126       lspgmi=1.0e-10;
00127       lspgma=1.0e10;
00128       theta=1.0e-6;
00129       gamma=1.0e-4;
00130       beta=0.5;
00131       sigma1=0.1;
00132       sigma2=0.9;
00133       epsrel=1.0e-7;
00134       epsabs=1.0e-10;
00135       infrel=1.0e20;
00136       infabs=1.0e99;
00137     }
00138 
00139     /// Tolerance on Euclidean norm of projected gradient (default 1.0e-5)
00140     double epsgpen;
00141     /// Tolerance on infinite norm of projected gradient (default 1.0e-5)
00142     double epsgpsn;
00143     /** 
00144         \brief Minimum function value (default \f$ 10^{-99} \f$)
00145         
00146         If the function value is below this value, then the algorithm
00147         assumes that the function is not bounded and exits.
00148     */
00149     double fmin;
00150     /// Trust-region radius (default -1.0)
00151     double udelta0;
00152     /// Maximum interations per variable (default -1.0)
00153     double ucgmia;
00154     /// Extra maximum iterations (default -1.0)
00155     double ucgmib;
00156     /// Conjugate gradient condition type (default 1)
00157     int cg_scre;
00158     /// Projected gradient norm (default 1.0e-5)
00159     double cg_gpnf;
00160     /// Desc (default 1.0e-1)
00161     double cg_epsi;
00162     /// Desc (default 1.0e-5)
00163     double cg_epsf;
00164     /// Stopping fractional tolerance for conjugate gradient (default 1.0e-4)
00165     double cg_epsnqmp;
00166     /// Maximum iterations for conjugate gradient (default 5)
00167     int cg_maxitnqmp;
00168     /// Set to 1 if the function is nearly quadratic (default 0)
00169     int nearlyq;
00170     /// Interpolation constant (default 2.0)
00171     double nint;
00172     /// Extrapolation constant (default 2.0)
00173     double next;
00174     /// Minimum interpolation size (default 4)
00175     int mininterp;
00176     /// Maximum extrapolations in truncated Newton direction (default 100)
00177     int maxextrap;
00178     /// Type of trust region (default 0)
00179     int trtype;
00180     /// Threshold for abandoning current face (default 0.9)
00181     double eta;
00182     /// Minimum trust region for truncated Newton direction (default 0.1)
00183     double delmin;
00184     /// Minimum spectral steplength (default 1.0e-10)
00185     double lspgmi;
00186     /// Maximum spectral steplength (default 1.0e10)
00187     double lspgma;
00188     /// Constant for the angle condition (default 1.0e-6)
00189     double theta;
00190     /// Constant for Armijo condition (default 1.0e-4)
00191     double gamma;
00192     /// Constant for beta condition (default 0.5)
00193     double beta;
00194     /// Lower bound to the step length reduction (default 0.1)
00195     double sigma1;
00196     /// Upper bound to the step length reduction (default 0.9)
00197     double sigma2;
00198     /// Relative small number (default 1.0e-7)
00199     double epsrel;
00200     /// Absolute small number (default 1.0e-10)
00201     double epsabs;
00202     /// Relative infinite number (default 1.0e20)
00203     double infrel;
00204     /// Absolute infinite number (default 1.0e99)
00205     double infabs;
00206     
00207     /// Allocate memory
00208     virtual int alloc(const size_t n) {
00209       if (this->dim>0) free();
00210       this->ao.allocate(xx,n);
00211       this->ao.allocate(d,n);
00212       this->ao.allocate(s,n);
00213       this->ao.allocate(y,n);
00214       return ool_constr_min<param_t,func_t,dfunc_t,hfunc_t,vec_t,alloc_vec_t,
00215         alloc_t>::alloc(n);
00216     }
00217     
00218     /// Free previously allocated memory
00219     virtual int free() {
00220       if (this->dim>0) this->ao.free(xx);
00221       return ool_constr_min<param_t,func_t,dfunc_t,hfunc_t,vec_t,alloc_vec_t,
00222       alloc_t>::free();
00223     }
00224     
00225     /// Set the function, the initial guess, and the parameters
00226     virtual int set(func_t &fn, dfunc_t &dfn, hfunc_t &hfn,
00227                     vec_t &init, param_t &par) {
00228       
00229       int ret=ool_constr_min<param_t,func_t,dfunc_t,hfunc_t,vec_t,alloc_vec_t,
00230       alloc_t>::set(fn,dfn,hfn,init,par);
00231       
00232       // Turn initial guess into a feasible point
00233       proj(init);
00234       
00235       // Evaluate function and gradient
00236       (*this->func)(this->dim,this->x,this->f,*this->param);
00237       (*this->dfunc)(this->dim,this->x,this->gradient,*this->param);
00238       
00239       /* Infinite norm of d <- g1 = [P(x - g) - x] */
00240       o2scl_arith::vector_copy(this->dim,this->x,d);
00241 
00242       return 0;
00243     }
00244 
00245     /// Restart the minimizer
00246     virtual int restart() {
00247       return 0;
00248     }
00249 
00250     /// Perform an iteration
00251     virtual int iterate() {
00252       double t;
00253       
00254       line_search();
00255       
00256       return 0;
00257     }
00258 
00259     /// See if we're finished
00260     virtual int is_optimal() {
00261       if (this->size>tol && this->f>fmin) {
00262         return GSL_CONTINUE;
00263       }
00264       return GSL_SUCCESS;
00265     }
00266 
00267     /// Return string denoting type ("ool_mmin_gencan")
00268     const char *type() { return "ool_mmin_gencan"; }
00269       
00270   };
00271   
00272 #ifndef DOXYGENP
00273 }
00274 #endif
00275 
00276 #endif
00277 

Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page