MPQC  3.0.0-alpha
function.h
1 //
2 // function.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_function_h
29 #define _math_optimize_function_h
30 
31 #include <math.h>
32 #include <float.h>
33 
34 #include <util/state/state.h>
35 #include <math/optimize/transform.h>
36 #include <math/scmat/matrix.h>
37 #include <math/scmat/result.h>
38 
39 namespace sc {
40 
44 class Function: virtual public SavableState, public Compute {
45  protected:
47 
53  bool desired_value_accuracy_set_to_default_;
54  bool desired_gradient_accuracy_set_to_default_;
55  bool desired_hessian_accuracy_set_to_default_;
56 
57  bool throw_if_tolerance_exceeded_;
58 
63  virtual void set_value(double);
64  virtual void set_gradient(RefSCVector&);
65  virtual void set_hessian(RefSymmSCMatrix&);
67 
70  virtual void set_matrixkit(const Ref<SCMatrixKit>&);
71  virtual void set_dimension(const RefSCDimension&);
72 
77  virtual void set_actual_value_accuracy(double);
78  virtual void set_actual_gradient_accuracy(double);
79  virtual void set_actual_hessian_accuracy(double);
81 
84 
88  public:
89  Function();
90  Function(StateIn&);
91  Function(const Function&);
92 
113  Function(const Ref<KeyVal>&, double funcacc = DBL_EPSILON,
114  double gradacc = DBL_EPSILON, double hessacc = DBL_EPSILON);
115  virtual ~Function();
116 
117  Function & operator=(const Function&);
118 
121  Ref<SCMatrixKit> matrixkit() const;
123  RefSCDimension dimension() const;
124 
125  virtual void save_data_state(StateOut&);
126 
128  virtual double value();
130  int value_needed() const;
134  int do_value(int);
135  AccResultdouble& value_result() { return value_; }
136 
138  virtual void set_desired_value_accuracy(double);
140  virtual double actual_value_accuracy() const;
142  virtual double desired_value_accuracy() const;
143 
148  virtual RefSCVector gradient();
149  int gradient_needed() const;
150  int do_gradient(int);
151  virtual void set_desired_gradient_accuracy(double);
152  virtual double actual_gradient_accuracy() const;
153  virtual double desired_gradient_accuracy() const;
154  AccResultRefSCVector& gradient_result() { return gradient_; }
156 
161  virtual RefSymmSCMatrix hessian();
162  int hessian_needed() const;
163  int do_hessian(int);
164  virtual void set_desired_hessian_accuracy(double);
165  virtual double actual_hessian_accuracy() const;
166  virtual double desired_hessian_accuracy() const;
167  AccResultRefSymmSCMatrix& hessian_result() { return hessian_; }
169 
173  virtual bool desired_value_accuracy_set_to_default() const;
174  virtual bool desired_gradient_accuracy_set_to_default() const;
175  virtual bool desired_hessian_accuracy_set_to_default() const;
177 
179  virtual void guess_hessian(RefSymmSCMatrix&);
180  virtual RefSymmSCMatrix inverse_hessian(RefSymmSCMatrix&);
181 
185  virtual int value_implemented() const;
188  virtual int gradient_implemented() const;
190  virtual int hessian_implemented() const;
192 
194  virtual void set_x(const RefSCVector&);
195  RefSCVector get_x() const { return x_.copy(); }
196  const RefSCVector& get_x_no_copy() const { return x_; }
197 
204  virtual Ref<NonlinearTransform> change_coordinates();
205 
207  virtual void print(std::ostream& = ExEnv::out0()) const;
209  void print_desired_accuracy(std::ostream& = ExEnv::out0()) const;
210 
212  virtual bool throw_if_tolerance_exceeded() const;
213 };
214 
215 }
216 
217 #endif
218 
219 // Local Variables:
220 // mode: c++
221 // c-file-style: "CLJ"
222 // End:
sc::Function::matrixkit_
Ref< SCMatrixKit > matrixkit_
Used to construct new matrices.
Definition: function.h:46
sc::Function::matrixkit
Ref< SCMatrixKit > matrixkit() const
Return the SCMatrixKit used to construct vectors and matrices.
sc::RefSymmSCMatrix
The RefSymmSCMatrix class is a smart pointer to an SCSymmSCMatrix specialization.
Definition: matrix.h:265
sc::Function::dim_
RefSCDimension dim_
The dimension of x_.
Definition: function.h:49
sc::Function::set_desired_value_accuracy
virtual void set_desired_value_accuracy(double)
Set the accuracy to which the value is to be computed.
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
sc::Function::print_desired_accuracy
void print_desired_accuracy(std::ostream &=ExEnv::out0()) const
similar to print(), but only prins desired accuracies
sc::Function::print
virtual void print(std::ostream &=ExEnv::out0()) const
Print information about the object.
sc::Function::throw_if_tolerance_exceeded
virtual bool throw_if_tolerance_exceeded() const
Overridden Compute member.
sc::Function::hessian_implemented
virtual int hessian_implemented() const
sc::Function::desired_value_accuracy
virtual double desired_value_accuracy() const
Return the accuracy with which the value is to be computed.
sc::Function
The Function class is an abstract base class that, given a set of coordinates, will compute a value a...
Definition: function.h:44
sc::AccResult< RefSCVector >
sc::Function::gradient_
AccResultRefSCVector gradient_
The gradient at x_.
Definition: function.h:51
sc::Function::do_value
int do_value(int)
If passed a nonzero number, compute the value the next time compute() is called.
sc::StateIn
Definition: statein.h:79
sc::Function::gradient_implemented
virtual int gradient_implemented() const
sc::RefSCDimension
The RefSCDimension class is a smart pointer to an SCDimension specialization.
Definition: dim.h:152
sc::Function::actual_value_accuracy
virtual double actual_value_accuracy() const
Return the accuracy with which the value has been computed.
sc::Function::hessian_
AccResultRefSymmSCMatrix hessian_
The hessian at x_.
Definition: function.h:52
sc::Compute::obsolete
virtual void obsolete()
Marks all results as being out of date.
sc::Function::set_x
virtual void set_x(const RefSCVector &)
Set and retrieve the coordinate values.
sc::Function::get_x_reference
RefSCVector & get_x_reference()
Get read/write access to the coordinates for modification.
Definition: function.h:83
sc::Function::dimension
RefSCDimension dimension() const
Return the SCDimension of the problem.
sc::Function::save_data_state
virtual 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::Function::guess_hessian
virtual void guess_hessian(RefSymmSCMatrix &)
Compute a quick, approximate hessian.
sc::RefSCVector
The RefSCVector class is a smart pointer to an SCVector specialization.
Definition: matrix.h:55
sc::StateOut
Definition: stateout.h:71
sc::Compute
The Compute class provides a means of keeping results up to date.
Definition: compute.h:51
sc::Function::value_
AccResultdouble value_
The value of the function at x_.
Definition: function.h:50
sc::NCAccResult< double >
sc::Function::value_implemented
virtual int value_implemented() const
sc::Function::value
virtual double value()
Return the value of the function.
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::Function::x_
RefSCVector x_
The variables.
Definition: function.h:48
sc::SavableState
Base class for objects that can save/restore state.
Definition: state.h:45
sc::Function::change_coordinates
virtual Ref< NonlinearTransform > change_coordinates()
An optimizer can call change coordinates periodically to give the function an opportunity to change i...
sc::Function::value_needed
int value_needed() const
Returns nonzero if the current value is not up-to-date.
sc::Function::set_matrixkit
virtual void set_matrixkit(const Ref< SCMatrixKit > &)
Set the SCMatrixKit that should be used to construct the requisite vectors and matrices.
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::Function::do_change_coordinates
void do_change_coordinates(const Ref< NonlinearTransform > &)
Change the coordinate system and apply the given transform to intermediates matrices and vectors.

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