MPQC  3.0.0-alpha
opt.h
1 //
2 // opt.h
3 //
4 // Copyright (C) 1996 Limit Point Systems, Inc.
5 //
6 // Author: Curtis Janssen <cljanss@limitpt.com>
7 // Maintainer: LPS
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 #ifndef _math_optimize_opt_h
29 #define _math_optimize_opt_h
30 
31 #include <util/group/message.h>
32 #include <util/state/state.h>
33 #include <util/class/class.h>
34 #include <math/scmat/matrix.h>
35 #include <math/optimize/function.h>
36 #include <math/optimize/conv.h>
37 
38 namespace sc {
39 
40 // //////////////////////////////////////////////////////////////////////
41 
44 class Optimize: virtual public SavableState {
45  protected:
46  int max_iterations_;
47  int n_iterations_;
48  int ckpt_;
49  int print_timings_;
50  double max_stepsize_;
51  std::string ckpt_file_;
52  Ref<Function> function_;
53  Ref<Convergence> conv_;
54  Ref<MessageGrp> msg_;
56  void init();
57 
58  public:
59  Optimize();
61  Optimize(StateIn&);
62 
87  Optimize(const Ref<KeyVal>&);
88  virtual ~Optimize();
89 
91 
94  virtual int optimize();
95 
97  void set_checkpoint();
98  void set_checkpoint_file(const char*);
99 
101  void set_function(const Ref<Function>&);
102 
104  void set_max_iterations(int);
105 
108  virtual int update() = 0;
109 
110  virtual void apply_transform(const Ref<NonlinearTransform>&);
111 
113  Ref<Function> function() const { return function_; }
115  Ref<Convergence> convergence() const { return conv_; }
116  Ref<SCMatrixKit> matrixkit() const { return function_->matrixkit(); }
117  RefSCDimension dimension() const { return function_->dimension(); }
118 
119  void print(std::ostream& = ExEnv::out0()) const;
120 };
121 
122 
125 class LineOpt: public Optimize {
126 
127  protected:
128 
129  RefSCVector initial_x_;
130  double initial_value_;
131  RefSCVector initial_grad_;
132  RefSCVector search_direction_;
133  Ref<Function> function_;
134 
135  public:
136 
137  LineOpt();
138  LineOpt(StateIn&);
139  LineOpt(const Ref<KeyVal>&);
140  ~LineOpt();
141  void save_data_state(StateOut&);
142 
146  virtual void init(RefSCVector& direction);
151  virtual void init(RefSCVector& direction, Ref<Function> function);
154 
155  void print(std::ostream& = ExEnv::out0()) const;
156 };
157 
161 class Backtrack: public LineOpt {
162 
163  protected:
164  double decrease_factor_;
165  double backtrack_factor_;
166  int force_search_;
167 
173  int sufficient_decrease(RefSCVector& step);
174 
175  public:
176  Backtrack();
194  Backtrack(const Ref<KeyVal>&);
195  Backtrack(StateIn&s);
196  ~Backtrack();
197  int update();
198  void save_data_state(StateOut&s);
199 
200  int force_search() const { return force_search_; }
202  double decrease_factor() { return decrease_factor_; }
204  double set_decrease_factor( double factor )
205  { double temp = decrease_factor_; decrease_factor_ = factor; return temp; }
206 
207  void print(std::ostream& = ExEnv::out0()) const;
208 };
209 
210 }
211 
212 #endif
213 
214 // Local Variables:
215 // mode: c++
216 // c-file-style: "CLJ"
217 // End:
sc::LineOpt::apply_transform
void apply_transform(const Ref< NonlinearTransform > &)
Applies a nonlinear transform.
sc::Optimize::convergence
Ref< Convergence > convergence() const
Return information about the Convergence object being used.
Definition: opt.h:115
sc::Backtrack::sufficient_decrease
int sufficient_decrease(RefSCVector &step)
answers the question whether a given step satisfies the sufficient decrease (Armijo) condition
sc::LineOpt
The LineOpt abstract class is used to perform one dimensional optimizations.
Definition: opt.h:125
sc::Backtrack::set_decrease_factor
double set_decrease_factor(double factor)
Sets factor for sufficient decrease test.
Definition: opt.h:204
sc::Optimize::init
void init()
Initialize the optimizer.
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
sc::Optimize::save_data_state
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::Optimize
The Optimize class is an abstract base class for classes that find the extreme points of Function's.
Definition: opt.h:44
sc::LineOpt::save_data_state
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::Backtrack::update
int update()
Take a step.
sc::StateIn
Definition: statein.h:79
sc::Optimize::set_max_iterations
void set_max_iterations(int)
Set the iteration limit.
sc::Optimize::set_checkpoint
void set_checkpoint()
Set up for checkpointing.
sc::Backtrack::save_data_state
void save_data_state(StateOut &s)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::RefSCVector
The RefSCVector class is a smart pointer to an SCVector specialization.
Definition: matrix.h:55
sc::StateOut
Definition: stateout.h:71
sc::LineOpt::print
void print(std::ostream &=ExEnv::out0()) const
Print the object.
sc::Optimize::update
virtual int update()=0
Take a step.
sc::Backtrack::print
void print(std::ostream &=ExEnv::out0()) const
Print the object.
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::Optimize::set_function
void set_function(const Ref< Function > &)
Set the function to be optimized.
sc::Backtrack::decrease_factor
double decrease_factor()
Returns factor for sufficient decrease test.
Definition: opt.h:202
sc::SavableState
Base class for objects that can save/restore state.
Definition: state.h:45
sc::Optimize::print
void print(std::ostream &=ExEnv::out0()) const
Print the object.
sc::Optimize::optimize
virtual int optimize()
Do the optimization.
sc::Backtrack
Implements backtrack line search algorithm.
Definition: opt.h:161
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14

Generated at Sun Jan 26 2020 23:24:00 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.