CGOptimizer.h 2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2011 The Regents of the University of California
//
// This file is part of Qbox
//
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
// 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/>.
//
////////////////////////////////////////////////////////////////////////////////
//
// CGOptimizer.h:
//
////////////////////////////////////////////////////////////////////////////////

#ifndef CGOPTIMIZER_H
#define CGOPTIMIZER_H

#include "LineMinimizer.h"
#include <valarray>

class CGOptimizer
{
  private:

  int n_;
  bool first_step_, debug_print;
31
  std::valarray<double> x0_, p_, gm_;
32 33
  double f0_, fp0_, g0norm2_, alpha_, beta_max_;
  LineMinimizer linmin_;
34
  double norm2(std::valarray<double>& v);
35 36 37 38 39

  public:

  CGOptimizer(int n): n_(n), first_step_(true), alpha_(0.0), beta_max_(0.0),
    debug_print(false)
40 41
  {
    x0_.resize(n);
42
    p_.resize(n);
43
    gm_.resize(n);
44 45 46 47 48 49
  }

  void reset(void) { first_step_ = true; }
  void set_sigma1(double s) { linmin_.set_sigma1(s); }
  void set_sigma2(double s) { linmin_.set_sigma2(s); }
  void set_alpha_start(double a ) { linmin_.set_alpha_start(a); }
50
  void set_alpha_max(double a ) { linmin_.set_alpha_max(a); }
51
  void set_beta_max(double b ) { beta_max_ = b; }
52
  void set_debug_print(void) { debug_print = true; linmin_.set_debug_print(); }
53 54 55 56 57 58 59

  int size(void) const { return n_; }
  double sigma1(void) const { return linmin_.sigma1(); }
  double sigma2(void) const { return linmin_.sigma2(); }
  double alpha(void) const { return alpha_; }
  double alpha_start(void) const { return linmin_.alpha_start(); }
  double beta_max(void) const { return beta_max_; }
60
  void compute_xp(const std::valarray<double>& x, const double f,
61
                  std::valarray<double>& g, std::valarray<double>& xp);
62 63
};
#endif