| [0b990d] | 1 | // | 
|---|
|  | 2 | // qnewton.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_qnewton_h | 
|---|
|  | 29 | #define _math_optimize_qnewton_h | 
|---|
|  | 30 |  | 
|---|
|  | 31 | #ifdef __GNUC__ | 
|---|
|  | 32 | #pragma interface | 
|---|
|  | 33 | #endif | 
|---|
|  | 34 |  | 
|---|
|  | 35 | #include <util/state/state.h> | 
|---|
|  | 36 | #include <util/class/class.h> | 
|---|
|  | 37 | #include <math/scmat/matrix.h> | 
|---|
|  | 38 | #include <math/optimize/function.h> | 
|---|
|  | 39 | #include <math/optimize/opt.h> | 
|---|
|  | 40 | #include <math/optimize/update.h> | 
|---|
|  | 41 |  | 
|---|
|  | 42 | namespace sc { | 
|---|
|  | 43 |  | 
|---|
|  | 44 | // ////////////////////////////////////////////////////////////////////// | 
|---|
|  | 45 | // newton and related methods | 
|---|
|  | 46 |  | 
|---|
|  | 47 |  | 
|---|
|  | 48 | /** The QNewtonOpt implements a quasi-Newton optimization scheme. */ | 
|---|
|  | 49 | class QNewtonOpt: public Optimize { | 
|---|
|  | 50 |  | 
|---|
|  | 51 | protected: | 
|---|
|  | 52 | double maxabs_gradient; | 
|---|
|  | 53 | double accuracy_; | 
|---|
|  | 54 |  | 
|---|
|  | 55 | RefSymmSCMatrix ihessian_; | 
|---|
|  | 56 | Ref<HessianUpdate> update_; | 
|---|
|  | 57 | Ref<LineOpt> lineopt_; | 
|---|
|  | 58 |  | 
|---|
|  | 59 | int take_newton_step_; | 
|---|
|  | 60 |  | 
|---|
|  | 61 | int print_hessian_; | 
|---|
|  | 62 | int print_x_; | 
|---|
|  | 63 | int print_gradient_; | 
|---|
|  | 64 | int linear_; | 
|---|
|  | 65 | int restrict_; | 
|---|
|  | 66 | int dynamic_grad_acc_; | 
|---|
|  | 67 | int force_search_; | 
|---|
|  | 68 | int restart_; | 
|---|
|  | 69 |  | 
|---|
|  | 70 | public: | 
|---|
|  | 71 | /** The KeyVal constructor. | 
|---|
|  | 72 | The KeyVal constructor reads the following keywords: | 
|---|
|  | 73 | <dl> | 
|---|
|  | 74 |  | 
|---|
|  | 75 | <dt><tt>update</tt><dd> This gives a HessianUpdate object.  The | 
|---|
|  | 76 | default is to not update the hessian. | 
|---|
|  | 77 |  | 
|---|
|  | 78 | <dt><tt>hessian</tt><dd> By default, the guess hessian is obtained | 
|---|
|  | 79 | from the Function object.  This keyword specifies an lower triangle | 
|---|
|  | 80 | array (the second index must be less than or equal to than the | 
|---|
|  | 81 | first) that replaces the guess hessian.  If some of the elements | 
|---|
|  | 82 | are not given, elements from the guess hessian will be used. | 
|---|
|  | 83 |  | 
|---|
|  | 84 | <dt><tt>lineopt</tt><dd> This gives a LineOpt object for doing line | 
|---|
|  | 85 | optimizations in the Newton direction.  The default is to skip the | 
|---|
|  | 86 | line optimizations. | 
|---|
|  | 87 |  | 
|---|
|  | 88 | <dt><tt>accuracy</tt><dd> The accuracy with which the first | 
|---|
|  | 89 | gradient will be computed.  If this is too large, it may be | 
|---|
|  | 90 | necessary to evaluate the first gradient point twice.  If it is too | 
|---|
|  | 91 | small, it may take longer to evaluate the first point. The default | 
|---|
|  | 92 | is 0.0001. | 
|---|
|  | 93 |  | 
|---|
|  | 94 | <dt><tt>print_x</tt><dd> If true, print the coordinates each | 
|---|
|  | 95 | iteration.  The default is false. | 
|---|
|  | 96 |  | 
|---|
|  | 97 | <dt><tt>print_gradient</tt><dd> If true, print the gradient each | 
|---|
|  | 98 | iteration. The default is false. | 
|---|
|  | 99 |  | 
|---|
|  | 100 | <dt><tt>print_hessian</tt><dd> If true, print the approximate | 
|---|
|  | 101 | hessian each iteration. The default is false. | 
|---|
|  | 102 |  | 
|---|
|  | 103 | <dt><tt>restrict</tt><dd> Use step size restriction when not | 
|---|
|  | 104 | using a line search.  The default is true. | 
|---|
|  | 105 |  | 
|---|
|  | 106 | </dl> */ | 
|---|
|  | 107 | QNewtonOpt(const Ref<KeyVal>&); | 
|---|
|  | 108 | QNewtonOpt(StateIn&); | 
|---|
|  | 109 | ~QNewtonOpt(); | 
|---|
|  | 110 | void save_data_state(StateOut&); | 
|---|
|  | 111 |  | 
|---|
|  | 112 | void apply_transform(const Ref<NonlinearTransform>&); | 
|---|
|  | 113 |  | 
|---|
|  | 114 | void init(); | 
|---|
|  | 115 | int update(); | 
|---|
|  | 116 | }; | 
|---|
|  | 117 |  | 
|---|
|  | 118 | } | 
|---|
|  | 119 |  | 
|---|
|  | 120 | #endif | 
|---|
|  | 121 |  | 
|---|
|  | 122 | // Local Variables: | 
|---|
|  | 123 | // mode: c++ | 
|---|
|  | 124 | // c-file-style: "ETS" | 
|---|
|  | 125 | // End: | 
|---|