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 00046 class Function: virtual public SavableState, public Compute { 00047 protected: 00048 Ref<SCMatrixKit> matrixkit_; 00049 00050 RefSCVector x_; 00051 RefSCDimension dim_; 00052 AccResultdouble value_; 00053 AccResultRefSCVector gradient_; 00054 AccResultRefSymmSCMatrix hessian_; 00055 00060 virtual void set_value(double); 00061 virtual void set_gradient(RefSCVector&); 00062 virtual void set_hessian(RefSymmSCMatrix&); 00064 00067 virtual void set_matrixkit(const Ref<SCMatrixKit>&); 00068 virtual void set_dimension(const RefSCDimension&); 00069 00074 virtual void set_actual_value_accuracy(double); 00075 virtual void set_actual_gradient_accuracy(double); 00076 virtual void set_actual_hessian_accuracy(double); 00078 00080 RefSCVector& get_x_reference() { obsolete(); return x_; } 00081 00084 void do_change_coordinates(const Ref<NonlinearTransform>&); 00085 public: 00086 Function(); 00087 Function(StateIn&); 00088 Function(const Function&); 00089 00106 Function(const Ref<KeyVal>&, double funcacc = DBL_EPSILON, 00107 double gradacc = DBL_EPSILON, double hessacc = DBL_EPSILON); 00108 virtual ~Function(); 00109 00110 Function & operator=(const Function&); 00111 00114 Ref<SCMatrixKit> matrixkit() const; 00116 RefSCDimension dimension() const; 00117 00118 virtual void save_data_state(StateOut&); 00119 00121 virtual double value(); 00123 int value_needed() const; 00127 int do_value(int); 00128 AccResultdouble& value_result() { return value_; } 00129 00131 virtual void set_desired_value_accuracy(double); 00133 virtual double actual_value_accuracy() const; 00135 virtual double desired_value_accuracy() const; 00136 00141 virtual RefSCVector gradient(); 00142 int gradient_needed() const; 00143 int do_gradient(int); 00144 virtual void set_desired_gradient_accuracy(double); 00145 virtual double actual_gradient_accuracy() const; 00146 virtual double desired_gradient_accuracy() const; 00147 AccResultRefSCVector& gradient_result() { return gradient_; } 00149 00154 virtual RefSymmSCMatrix hessian(); 00155 int hessian_needed() const; 00156 int do_hessian(int); 00157 virtual void set_desired_hessian_accuracy(double); 00158 virtual double actual_hessian_accuracy() const; 00159 virtual double desired_hessian_accuracy() const; 00160 AccResultRefSymmSCMatrix& hessian_result() { return hessian_; } 00162 00163 // hessian by gradients at finite displacements 00164 // virtual RefSCMatrix fd1_hessian(); 00165 00167 virtual void guess_hessian(RefSymmSCMatrix&); 00168 virtual RefSymmSCMatrix inverse_hessian(RefSymmSCMatrix&); 00169 00172 virtual int value_implemented() const; 00173 virtual int gradient_implemented() const; 00174 virtual int hessian_implemented() const; 00175 00177 virtual void set_x(const RefSCVector&); 00178 RefSCVector get_x() const { return x_.copy(); } 00179 const RefSCVector& get_x_no_copy() const { return x_; } 00180 00187 virtual Ref<NonlinearTransform> change_coordinates(); 00188 00190 virtual void print(std::ostream& = ExEnv::out()) const; 00191 }; 00192 00193 00194 #endif 00195 00196 // Local Variables: 00197 // mode: c++ 00198 // c-file-style: "CLJ" 00199 // End: