00001 // 00002 // function.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 #ifdef __GNUC__ 00029 #pragma interface 00030 #endif 00031 00032 #ifndef _math_optimize_function_h 00033 #define _math_optimize_function_h 00034 00035 #include <math.h> 00036 #include <float.h> 00037 00038 #include <util/state/state.h> 00039 #include <math/optimize/transform.h> 00040 #include <math/scmat/matrix.h> 00041 #include <math/scmat/result.h> 00042 00043 namespace sc { 00044 00048 class Function: virtual public SavableState, public Compute { 00049 protected: 00050 Ref<SCMatrixKit> matrixkit_; 00051 00052 RefSCVector x_; 00053 RefSCDimension dim_; 00054 AccResultdouble value_; 00055 AccResultRefSCVector gradient_; 00056 AccResultRefSymmSCMatrix hessian_; 00057 00058 bool throw_if_tolerance_exceeded_; 00059 00064 virtual void set_value(double); 00065 virtual void set_gradient(RefSCVector&); 00066 virtual void set_hessian(RefSymmSCMatrix&); 00068 00071 virtual void set_matrixkit(const Ref<SCMatrixKit>&); 00072 virtual void set_dimension(const RefSCDimension&); 00073 00078 virtual void set_actual_value_accuracy(double); 00079 virtual void set_actual_gradient_accuracy(double); 00080 virtual void set_actual_hessian_accuracy(double); 00082 00084 RefSCVector& get_x_reference() { obsolete(); return x_; } 00085 00088 void do_change_coordinates(const Ref<NonlinearTransform>&); 00089 public: 00090 Function(); 00091 Function(StateIn&); 00092 Function(const Function&); 00093 00114 Function(const Ref<KeyVal>&, double funcacc = DBL_EPSILON, 00115 double gradacc = DBL_EPSILON, double hessacc = DBL_EPSILON); 00116 virtual ~Function(); 00117 00118 Function & operator=(const Function&); 00119 00122 Ref<SCMatrixKit> matrixkit() const; 00124 RefSCDimension dimension() const; 00125 00126 virtual void save_data_state(StateOut&); 00127 00129 virtual double value(); 00131 int value_needed() const; 00135 int do_value(int); 00136 AccResultdouble& value_result() { return value_; } 00137 00139 virtual void set_desired_value_accuracy(double); 00141 virtual double actual_value_accuracy() const; 00143 virtual double desired_value_accuracy() const; 00144 00149 virtual RefSCVector gradient(); 00150 int gradient_needed() const; 00151 int do_gradient(int); 00152 virtual void set_desired_gradient_accuracy(double); 00153 virtual double actual_gradient_accuracy() const; 00154 virtual double desired_gradient_accuracy() const; 00155 AccResultRefSCVector& gradient_result() { return gradient_; } 00157 00162 virtual RefSymmSCMatrix hessian(); 00163 int hessian_needed() const; 00164 int do_hessian(int); 00165 virtual void set_desired_hessian_accuracy(double); 00166 virtual double actual_hessian_accuracy() const; 00167 virtual double desired_hessian_accuracy() const; 00168 AccResultRefSymmSCMatrix& hessian_result() { return hessian_; } 00170 00171 // hessian by gradients at finite displacements 00172 // virtual RefSCMatrix fd1_hessian(); 00173 00175 virtual void guess_hessian(RefSymmSCMatrix&); 00176 virtual RefSymmSCMatrix inverse_hessian(RefSymmSCMatrix&); 00177 00180 virtual int value_implemented() const; 00181 virtual int gradient_implemented() const; 00182 virtual int hessian_implemented() const; 00183 00185 virtual void set_x(const RefSCVector&); 00186 RefSCVector get_x() const { return x_.copy(); } 00187 const RefSCVector& get_x_no_copy() const { return x_; } 00188 00195 virtual Ref<NonlinearTransform> change_coordinates(); 00196 00198 virtual void print(std::ostream& = ExEnv::out0()) const; 00199 00201 virtual bool throw_if_tolerance_exceeded() const; 00202 }; 00203 00204 } 00205 00206 #endif 00207 00208 // Local Variables: 00209 // mode: c++ 00210 // c-file-style: "CLJ" 00211 // End: