00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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/group/message.h>
00036 #include <util/state/state.h>
00037 #include <util/class/class.h>
00038 #include <math/scmat/matrix.h>
00039 #include <math/optimize/function.h>
00040 #include <math/optimize/conv.h>
00041
00042 namespace sc {
00043
00044
00045
00048 class Optimize: virtual public SavableState {
00049 protected:
00050 int max_iterations_;
00051 int n_iterations_;
00052 int ckpt_;
00053 int print_timings_;
00054 double max_stepsize_;
00055 char *ckpt_file;
00056 Ref<Function> function_;
00057 Ref<Convergence> conv_;
00058 Ref<MessageGrp> msg_;
00059 public:
00060 Optimize();
00062 Optimize(StateIn&);
00063
00088 Optimize(const Ref<KeyVal>&);
00089 virtual ~Optimize();
00090
00091 void save_data_state(StateOut&);
00092
00095 virtual int optimize();
00096
00098 void set_checkpoint();
00099 void set_checkpoint_file(const char*);
00100
00102 void set_function(const Ref<Function>&);
00103
00105 void set_max_iterations(int);
00106
00108 virtual void init();
00111 virtual int update() = 0;
00112
00113 virtual void apply_transform(const Ref<NonlinearTransform>&);
00114
00116 Ref<Function> function() const { return function_; }
00117 Ref<SCMatrixKit> matrixkit() const { return function_->matrixkit(); }
00118 RefSCDimension dimension() const { return function_->dimension(); }
00119
00120 void print(std::ostream& = ExEnv::out0()) const;
00121 };
00122
00123
00126 class LineOpt: public Optimize {
00127
00128 protected:
00129
00130 RefSCVector initial_x_;
00131 double initial_value_;
00132 RefSCVector initial_grad_;
00133 RefSCVector search_direction_;
00134 Ref<Function> function_;
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
00156 void print(std::ostream& = ExEnv::out0()) const;
00157 };
00158
00159 class Backtrack: public LineOpt {
00160
00161 protected:
00162 double decrease_factor_;
00163 double backtrack_factor_;
00164 int force_search_;
00165
00166 int sufficient_decrease(RefSCVector& step);
00167
00168 public:
00169 Backtrack(const Ref<KeyVal>&);
00170 Backtrack(StateIn&s);
00171 ~Backtrack();
00172 int update();
00173 void save_data_state(StateOut&s);
00174
00175 int force_search() const { return force_search_; }
00177 double decrease_factor() { return decrease_factor_; }
00179 double set_decrease_factor( double factor )
00180 { double temp = decrease_factor_; decrease_factor_ = factor; return temp; }
00181
00182 void print(std::ostream& = ExEnv::out0()) const;
00183 };
00184
00185 }
00186
00187 #endif
00188
00189
00190
00191
00192