MPQC 3.0.0-alpha
Loading...
Searching...
No Matches
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
38namespace sc {
39
40// //////////////////////////////////////////////////////////////////////
41
44class 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();
62
88 virtual ~Optimize();
89
91
94 virtual int optimize();
95
98 void set_checkpoint_file(const char*);
99
102
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
125class 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();
139 LineOpt(const Ref<KeyVal>&);
140 ~LineOpt();
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
161class Backtrack: public LineOpt {
162
163 protected:
164 double decrease_factor_;
165 double backtrack_factor_;
166 int force_search_;
167
174
175 public:
176 Backtrack();
196 ~Backtrack();
197 int update();
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:
Implements backtrack line search algorithm.
Definition opt.h:161
int sufficient_decrease(RefSCVector &step)
answers the question whether a given step satisfies the sufficient decrease (Armijo) condition
Backtrack(const Ref< KeyVal > &)
A KeyVal constructor is used to generate a Backtrack object from the input.
double set_decrease_factor(double factor)
Sets factor for sufficient decrease test.
Definition opt.h:204
double decrease_factor()
Returns factor for sufficient decrease test.
Definition opt.h:202
void print(std::ostream &=ExEnv::out0()) const
Print the object.
int update()
Take a step.
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 ...
static std::ostream & out0()
Return an ostream that writes from node 0.
The LineOpt abstract class is used to perform one dimensional optimizations.
Definition opt.h:125
virtual void init(RefSCVector &direction)
Initializes the line search object.
void print(std::ostream &=ExEnv::out0()) const
Print the object.
void apply_transform(const Ref< NonlinearTransform > &)
Applies a nonlinear transform.
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
virtual void init(RefSCVector &direction, Ref< Function > function)
Initializes the line search object.
The Optimize class is an abstract base class for classes that find the extreme points of Function's.
Definition opt.h:44
void set_max_iterations(int)
Set the iteration limit.
void set_checkpoint()
Set up for checkpointing.
void init()
Initialize the optimizer.
Optimize(StateIn &)
Restore the state of a Function object.
Ref< Function > function() const
Returns information about the Function being optimized.
Definition opt.h:113
void set_function(const Ref< Function > &)
Set the function to be optimized.
virtual int optimize()
Do the optimization.
virtual int update()=0
Take a step.
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
Ref< Convergence > convergence() const
Return information about the Convergence object being used.
Definition opt.h:115
void print(std::ostream &=ExEnv::out0()) const
Print the object.
Optimize(const Ref< KeyVal > &)
The KeyVal constructor reads the following information:
The RefSCVector class is a smart pointer to an SCVector specialization.
Definition matrix.h:55
A template class that maintains references counts.
Definition ref.h:361
Base class for objects that can save/restore state.
Definition state.h:45
Restores fundamental and user-defined types from images created with StateOut.
Definition statein.h:79
Serializes fundamental and user-defined types.
Definition stateout.h:71
Contains all MPQC code up to version 3.
Definition mpqcin.h:14

Generated at Wed Sep 25 2024 02:45:30 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.12.0.