opt.h

00001 //
00002 // opt.h
00003 //
00004 // Copyright (C) 1996 Limit Point Systems, Inc.
00005 //
00006 // Author: Curtis Janssen <cljanss@limitpt.com>
00007 // Maintainer: LPS
00008 //
00009 // This file is part of the SC Toolkit.
00010 //
00011 // The SC Toolkit is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Library General Public License as published by
00013 // the Free Software Foundation; either version 2, or (at your option)
00014 // any later version.
00015 //
00016 // The SC Toolkit is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU Library General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Library General Public License
00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00024 //
00025 // The U.S. Government is granted a limited license as per AL 91-7.
00026 //
00027 
00028 #ifndef _math_optimize_opt_h
00029 #define _math_optimize_opt_h
00030 
00031 #ifdef __GNUC__
00032 #pragma interface
00033 #endif
00034 
00035 #include <util/state/state.h>
00036 #include <util/class/class.h>
00037 #include <math/scmat/matrix.h>
00038 #include <math/optimize/function.h>
00039 #include <math/optimize/conv.h>
00040 
00041 namespace sc {
00042 
00043 // //////////////////////////////////////////////////////////////////////
00044 
00047 class Optimize: virtual public SavableState {
00048   protected:
00049     int max_iterations_;
00050     int n_iterations_;
00051     int ckpt_;
00052     int print_timings_;
00053     double max_stepsize_;
00054     char *ckpt_file;
00055     Ref<Function> function_;
00056     Ref<Convergence> conv_;
00057   public:
00058     Optimize();
00060     Optimize(StateIn&);
00061 
00086     Optimize(const Ref<KeyVal>&);
00087     virtual ~Optimize();
00088 
00089     void save_data_state(StateOut&);
00090 
00093     virtual int optimize();
00094 
00096     void set_checkpoint();
00097     void set_checkpoint_file(const char*);
00098 
00100     void set_function(const Ref<Function>&);
00101     
00103     void set_max_iterations(int);
00104   
00106     virtual void init();
00109     virtual int update() = 0;
00110 
00111     virtual void apply_transform(const Ref<NonlinearTransform>&);
00112 
00114     Ref<Function> function() const { return function_; }
00115     Ref<SCMatrixKit> matrixkit() const { return function_->matrixkit(); }
00116     RefSCDimension dimension() const { return function_->dimension(); }
00117 
00118 };
00119 
00120 
00123 class LineOpt: public Optimize {
00124 
00125   protected:
00126 
00127     double decrease_factor_;
00128     RefSCVector initial_x_;
00129     double initial_value_;
00130     RefSCVector initial_grad_;
00131     RefSCVector search_direction_;
00132     Ref<Function> function_;
00133     
00134     int sufficient_decrease(RefSCVector& step);
00135 
00136   public:
00137 
00138     LineOpt();
00139     LineOpt(StateIn&);
00140     LineOpt(const Ref<KeyVal>&);
00141     ~LineOpt();
00142     void save_data_state(StateOut&);
00143 
00147     virtual void init(RefSCVector& direction);
00152     virtual void init(RefSCVector& direction, Ref<Function> function);
00154     void apply_transform(const Ref<NonlinearTransform>&);
00155   
00157     double decrease_factor() { return decrease_factor_; }
00159     double set_decrease_factor( double factor ) 
00160     { double temp = decrease_factor_; decrease_factor_ = factor; return temp; }
00161 };
00162 
00163 class Backtrack: public LineOpt {
00164 
00165  protected:
00166    double backtrack_factor_;
00167 
00168  public:
00169    Backtrack(const Ref<KeyVal>&);
00170    ~Backtrack(){}
00171    int update();
00172 
00173 };
00174 
00175 }
00176 
00177 #endif
00178 
00179 // Local Variables:
00180 // mode: c++
00181 // c-file-style: "CLJ"
00182 // End:

Generated at Mon Dec 3 23:23:40 2007 for MPQC 2.3.1 using the documentation package Doxygen 1.5.2.