| 1 | /****************************************************************************/cxx . . $ `<file>/src/Algo/BrentLS.hpp`/ |
| 2 | /* This file is part of FreeFEM. */ |
| 3 | /* */ |
| 4 | /* FreeFEM is free software: you can redistribute it and/or modify */ |
| 5 | /* it under the terms of the GNU Lesser General Public License as */ |
| 6 | /* published by the Free Software Foundation, either version 3 of */ |
| 7 | /* the License, or (at your option) any later version. */ |
| 8 | /* */ |
| 9 | /* FreeFEM is distributed in the hope that it will be useful, */ |
| 10 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 11 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ |
| 12 | /* GNU Lesser General Public License for more details. */ |
| 13 | /* */ |
| 14 | /* You should have received a copy of the GNU Lesser General Public License */ |
| 15 | /* along with FreeFEM. If not, see <http://www.gnu.org/licenses/>. */ |
| 16 | /****************************************************************************/ |
| 17 | // SUMMARY : ... |
| 18 | // LICENSE : LGPLv3 |
| 19 | // ORG : LJLL Universite Pierre et Marie Curie, Paris, FRANCE |
| 20 | // AUTHORS : ... |
| 21 | // E-MAIL : ... |
| 22 | |
| 23 | //====================================================================== |
| 24 | // Definition of the BrentLineSearch class |
| 25 | // Brent's line search algorithm |
| 26 | // author: Wenceslau Gouveia, Adapted from Numerical Recipes in C |
| 27 | // Modified to fit into new classes. H. Lydia Deng, 02/21/94, 03/15/94 |
| 28 | // Tony : cf. page 301 section 10.2 |
| 29 | //======================================================================== |
| 30 | // .B BrentLineSearch() |
| 31 | // This routine, inpired by the Numerical Recipes book, performs a unidimensional search |
| 32 | // for the minimum of the objective function along a specified direction. The minimum is |
| 33 | // at first bracket using the Golden search procedure. After bracketing the Brent's |
| 34 | // algorithm is used to isolate the minimum to a fractional precision of about the specified |
| 35 | // tolerance. |
| 36 | // |
| 37 | // .SECTION Description |
| 38 | // Public Operations |
| 39 | // Constructors: |
| 40 | // BrentLineSearch (ObjectiveFunction *f, int iter); |
| 41 | // Here: |
| 42 | // f: Define the objective function |
| 43 | // iter: Maximum number of iterations |
| 44 | // Methods: |
| 45 | // model <> BrentLineSearch::search(Model<double>& model0, Vector<double>& direction, |
| 46 | // double tol, double delta) |
| 47 | // Here: |
| 48 | // model0: Initial model to initiate the bracketing procedure |
| 49 | // direction: Vector that defines the direction of the line search |
| 50 | // tol: The minimum is within the returned this->value +/- tol |
| 51 | // delta: Used in the bracketing procedure. The initial interval |
| 52 | // for the bracketing is from 0 to delta * STEP_MAX, where |
| 53 | // STEP_MAX is hard coded to 5. |
| 54 | // |
| 55 | // The sought minimum is returned by the function. |
| 56 | // |
| 57 | // .SECTION Caveats |
| 58 | // This line search was not thoroughly tested. The CubicLineSearch procedure, that requires |
| 59 | // certain derivative information on the objective function (that can be provided by numerical |
| 60 | // methods) has demonstrated to be a more efficient line search procedure. |
| 61 | |
| 62 | // Cela me semble louche... cf. les commentaires BIZARRE ! |
| 63 | // Ceci dit, le premiers tests semblent OK... |
| 64 | |
| 65 | #include "defs.hpp"cxx . . $ `<file>/src/Algo/defs.hpp`/ |
| 66 | #include <cstdio> |
| 67 | |
| 68 | #ifndef BRENT_LINE_SEARCH_HH |
| 69 | #define BRENT_LINE_SEARCH_HHcxx . . $ `src/Algo/BrentLS.hpp:69:9`! |
| 70 | |
| 71 | #include "LineSearch.hpp"cxx . . $ `<file>/src/Algo/LineSearch.hpp`/ |
| 72 | |
| 73 | #define CGOLDcxx . . $ `src/Algo/BrentLS.hpp:73:9`! .3819660 |
| 74 | #define ZEPScxx . . $ `src/Algo/BrentLS.hpp:74:9`! 1.e-10 |
| 75 | #define GOLDcxx . . $ `src/Algo/BrentLS.hpp:75:9`! 1.618034 |
| 76 | #define STEP_MAXcxx . . $ `src/Algo/BrentLS.hpp:76:9`! 5 |
| 77 | #define GLIMITcxx . . $ `src/Algo/BrentLS.hpp:77:9`! 100. |
| 78 | |
| 79 | /* |
| 80 | BrentLineSearch class was inpired by the Numerical Recipes book, |
| 81 | performs an unidimensional search for the minimum of the objective |
| 82 | function along a specified direction. The minimum is at first |
| 83 | bracket using the Golden search procedure. After bracketing |
| 84 | the Brent's algorithm is used to isolate the minimum to a |
| 85 | fractional precision of about the specified tolerance. |
| 86 | |
| 87 | This line search was not thoroughly tested. The |
| 88 | CubicLineSearch procedure, that requires certain |
| 89 | derivative information on the objective function |
| 90 | (that can be provided by numerical methods) has |
| 91 | demonstrated to be a more efficient line search procedure. |
| 92 | |
| 93 | */ |
| 94 | |
| 95 | template< class LS > |
| 96 | class BrentLineSearchcxx . . $ BrentLineSearch# : public LS { |
| 97 | typedef typename LS::Real Realcxx . . $ BrentLineSearch#Real#; |
| 98 | typedef typename LS::Param Paramcxx . . $ BrentLineSearch#Param#; |
| 99 | typedef typename LS::Vect Vectcxx . . $ BrentLineSearch#Vect#; |
| 100 | typedef typename LS::VMat VMatcxx . . $ BrentLineSearch#VMat#; |
| 101 | typedef typename LS::Mat Matcxx . . $ BrentLineSearch#Mat#; |
| 102 | typedef typename LS::NRJ NRJcxx . . $ BrentLineSearch#NRJ#; |
| 103 | |
| 104 | public: |
| 105 | BrentLineSearchcxx . . $ BrentLineSearch#`BrentLineSearch<LS>`(5ee6e0b1bac895c1).(NRJcxx . . $ BrentLineSearch#NRJ# *f, int iter); |
| 106 | ~cxx . . $ BrentLineSearch#`~BrentLineSearch<LS>`(49f6e7a06ebc5aa8).BrentLineSearch( ); |
| 107 | |
| 108 | // Implementation of the Brent Search |
| 109 | // search for minimum model along a 1-D direction |
| 110 | Paramcxx . . $ BrentLineSearch#Param# searchcxx . . $ BrentLineSearch#search(6c3890faa1cd9ad5).(Paramcxx . . $ BrentLineSearch#Param# &m0, // initial model to initiate the bracketing procedure |
| 111 | Vectcxx . . $ BrentLineSearch#Vect# &direction, // the direction of the line search |
| 112 | Realcxx . . $ BrentLineSearch#Real# tol, // the minimum is within the returned this->value +/- tol |
| 113 | double delta); // a parameter used in the bracketing procedure |
| 114 | /*The initial interval for the bracketing is from $0$ to |
| 115 | $delta \times STEP\_MAX$, where $STEP\_MAX$ is hard coded to $5$. |
| 116 | The sought minimum is returned by the function. */ |
| 117 | //@ManMemo: search for minimum model along a 1-D direction |
| 118 | }; |
| 119 | |
| 120 | template< class LS > |
| 121 | BrentLineSearchcxx . . $ BrentLineSearch#< LS >::BrentLineSearchcxx . . $ BrentLineSearch#`BrentLineSearch<LS>`(5ee6e0b1bac895c1).(NRJcxx . . $ BrentLineSearch#NRJ# *f, int it) : LS(f) { |
| 122 | this->iterMax = it; |
| 123 | } |
| 124 | |
| 125 | template< class LS > |
| 126 | BrentLineSearchcxx . . $ BrentLineSearch#< LS >::~cxx . . $ BrentLineSearch#`~BrentLineSearch<LS>`(49f6e7a06ebc5aa8).BrentLineSearch( ) { |
| 127 | ; |
| 128 | } |
| 129 | |
| 130 | // Code for the BrentBrent line search |
| 131 | template< class LS > |
| 132 | typename BrentLineSearchcxx . . $ BrentLineSearch#< LS >::Paramcxx . . $ BrentLineSearch#Param# BrentLineSearchcxx . . $ BrentLineSearch#< LS >::searchcxx . . $ BrentLineSearch#search(6c3890faa1cd9ad5).(Paramcxx . . $ BrentLineSearch#Param# &model0, Vectcxx . . $ BrentLineSearch#Vect# &direction, |
| 133 | Realcxx . . $ BrentLineSearch#Real# tol, double delta) { |
| 134 | this->iterNum = 0; |
| 135 | KNcxx . . $ KN#< double > stepscxx . . $ KN#KN(1624ee8275b10bda).(3); // brackets |
| 136 | Vectcxx . . $ BrentLineSearch#Vect# of_values(3); // OF evaluated inside bracket |
| 137 | Realcxx . . $ BrentLineSearch#Real# dum; // auxiliary quantity |
| 138 | Realcxx . . $ BrentLineSearch#Real# r, q, ulim; // auxiliary quantity |
| 139 | Realcxx . . $ BrentLineSearch#Real# u, fu; // define the new bracket limit |
| 140 | |
| 141 | // Variables related to Brent's algorithm |
| 142 | Realcxx . . $ BrentLineSearch#Real# d, fv, fw, fx, p; // auxiliary variables |
| 143 | double v, w; // auxiliary variables |
| 144 | double x, e = 0., etemp; // auxiliary variables |
| 145 | int i; // counter |
| 146 | |
| 147 | // Ajout Tony |
| 148 | d = 0; // Sinon, il n'est pas initialise : BIZARRE ! |
| 149 | |
| 150 | // Beggining of the bracketing stage |
| 151 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0] = 0.; |
| 152 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1] = STEP_MAXcxx . . $ `src/Algo/BrentLS.hpp:76:9`! * delta; |
| 153 | |
| 154 | of_values[0] = this->nrj->getVal(model0); |
| 155 | of_values[1] = this->nrj->getVal(update(model0, 1, steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1], direction)); |
| 156 | this->iterNum +=cxx . . $ `operator+=`(d02e6a613fcf7dc7). 2; |
| 157 | |
| 158 | if (of_values[1] >cxx . . $ std/`operator>`(c2ad8cf295ccec45). of_values[0]) { |
| 159 | dum = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0]; |
| 160 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0] = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1]; |
| 161 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1] = dum; |
| 162 | dum = of_values[0]; |
| 163 | of_values[0] = of_values[1]; |
| 164 | of_values[1] = dum; |
| 165 | } |
| 166 | |
| 167 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1] + GOLDcxx . . $ `src/Algo/BrentLS.hpp:75:9`! * (steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1] - steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0]); |
| 168 | of_values[2] = this->nrj->getVal(update(model0, 1, steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2], direction)); |
| 169 | this->iterNum++; |
| 170 | while (of_values[1] >cxx . . $ std/`operator>`(c2ad8cf295ccec45). of_values[2]) { |
| 171 | r = (steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1] - steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0]) *cxx . . $ `operator*`(ca0d58f853b0940). (of_values[1] -cxx . . $ operator-(4b6fd085471a9fb1). of_values[2]); |
| 172 | q = (steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1] - steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2]) *cxx . . $ `operator*`(ca0d58f853b0940). (of_values[1] -cxx . . $ operator-(4b6fd085471a9fb1). of_values[0]); |
| 173 | u = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1] -cxx . . $ operator-(4b6fd085471a9fb1). ((steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1] - steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2]) *cxx . . $ `operator*`(ca0d58f853b0940). q -cxx . . $ operator-(4b6fd085471a9fb1). (steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1] - steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0]) *cxx . . $ `operator*`(ca0d58f853b0940). r) /cxx . . $ `operator/`(42306a5d7abcb141). |
| 174 | (2. *cxx . . $ `operator*`(ca0d58f853b0940). Abscxx . . $ `src/Algo/defs.hpp:66:9`!(Maxcxx . . $ `src/Algo/defs.hpp:69:9`!(Abscxx . . $ `src/Algo/defs.hpp:66:9`!(q - r), TINYcxx . . $ `src/Algo/defs.hpp:46:9`!)) /cxx . . $ `operator/`(42306a5d7abcb141). Sgncxx . . $ `src/Algo/defs.hpp:63:9`!(q - r)); |
| 175 | ulim = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1] + GLIMITcxx . . $ `src/Algo/BrentLS.hpp:77:9`! * (steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] - steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1]); |
| 176 | |
| 177 | if ((steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1] -cxx . . $ operator-(4b6fd085471a9fb1). u) *cxx . . $ `operator*`(ca0d58f853b0940). (u -cxx . . $ operator-(4b6fd085471a9fb1). steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2]) >cxx . . $ std/`operator>`(c2ad8cf295ccec45). 0.) { |
| 178 | fu = this->nrj->getVal(update(model0, 1, u, direction)); |
| 179 | this->iterNum++; |
| 180 | if (fu <cxx . . $ std/`operator<`(c2ad8cf295ccec45). of_values[2]) { |
| 181 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0] = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1]; |
| 182 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1] = u; |
| 183 | of_values[0] = of_values[1]; |
| 184 | of_values[1] = fu; |
| 185 | break; |
| 186 | } else if (fu >cxx . . $ std/`operator>`(c2ad8cf295ccec45). of_values[1]) { |
| 187 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] = u; |
| 188 | of_values[2] = fu; |
| 189 | break; |
| 190 | } |
| 191 | |
| 192 | u = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] + GOLDcxx . . $ `src/Algo/BrentLS.hpp:75:9`! * (steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] - steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1]); |
| 193 | fu = this->nrj->getVal(update(model0, 1, u, direction)); |
| 194 | this->iterNum++; |
| 195 | } else if ((steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] -cxx . . $ operator-(4b6fd085471a9fb1). u) *cxx . . $ `operator*`(ca0d58f853b0940). (u -cxx . . $ operator-(4b6fd085471a9fb1). ulim) >cxx . . $ std/`operator>`(c2ad8cf295ccec45). 0.) { |
| 196 | fu = this->nrj->getVal(update(model0, 1, u, direction)); |
| 197 | this->iterNum++; |
| 198 | if (fu <cxx . . $ std/`operator<`(c2ad8cf295ccec45). of_values[2]) { |
| 199 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1] = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2]; |
| 200 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] = u; |
| 201 | u = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] + GOLDcxx . . $ `src/Algo/BrentLS.hpp:75:9`! * (steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] - steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1]); |
| 202 | |
| 203 | of_values[1] = of_values[2]; |
| 204 | of_values[2] = fu; |
| 205 | fu = this->nrj->getVal(update(model0, 1, u, direction)); |
| 206 | this->iterNum++; |
| 207 | } |
| 208 | } else if ((u -cxx . . $ operator-(4b6fd085471a9fb1). ulim) *cxx . . $ `operator*`(ca0d58f853b0940). (ulim *cxx . . $ `operator*`(ca0d58f853b0940). steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2]) >=cxx . . $ std/`operator>=`(c2ad8cf295ccec45). 0.) { |
| 209 | u = ulim; |
| 210 | fu = this->nrj->getVal(update(model0, 1, u, direction)); |
| 211 | this->iterNum++; |
| 212 | } else { |
| 213 | u = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] + GOLDcxx . . $ `src/Algo/BrentLS.hpp:75:9`! * (steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] - steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1]); |
| 214 | fu = this->nrj->getVal(update(model0, 1, u, direction)); |
| 215 | this->iterNum++; |
| 216 | } |
| 217 | |
| 218 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0] = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1]; |
| 219 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1] = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2]; |
| 220 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] = u; |
| 221 | of_values[0] = of_values[1]; |
| 222 | of_values[1] = of_values[2]; |
| 223 | of_values[2] = fu; |
| 224 | } |
| 225 | |
| 226 | // Sorting STEPS in ascending order |
| 227 | for (i = 0; i < 2; i++) { |
| 228 | if (steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0] > steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).i + 1]) { |
| 229 | dum = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0]; |
| 230 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0] = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).i + 1]; |
| 231 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).i + 1] = dum; |
| 232 | |
| 233 | dum = of_values[0]; |
| 234 | of_values[0] = of_values[i + 1]; |
| 235 | of_values[i + 1] = dum; |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | if (steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1] > steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2]) { |
| 240 | dum = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1]; |
| 241 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1] = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2]; |
| 242 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] = dum; |
| 243 | |
| 244 | dum = of_values[1]; |
| 245 | of_values[1] = of_values[2]; |
| 246 | of_values[2] = dum; |
| 247 | } |
| 248 | |
| 249 | // The line minimization will be performed now using as |
| 250 | // bracket the 3 first steps given in vector steps |
| 251 | // The algorithm is due to Brent |
| 252 | |
| 253 | // initializations |
| 254 | x = w = v = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).1]; |
| 255 | fw = fv = fx = of_values[1]; |
| 256 | |
| 257 | for (; this->iterNum <=cxx . . $ std/`operator<=`(c2ad8cf295ccec45). this->iterMax; this->iterNum++) { |
| 258 | double tol1, tol2, xm; |
| 259 | xm = .5 * (steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0] + steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2]); |
| 260 | tol1 = tol *cxx . . $ `operator*`(ca0d58f853b0940). Abscxx . . $ `src/Algo/defs.hpp:66:9`!(x) +cxx . . $ operator+(1f62e43363bf5779). ZEPScxx . . $ `src/Algo/BrentLS.hpp:74:9`!; |
| 261 | tol2 = 2.0 * tol1; |
| 262 | if (Abscxx . . $ `src/Algo/defs.hpp:66:9`!(x - xm) <= (tol2 - .5 * (steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] - steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0]))) { |
| 263 | this->value = fx; |
| 264 | Paramcxx . . $ BrentLineSearch#Param# new_model(update(model0, 1, x, direction)); |
| 265 | |
| 266 | return new_model; |
| 267 | } |
| 268 | // minimum along a line |
| 269 | if (Abscxx . . $ `src/Algo/defs.hpp:66:9`!(e) > tol1) { |
| 270 | r = (x - w) *cxx . . $ `operator*`(ca0d58f853b0940). (fx -cxx . . $ operator-(4b6fd085471a9fb1). fv); |
| 271 | q = (x - v) *cxx . . $ `operator*`(ca0d58f853b0940). (fx -cxx . . $ operator-(4b6fd085471a9fb1). fw); |
| 272 | p = (x - v) *cxx . . $ `operator*`(ca0d58f853b0940). q -cxx . . $ operator-(4b6fd085471a9fb1). (x - w) *cxx . . $ `operator*`(ca0d58f853b0940). r; |
| 273 | q = 2.0 *cxx . . $ `operator*`(ca0d58f853b0940). (q -cxx . . $ operator-(4b6fd085471a9fb1). r); |
| 274 | // Tony |
| 275 | // ??? ERREUR ??? |
| 276 | // dans le numerical recipe, c'est p=-p... |
| 277 | // BIZARRE ! |
| 278 | if (q >cxx . . $ std/`operator>`(c2ad8cf295ccec45). 0.) { |
| 279 | cerrcxx . . $ `src/fflib/throwassert.hpp:33:9`! <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "BIZARRE BrentLS" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ endl(345bf97a19cc83a9).; |
| 280 | p = -cxx . . $ operator-(4b6fd085471a9fb1).q; |
| 281 | } |
| 282 | |
| 283 | q = Abscxx . . $ `src/Algo/defs.hpp:66:9`!(q); |
| 284 | etemp = e; |
| 285 | e = d; |
| 286 | if (Abscxx . . $ `src/Algo/defs.hpp:66:9`!(p) >=cxx . . $ std/`operator>=`(c2ad8cf295ccec45). Abscxx . . $ `src/Algo/defs.hpp:66:9`!(.5 * q * etemp) || p <=cxx . . $ std/`operator<=`(c2ad8cf295ccec45). q *cxx . . $ `operator*`(ca0d58f853b0940). (steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0] - x) || |
| 287 | p >=cxx . . $ std/`operator>=`(c2ad8cf295ccec45). q *cxx . . $ `operator*`(ca0d58f853b0940). (steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] - x)) { // parabolic fit |
| 288 | if (x >= xm) |
| 289 | e = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0] - x; |
| 290 | else |
| 291 | e = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] - x; |
| 292 | d = CGOLDcxx . . $ `src/Algo/BrentLS.hpp:73:9`! * e; |
| 293 | } else { |
| 294 | d = p /cxx . . $ `operator/`(42306a5d7abcb141). q; |
| 295 | u = x +cxx . . $ operator+(1f62e43363bf5779). d; |
| 296 | if (u -cxx . . $ operator-(4b6fd085471a9fb1). steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0] <cxx . . $ std/`operator<`(c2ad8cf295ccec45). tol2 || steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] -cxx . . $ operator-(4b6fd085471a9fb1). u <cxx . . $ std/`operator<`(c2ad8cf295ccec45). tol2) d = Abscxx . . $ `src/Algo/defs.hpp:66:9`!(tol1) / Sgncxx . . $ `src/Algo/defs.hpp:63:9`!(xm - x); |
| 297 | } |
| 298 | } else { |
| 299 | if (x >= xm) |
| 300 | e = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0] - x; |
| 301 | else |
| 302 | e = steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] - x; |
| 303 | |
| 304 | d = CGOLDcxx . . $ `src/Algo/BrentLS.hpp:73:9`! * e; |
| 305 | } |
| 306 | |
| 307 | if (Abscxx . . $ `src/Algo/defs.hpp:66:9`!(d) >=cxx . . $ std/`operator>=`(c2ad8cf295ccec45). tol1) |
| 308 | u = x +cxx . . $ operator+(1f62e43363bf5779). d; |
| 309 | else |
| 310 | u = x +cxx . . $ operator+(1f62e43363bf5779). Abscxx . . $ `src/Algo/defs.hpp:66:9`!(tol1) /cxx . . $ `operator/`(42306a5d7abcb141). Sgncxx . . $ `src/Algo/defs.hpp:63:9`!(d); |
| 311 | |
| 312 | fu = this->nrj->getVal(update(model0, 1, u, direction)); |
| 313 | |
| 314 | if (fu <=cxx . . $ std/`operator<=`(c2ad8cf295ccec45). fx) { |
| 315 | if (u >=cxx . . $ std/`operator>=`(c2ad8cf295ccec45). x) |
| 316 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0] = x; |
| 317 | else |
| 318 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] = x; |
| 319 | v = w; |
| 320 | w = x; |
| 321 | x = u; |
| 322 | fv = fw; |
| 323 | fw = fx; |
| 324 | fx = fu; |
| 325 | } else { |
| 326 | if (u <cxx . . $ std/`operator<`(c2ad8cf295ccec45). x) |
| 327 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).0] = u; |
| 328 | else |
| 329 | steps[cxx . . $ KN_#`operator[]`(106a727bdc027555).2] = u; |
| 330 | |
| 331 | if (fu <=cxx . . $ std/`operator<=`(c2ad8cf295ccec45). fw || w == x) { |
| 332 | v = w; |
| 333 | w = u; |
| 334 | fv = fw; |
| 335 | fw = fu; |
| 336 | } else if (fu <=cxx . . $ std/`operator<=`(c2ad8cf295ccec45). fw || v == x || v == w) { |
| 337 | v = u; |
| 338 | fv = fu; |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | this->appendSearchNumber( ); |
| 344 | // cout << " Maximum number of iterations reached " << endl; |
| 345 | |
| 346 | Paramcxx . . $ BrentLineSearch#Param# new_model(update(model0, 1, x, direction)); |
| 347 | this->value = this->nrj->getVal(new_model); |
| 348 | return new_model; |
| 349 | } |
| 350 | |
| 351 | #endif |