Chemical Data Processing Library C++ API - Version 1.1.1
BFGSMinimizer.hpp
Go to the documentation of this file.
1 /*
2  * BFGSMinimizer.hpp
3  *
4  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
27 #ifndef CDPL_MATH_BFGSMINIMIZER_HPP
28 #define CDPL_MATH_BFGSMINIMIZER_HPP
29 
30 #include <cstddef>
31 #include <limits>
32 #include <functional>
33 
35 #include "CDPL/Math/TypeTraits.hpp"
36 
37 
38 namespace CDPL
39 {
40 
41  namespace Math
42  {
43 
52  template <typename VA, typename VT = typename MinimizerVariableArrayTraits<VA>::ValueType, typename FVT = VT>
54  {
55 
56  public:
57  typedef VA VariableArrayType;
58  typedef VT ValueType;
59  typedef FVT FunctionValueType;
60 
61  typedef typename std::function<FVT(const VA&, VA&)> GradientFunction;
62  typedef typename std::function<FVT(const VA&)> ObjectiveFunction;
63 
64  enum Status
65  {
66 
67  SUCCESS = 0, // general success indicator
68  NO_PROGRESS = 1, // no more progress towards solution
69  ITER_LIMIT_REACHED = 2, // the maximum number of minimization iterations has been reached
70  GNORM_REACHED = 4, // the specified gradient norm has been reached
71  DELTAF_REACHED = 8 // the specified function value delta between successive iterations has been reached
72  };
73 
74  BFGSMinimizer(const ObjectiveFunction& func, const GradientFunction& grad_func):
75  rho(0.01), tau1(9), tau2(0.05), tau3(0.5), order(3), sigma(0.1), func(func), gradFunc(grad_func), status(SUCCESS) {}
76 
78  {
79  return g0Norm;
80  }
81 
83  {
84  return -deltaF;
85  }
86 
88  {
89  return fValue;
90  }
91 
92  std::size_t getNumIterations() const
93  {
94  return numIter;
95  }
96 
97  Status getStatus() const
98  {
99  return status;
100  }
101 
102  Status minimize(VariableArrayType& x, VariableArrayType& g, std::size_t max_iter,
103  const ValueType& g_norm, const ValueType& delta_f, bool do_setup = true)
104  {
105  if (do_setup)
106  setup(x, g);
107 
108  fValue = ValueType(0);
109 
110  for (std::size_t i = 0; max_iter == 0 || i < max_iter; i++) {
111  status = iterate(fValue, x, g);
112 
113  if (status != SUCCESS)
114  return status;
115 
116  if (g_norm >= ValueType(0) && g0Norm <= g_norm)
117  status = GNORM_REACHED;
118 
119  if (delta_f >= ValueType(0) && deltaF <= delta_f)
120  status = Status(status | DELTAF_REACHED);
121 
122  if (status != SUCCESS)
123  return status;
124  }
125 
126  return (status = ITER_LIMIT_REACHED);
127  }
128 
130  const ValueType& step_size = 0.001, const ValueType& tol = 0.15)
131  {
132  numIter = 0;
133  step = step_size;
134  deltaF = ValueType(0);
135 
136  startF = gradFunc(x, g);
137 
138  /* Use the gradient as the initial direction */
139 
140  assign(x0, x);
141  assign(g0, g);
142  g0Norm = norm2(g0);
143 
144  assign(p, g);
145  multiply(p, -1 / g0Norm);
146 
147  pNorm = norm2(p); /* should be 1 */
148  fp0 = -g0Norm;
149 
150  /* Prepare the function evaluation cache */
151 
152  initFuncEvalCache();
153 
154  /* Prepare 1d minimisation parameters */
155 
156  sigma = tol;
157 
158  return startF;
159  }
160 
162  {
163  if (numIter == 0)
164  f = startF;
165 
166  ValueType alpha = ValueType(0), alpha1;
167  ValueType f0 = f;
168 
169  if (pNorm == ValueType(0) || g0Norm == ValueType(0) || fp0 == ValueType(0)) {
170  clear(dx);
171  return NO_PROGRESS;
172  }
173 
174  if (deltaF < ValueType(0)) {
175  ValueType del = std::max(-deltaF, 10 * std::numeric_limits<ValueType>::epsilon() * TypeTraits<ValueType>::abs(f0));
176  alpha1 = std::min(ValueType(1), 2 * del / -fp0);
177 
178  } else
179  alpha1 = TypeTraits<ValueType>::abs(step);
180 
181  /* line minimisation, with cubic interpolation (order = 3) */
182 
183  Status status = minimize(alpha1, alpha);
184 
185  if (status != SUCCESS)
186  return status;
187 
188  updatePosition(alpha, x, f, g);
189 
190  deltaF = f - f0;
191 
192  /* Choose a new direction for the next step */
193 
194  /* This is the BFGS update: */
195  /* p' = g1 - A dx - B dg */
196  /* A = - (1 + dg.dg / dx.dg) B + dg.g / dx.dg */
197  /* B = dx.g / dx.dg */
198 
199  /* dx0 = x - x0 */
200 
201  assign(dx0, x);
202  sub(dx0, x0);
203  assign(dx, dx0); /* keep a copy */
204 
205  /* dg0 = g - g0 */
206 
207  assign(dg0, g);
208  sub(dg0, g0);
209 
210  ValueType dxg = dot(dx0, g);
211  ValueType dgg = dot(dg0, g);
212  ValueType dxdg = dot(dx0, dg0);
213  ValueType dgnorm = norm2(dg0);
214 
215  ValueType A = ValueType(0);
216  ValueType B = ValueType(0);
217 
218  if (dxdg != 0) {
219  B = dxg / dxdg;
220  A = -(1 + dgnorm * dgnorm / dxdg) * B + dgg / dxdg;
221  }
222 
223  assign(p, g);
224 
225  axpy(-A, dx0, p);
226  axpy(-B, dg0, p);
227 
228  assign(g0, g);
229  assign(x0, x);
230  g0Norm = norm2(g0);
231  pNorm = norm2(p);
232 
233  /* update direction and fp0 */
234 
235  ValueType pg = dot(p, g);
236  ValueType dir(pg >= ValueType(0) ? -1 : +1);
237 
238  multiply(p, dir / pNorm);
239 
240  pNorm = norm2(p);
241 
242  fp0 = dot(p, g0);
243 
244  changeDirection();
245 
246  numIter++;
247 
248  return SUCCESS;
249  }
250 
251  private:
252  BFGSMinimizer();
253 
254  BFGSMinimizer& operator=(const BFGSMinimizer&);
255 
256  void initFuncEvalCache()
257  {
258  assign(xAlpha, x0);
259  assign(gAlpha, g0);
260 
261  xCacheKey = ValueType(0);
262  fAlpha = startF;
263  fCacheKey = ValueType(0);
264  gCacheKey = ValueType(0);
265  dfAlpha = slope();
266  dfCacheKey = ValueType(0);
267  }
268 
269  void assign(VariableArrayType& v1, const VariableArrayType& v2)
270  {
272  }
273 
274  void clear(VariableArrayType& v)
275  {
277  }
278 
279  void multiply(VariableArrayType& v, const ValueType& f)
280  {
282  }
283 
284  void sub(VariableArrayType& v1, const VariableArrayType& v2)
285  {
287  }
288 
289  ValueType norm2(const VariableArrayType& v) const
290  {
291  return MinimizerVariableArrayTraits<VA>::template norm2<ValueType>(v);
292  }
293 
294  ValueType dot(const VariableArrayType& v1, const VariableArrayType& v2) const
295  {
296  return MinimizerVariableArrayTraits<VA>::template dot<ValueType>(v1, v2);
297  }
298 
299  void axpy(const ValueType& alpha, const VariableArrayType& x, VariableArrayType& y) const
300  {
302  }
303 
304  ValueType slope() const
305  { /* compute gradient . direction */
306  return dot(gAlpha, p);
307  }
308 
309  void moveTo(const ValueType& alpha)
310  {
311  if (alpha == xCacheKey) /* using previously cached position */
312  return;
313 
314  /* set xAlpha = x + alpha * p */
315 
316  assign(xAlpha, x0);
317 
318  axpy(alpha, p, xAlpha);
319 
320  xCacheKey = alpha;
321  }
322 
323  ValueType getF(const ValueType& alpha)
324  {
325  if (alpha == fCacheKey) /* using previously cached f(alpha) */
326  return fAlpha;
327 
328  moveTo(alpha);
329 
330  fAlpha = func(xAlpha);
331  fCacheKey = alpha;
332 
333  return fAlpha;
334  }
335 
336  ValueType getDF(const ValueType& alpha)
337  {
338  if (alpha == dfCacheKey) /* using previously cached df(alpha) */
339  return dfAlpha;
340 
341  moveTo(alpha);
342 
343  if (alpha != gCacheKey) {
344  fAlpha = gradFunc(xAlpha, gAlpha);
345  gCacheKey = alpha;
346  fCacheKey = alpha;
347  }
348 
349  dfAlpha = slope();
350  dfCacheKey = alpha;
351 
352  return dfAlpha;
353  }
354 
355  void getFDF(const ValueType& alpha, ValueType& f, ValueType& df)
356  {
357  /* Check for previously cached values */
358 
359  if (alpha == fCacheKey && alpha == dfCacheKey) {
360  f = fAlpha;
361  df = dfAlpha;
362  return;
363  }
364 
365  if (alpha == fCacheKey || alpha == dfCacheKey) {
366  df = getDF(alpha);
367  f = getF(alpha);
368  return;
369  }
370 
371  moveTo(alpha);
372 
373  fAlpha = gradFunc(xAlpha, gAlpha);
374  fCacheKey = alpha;
375  gCacheKey = alpha;
376 
377  dfAlpha = slope();
378  dfCacheKey = alpha;
379 
380  f = fAlpha;
381  df = dfAlpha;
382  }
383 
384  void updatePosition(const ValueType& alpha, VariableArrayType& x, ValueType& f, VariableArrayType& g)
385  {
386  ValueType f_alpha, df_alpha;
387 
388  /* ensure that everything is fully cached */
389 
390  getFDF(alpha, f_alpha, df_alpha);
391 
392  f = f_alpha;
393  assign(x, xAlpha);
394  assign(g, gAlpha);
395  }
396 
397  void changeDirection()
398  {
399  /* Convert the cache values from the end of the current minimisation
400  to those needed for the start of the next minimisation, alpha = 0 */
401 
402  /* The new xAlpha for alpha = 0 is the current position */
403 
404  assign(xAlpha, x0);
405  xCacheKey = ValueType(0);
406 
407  /* The function value does not change */
408 
409  fCacheKey = ValueType(0);
410 
411  /* The new gAlpha for alpha = 0 is the current gradient at the endpoint */
412 
413  assign(gAlpha, g0);
414  gCacheKey = ValueType(0);
415 
416  /* Calculate the slope along the new direction vector, p */
417 
418  dfAlpha = slope();
419  dfCacheKey = ValueType(0);
420  }
421 
422  std::size_t solveQuadratic(const ValueType& a, const ValueType& b, const ValueType& c,
423  ValueType& x0, ValueType& x1) const
424  {
425 
426  ValueType disc = b * b - 4 * a * c;
427 
428  if (a == ValueType(0)) { /* Handle linear case */
429  if (b == ValueType(0))
430  return 0;
431 
432  else {
433  x0 = -c / b;
434  return 1;
435  };
436  }
437 
438  if (disc > ValueType(0)) {
439  if (b == ValueType(0)) {
440  ValueType r = TypeTraits<ValueType>::abs(TypeTraits<ValueType>::sqrt(disc) / (a * 2));
441  x0 = -r;
442  x1 = r;
443 
444  } else {
445  ValueType sgnb(b > ValueType(0) ? 1 : -1);
446  ValueType temp = -(b + sgnb * TypeTraits<ValueType>::sqrt(disc)) / 2;
447  ValueType r1 = temp / a;
448  ValueType r2 = c / temp;
449 
450  if (r1 < r2) {
451  x0 = r1;
452  x1 = r2;
453 
454  } else {
455  x0 = r2;
456  x1 = r1;
457  }
458  }
459 
460  return 2;
461 
462  } else if (disc == ValueType(0)) {
463  x0 = -b / (2 * a);
464  x1 = -b / (2 * a);
465  return 2;
466 
467  } else
468  return 0;
469  }
470 
471  /*
472  * Find a minimum in x = [0, 1] of the interpolating quadratic through
473  * (0, f0) (1, f1) with derivative fp0 at x = 0. The interpolating
474  * polynomial is q(x) = f0 + fp0 * z + (f1 - f0 - fp0) * z^2
475  */
476  ValueType interpolateQuadratic(const ValueType& f0, const ValueType& fp0, const ValueType& f1,
477  const ValueType& zl, const ValueType& zh) const
478  {
479 
480  ValueType fl = f0 + zl * (fp0 + zl * (f1 - f0 - fp0));
481  ValueType fh = f0 + zh * (fp0 + zh * (f1 - f0 - fp0));
482  ValueType c = 2 * (f1 - f0 - fp0); /* curvature */
483 
484  ValueType zmin = zl, fmin = fl;
485 
486  if (fh < fmin) {
487  zmin = zh;
488  fmin = fh;
489  }
490 
491  if (c > ValueType(0)) { /* positive curvature required for a minimum */
492  ValueType z = -fp0 / c; /* location of minimum */
493 
494  if (z > zl && z < zh) {
495  ValueType f = f0 + z * (fp0 + z * (f1 - f0 - fp0));
496 
497  if (f < fmin) {
498  zmin = z;
499  fmin = f;
500  }
501  }
502  }
503 
504  return zmin;
505  }
506 
507  /*
508  * Find a minimum in x = [0, 1] of the interpolating cubic through
509  * (0, f0) (1, f1) with derivatives fp0 at x = 0 and fp1 at x = 1.
510  *
511  * The interpolating polynomial is:
512  *
513  * c(x) = f0 + fp0 * z + eta * z^2 + xi * z^3
514  *
515  * where eta = 3 * (f1 - f0) - 2 * fp0 - fp1, xi = fp0 + fp1 - 2 * (f1 - f0).
516  */
517  ValueType cubic(const ValueType& c0, const ValueType& c1, const ValueType& c2,
518  const ValueType& c3, const ValueType& z) const
519  {
520 
521  return c0 + z * (c1 + z * (c2 + z * c3));
522  }
523 
524  void checkExtremum(const ValueType& c0, const ValueType& c1, const ValueType& c2,
525  const ValueType& c3, const ValueType& z, ValueType& zmin, ValueType& fmin) const
526  {
527  /* could make an early return by testing curvature > 0 for minimum */
528 
529  ValueType y = cubic(c0, c1, c2, c3, z);
530 
531  if (y < fmin) {
532  zmin = z; /* accepted new point*/
533  fmin = y;
534  }
535  }
536 
537  ValueType interpolateCubic(const ValueType& f0, const ValueType& fp0, const ValueType& f1,
538  const ValueType& fp1, const ValueType& zl, const ValueType& zh) const
539  {
540 
541  ValueType eta = 3 * (f1 - f0) - 2 * fp0 - fp1;
542  ValueType xi = fp0 + fp1 - 2 * (f1 - f0);
543  ValueType c0 = f0, c1 = fp0, c2 = eta, c3 = xi;
544 
545  ValueType zmin = zl;
546  ValueType fmin = cubic(c0, c1, c2, c3, zl);
547 
548  checkExtremum(c0, c1, c2, c3, zh, zmin, fmin);
549 
550  ValueType z0, z1;
551  std::size_t n = solveQuadratic(3 * c3, 2 * c2, c1, z0, z1);
552 
553  if (n == 2) { /* found 2 roots */
554  if (z0 > zl && z0 < zh)
555  checkExtremum(c0, c1, c2, c3, z0, zmin, fmin);
556 
557  if (z1 > zl && z1 < zh)
558  checkExtremum(c0, c1, c2, c3, z1, zmin, fmin);
559 
560  } else if (n == 1) { /* found 1 root */
561  if (z0 > zl && z0 < zh)
562  checkExtremum(c0, c1, c2, c3, z0, zmin, fmin);
563  }
564 
565  return zmin;
566  }
567 
568  ValueType interpolate(const ValueType& a, const ValueType& fa, const ValueType& fpa,
569  const ValueType& b, const ValueType& fb, const ValueType& fpb,
570  const ValueType& xmin, const ValueType& xmax) const
571  {
572  /* Map [a, b] to [0, 1] */
573 
574  ValueType zmin = (xmin - a) / (b - a);
575  ValueType zmax = (xmax - a) / (b - a);
576 
577  if (zmin > zmax) {
578  ValueType tmp(zmin);
579  zmin = zmax;
580  zmax = tmp;
581  }
582 
583  ValueType z;
584 
585  if (order > 2 && std::isfinite(fpb))
586  z = interpolateCubic(fa, fpa * (b - a), fb, fpb * (b - a), zmin, zmax);
587  else
588  z = interpolateQuadratic(fa, fpa * (b - a), fb, zmin, zmax);
589 
590  ValueType alpha = a + z * (b - a);
591 
592  return alpha;
593  }
594 
595  Status minimize(const ValueType& alpha1, ValueType& alpha_new)
596  {
597  ValueType falpha, fpalpha, delta, alpha_next;
598  ValueType alpha = alpha1, alpha_prev = ValueType(0);
599  ValueType a = ValueType(0), fb = ValueType(0), fpb = ValueType(0);
600 
601  ValueType f0, fp0;
602 
603  getFDF(ValueType(0), f0, fp0);
604 
605  ValueType falpha_prev = f0;
606  ValueType fpalpha_prev = fp0;
607 
608  ValueType b = alpha;
609  ValueType fa = f0;
610  ValueType fpa = fp0;
611 
612  /* Begin bracketing */
613 
614  const std::size_t num_brack_iter = 100, section_iters = 100;
615  std::size_t i = 0;
616 
617  while (i++ < num_brack_iter) {
618  falpha = getF(alpha);
619 
620  /* Fletcher's rho test */
621 
622  if (falpha > f0 + alpha * rho * fp0 || falpha >= falpha_prev) {
623  a = alpha_prev;
624  fa = falpha_prev;
625  fpa = fpalpha_prev;
626  b = alpha;
627  fb = falpha;
628  fpb = std::numeric_limits<ValueType>::quiet_NaN();
629  break; /* goto sectioning */
630  }
631 
632  fpalpha = getDF(alpha);
633 
634  /* Fletcher's sigma test */
635 
636  if (TypeTraits<ValueType>::abs(fpalpha) <= -sigma * fp0) {
637  alpha_new = alpha;
638  return SUCCESS;
639  }
640 
641  if (fpalpha >= ValueType(0)) {
642  a = alpha;
643  fa = falpha;
644  fpa = fpalpha;
645  b = alpha_prev;
646  fb = falpha_prev;
647  fpb = fpalpha_prev;
648  break; /* goto sectioning */
649  }
650 
651  delta = alpha - alpha_prev;
652 
653  ValueType lower = alpha + delta;
654  ValueType upper = alpha + tau1 * delta;
655 
656  alpha_next = interpolate(alpha_prev, falpha_prev, fpalpha_prev,
657  alpha, falpha, fpalpha, lower, upper);
658 
659  alpha_prev = alpha;
660  falpha_prev = falpha;
661  fpalpha_prev = fpalpha;
662  alpha = alpha_next;
663  }
664 
665  /* Sectioning of bracket [a, b] */
666 
667  while (i++ < section_iters) {
668  delta = b - a;
669 
670  ValueType lower = a + tau2 * delta;
671  ValueType upper = b - tau3 * delta;
672 
673  alpha = interpolate(a, fa, fpa, b, fb, fpb, lower, upper);
674  falpha = getF(alpha);
675 
676  if ((a - alpha) * fpa <= std::numeric_limits<ValueType>::epsilon()) {
677  /* roundoff prevents progress */
678  return NO_PROGRESS;
679  }
680 
681  if (falpha > f0 + rho * alpha * fp0 || falpha >= fa) {
682  /* a_next = a; */
683  b = alpha;
684  fb = falpha;
685  fpb = std::numeric_limits<ValueType>::quiet_NaN();
686 
687  } else {
688  fpalpha = getDF(alpha);
689 
690  if (TypeTraits<ValueType>::abs(fpalpha) <= -sigma * fp0) {
691  alpha_new = alpha;
692  return SUCCESS; /* terminate */
693  }
694 
695  if (((b - a) >= ValueType(0) && fpalpha >= ValueType(0)) || ((b - a) <= ValueType(0) && fpalpha <= ValueType(0))) {
696  b = a;
697  fb = fa;
698  fpb = fpa;
699  a = alpha;
700  fa = falpha;
701  fpa = fpalpha;
702 
703  } else {
704  a = alpha;
705  fa = falpha;
706  fpa = fpalpha;
707  }
708  }
709  }
710 
711  return SUCCESS;
712  }
713 
714  const ValueType rho;
715  const ValueType tau1;
716  const ValueType tau2;
717  const ValueType tau3;
718  const std::size_t order;
719  std::size_t numIter;
720  ValueType step;
721  ValueType g0Norm;
722  ValueType pNorm;
723  ValueType startF;
724  ValueType deltaF;
725  ValueType fValue;
726  ValueType fp0;
731  VariableArrayType dx0;
732  VariableArrayType dg0;
733  VariableArrayType xAlpha;
734  VariableArrayType gAlpha;
735  ValueType sigma;
736  ValueType fAlpha;
737  ValueType dfAlpha;
738  ValueType fCacheKey;
739  ValueType dfCacheKey;
740  ValueType xCacheKey;
741  ValueType gCacheKey;
742  ObjectiveFunction func;
743  GradientFunction gradFunc;
744  Status status;
745  };
746  } // namespace Math
747 } // namespace CDPL
748 
749 #endif // CDPL_MATH_BFGSMINIMIZER_HPP
CDPL::Math::MinimizerVariableArrayTraits::sub
static void sub(ArrayType &a1, const ArrayType &a2)
Definition: MinimizerVariableArrayTraits.hpp:112
CDPL::Math::TypeTraits
Definition: TypeTraits.hpp:171
CDPL::Math::BFGSMinimizer::getFunctionDelta
ValueType getFunctionDelta() const
Definition: BFGSMinimizer.hpp:82
CDPL::Chem::AtomType::B
const unsigned int B
Specifies Boron.
Definition: AtomType.hpp:87
CDPL::Math::BFGSMinimizer::ValueType
VT ValueType
Definition: BFGSMinimizer.hpp:58
CDPL::Math::MinimizerVariableArrayTraits::assign
static void assign(ArrayType &a1, const ArrayType &a2)
Definition: MinimizerVariableArrayTraits.hpp:101
CDPL::Math::BFGSMinimizer::VariableArrayType
VA VariableArrayType
Definition: BFGSMinimizer.hpp:57
CDPL::Math::MinimizerVariableArrayTraits::axpy
static void axpy(const T &alpha, const ArrayType &x, ArrayType &y)
Definition: MinimizerVariableArrayTraits.hpp:91
CDPL::Math::BFGSMinimizer::DELTAF_REACHED
@ DELTAF_REACHED
Definition: BFGSMinimizer.hpp:71
CDPL::Math::BFGSMinimizer::GradientFunction
std::function< FVT(const VA &, VA &)> GradientFunction
Definition: BFGSMinimizer.hpp:61
CDPL::Math::BFGSMinimizer::ObjectiveFunction
std::function< FVT(const VA &)> ObjectiveFunction
Definition: BFGSMinimizer.hpp:62
CDPL::Math::BFGSMinimizer::GNORM_REACHED
@ GNORM_REACHED
Definition: BFGSMinimizer.hpp:70
CDPL::Math::BFGSMinimizer::iterate
Status iterate(ValueType &f, VariableArrayType &x, VariableArrayType &g)
Definition: BFGSMinimizer.hpp:161
CDPL::Math::BFGSMinimizer< QuaternionTransformation >::Status
Status
Definition: BFGSMinimizer.hpp:65
TypeTraits.hpp
Definition of type traits.
MinimizerVariableArrayTraits.hpp
Provides traits to flexibly handle different types of variable arrays in function optimization algori...
CDPL::Math::BFGSMinimizer::BFGSMinimizer
BFGSMinimizer(const ObjectiveFunction &func, const GradientFunction &grad_func)
Definition: BFGSMinimizer.hpp:74
CDPL::Math::BFGSMinimizer
Fletcher's implementation of the BFGS method.
Definition: BFGSMinimizer.hpp:54
CDPL::Math::BFGSMinimizer::getStatus
Status getStatus() const
Definition: BFGSMinimizer.hpp:97
CDPL::Math::BFGSMinimizer::SUCCESS
@ SUCCESS
Definition: BFGSMinimizer.hpp:67
CDPL::Math::BFGSMinimizer::FunctionValueType
FVT FunctionValueType
Definition: BFGSMinimizer.hpp:59
CDPL::Chem::CIPDescriptor::r
const unsigned int r
Specifies that the stereocenter has r configuration.
Definition: CIPDescriptor.hpp:76
CDPL::Math::BFGSMinimizer::getFunctionValue
ValueType getFunctionValue() const
Definition: BFGSMinimizer.hpp:87
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Math::MinimizerVariableArrayTraits::clear
static void clear(ArrayType &a)
Definition: MinimizerVariableArrayTraits.hpp:96
CDPL::Math::BFGSMinimizer::minimize
Status minimize(VariableArrayType &x, VariableArrayType &g, std::size_t max_iter, const ValueType &g_norm, const ValueType &delta_f, bool do_setup=true)
Definition: BFGSMinimizer.hpp:102
CDPL::Math::BFGSMinimizer::setup
ValueType setup(const VariableArrayType &x, VariableArrayType &g, const ValueType &step_size=0.001, const ValueType &tol=0.15)
Definition: BFGSMinimizer.hpp:129
CDPL::Math::BFGSMinimizer::getGradientNorm
ValueType getGradientNorm() const
Definition: BFGSMinimizer.hpp:77
CDPL::Math::MinimizerVariableArrayTraits::multiply
static void multiply(ArrayType &a, const T &v)
Definition: MinimizerVariableArrayTraits.hpp:107
CDPL::Math::BFGSMinimizer::ITER_LIMIT_REACHED
@ ITER_LIMIT_REACHED
Definition: BFGSMinimizer.hpp:69
CDPL::Math::BFGSMinimizer::getNumIterations
std::size_t getNumIterations() const
Definition: BFGSMinimizer.hpp:92
CDPL::Math::BFGSMinimizer::NO_PROGRESS
@ NO_PROGRESS
Definition: BFGSMinimizer.hpp:68
CDPL::Chem::AtomType::A
const unsigned int A
A generic type that covers any element except hydrogen.
Definition: AtomType.hpp:617