LineMinimizer.h 2.12 KB
Newer Older
Francois Gygi committed
1 2
////////////////////////////////////////////////////////////////////////////////
//
3
// Copyright (c) 2011 The Regents of the University of California
Francois Gygi committed
4 5 6
//
// This file is part of Qbox
//
Francois Gygi committed
7 8
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
Francois Gygi committed
9 10 11 12 13 14
// the License, or (at your option) any later version.
// See the file COPYING in the root directory of this distribution
// or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
15 16 17 18 19 20 21 22 23 24 25
// LineMinimizer.h
//
////////////////////////////////////////////////////////////////////////////////

#ifndef LINEMINIMIZER_H
#define LINEMINIMIZER_H

class LineMinimizer
{
  private:

26 27
  double f0,fp0,fm,fpm,f_low,fp_low,f_high,fp_high,
         alpha_m,alpha_low,alpha_high;
28 29 30
  bool first_use, done_, fail_, bracketing, use_psi;
  bool debug_print;
  double alpha_start_, alpha_max_, sigma1_, sigma2_;
31
  int nstep_, nstep_max_;
Francois Gygi committed
32

33 34
  double psi(double alpha, double f) { return f - f0 - alpha * fp0 * sigma1_; }
  double psip(double fp) { return fp - fp0 * sigma1_; }
35
  double interpolate(void);
Francois Gygi committed
36 37 38

  public:

39 40
  LineMinimizer(void) : sigma1_(0.1), sigma2_(0.5), alpha_start_(0.1),
   alpha_max_(1.0), first_use(true), done_(false), fail_(false),
Francois Gygi committed
41
   bracketing(false), use_psi(true), nstep_(0), nstep_max_(5),
42
   debug_print(false) {}
43 44
  void reset(void) { first_use = true; done_ = false; fail_ = false;
    bracketing = false; nstep_ = 0; }
Francois Gygi committed
45
  double sigma1(void) const { return sigma1_; }
46 47
  double sigma2(void) const { return sigma2_; }
  double alpha_start(void) const { return alpha_start_; }
48
  double alpha_max(void) const { return alpha_max_; }
49 50 51 52 53 54
  bool done(void) const { return done_; }
  bool fail(void) const { return fail_; }

  void set_sigma1(double s) { sigma1_ = s; }
  void set_sigma2(double s) { sigma2_ = s; }
  void set_alpha_start(double a) { alpha_start_ = a; }
55
  void set_alpha_max(double a) { alpha_max_ = a; }
56
  void set_nstep_max(int n) { nstep_max_ = n; }
57
  void set_debug_print(void) { debug_print = true; }
Francois Gygi committed
58

59
  double next_alpha(double alpha, double f, double fp);
Francois Gygi committed
60 61
};
#endif