vnl_lbfgsb.h
Go to the documentation of this file.
1 // This is core/vnl/algo/vnl_lbfgsb.h
2 #ifndef vnl_lbfgsb_h_
3 #define vnl_lbfgsb_h_
4 //:
5 // \file
6 // \brief Limited memory Broyden Fletcher Goldfarb Shannon constrained opt
7 // \author Brad King, Kitware Inc.
8 // \date 28 Aug 07
9 //
10 // \verbatim
11 // Modifications
12 // 070828 BJK Initial version.
13 // \endverbatim
14 //
15 
16 #include <vnl/vnl_cost_function.h>
18 #include <vnl/vnl_vector.h>
19 #include <vnl/algo/vnl_algo_export.h>
20 
21 //: Limited memory Broyden Fletcher Goldfarb Shannon minimization with constraints.
22 // Lower and upper bounds may be specified for the variables to be optimized.
23 // The algorithm minimizes a nonlinear function f(x) of n variables
24 // subject to simple bound constraints of l <= x <= u.
25 
26 class VNL_ALGO_EXPORT vnl_lbfgsb : public vnl_nonlinear_minimizer
27 {
28  public:
30 
31  //: Find a minimum in the feasible region given an initial guess.
32  // Returns true if a minimum is found and false for failure.
33  bool minimize(vnl_vector<double>& x);
34 
35  //: Set the bounds to be enforced on each variable.
36  // The argument should have one entry per unknown.
37  // Each entry may have one of these values:
38  // 0 - variable is not constrained
39  // 1 - variable has only a lower bound
40  // 2 - variable has both lower and upper bounds
41  // 3 - variable has only an upper bound
43  { this->bound_selection_ = nbd; }
44 
45  //: Get the bounds currently enforced on each variable.
47  { nbd = this->bound_selection_; }
48 
49  //: Set the lower bounds for all variables.
50  // The argument should have one entry per unknown.
51  // The lower bound is used only if the corresponding entry
52  // in the bound selection vector is set to 1 or 2.
54  { this->lower_bound_ = l; }
55 
56  //: Get the lower bounds for all variables.
58  { l = this->lower_bound_; }
59 
60  //: Set the upper bounds for all variables.
61  // The argument should have one entry per unknown.
62  // The upper bound is used only if the corresponding entry
63  // in the bound selection vector is set to 2 or 3.
65  { this->upper_bound_ = u; }
66 
67  //: Get the upper bounds for all variables.
69  { u = this->upper_bound_; }
70 
71  //: Set the maximum number of variable metric corrections.
72  // This is used to determine the size of the limited-memory matrix.
73  // The default value is 5.
75  { this->max_corrections_ = m; }
76 
77  //: Get the maximum number of variable metric corrections.
79  { return this->max_corrections_; }
80 
81  //: Set the cost function convergence factor.
82  // When an iteration changes the function value by an amount smaller than
83  // this factor times the machine epsilon (scaled by function magnitude)
84  // convergence is assumed. The default value is 1e+7.
86  { this->convergence_factor_ = factor; }
87 
88  //: Get the cost function convergence factor.
90  { return this->convergence_factor_; }
91 
92  //: Set the projected gradient tolerance.
93  // When the projected gradient vector has no component larger than
94  // the given value convergence is assumed. The default value is
95  // 1e-5.
97  { this->projected_gradient_tolerance_ = tol; }
98 
99  //: Get the projected gradient tolerance.
101  { return this->projected_gradient_tolerance_; }
102 
103  //: Get the current infinity norm of the projected gradient.
105  { return this->inf_norm_projected_gradient_; }
106 
107  protected:
108 
116 
117  private:
118  vnl_lbfgsb() = delete; // Not implemented
119  void init_parameters();
121 };
122 
123 #endif // vnl_lbfgsb_h_
An object that represents a function from R^n -> R.
void set_max_variable_metric_corrections(long m)
Set the maximum number of variable metric corrections.
Definition: vnl_lbfgsb.h:74
vnl_cost_function * f_
Definition: vnl_lbfgsb.h:120
void get_upper_bound(vnl_vector< double > &u) const
Get the upper bounds for all variables.
Definition: vnl_lbfgsb.h:68
long max_corrections_
Definition: vnl_lbfgsb.h:112
Vector->Real function.
void set_cost_function_convergence_factor(double factor)
Set the cost function convergence factor.
Definition: vnl_lbfgsb.h:85
#define m
Definition: vnl_vector.h:43
void set_lower_bound(vnl_vector< double > const &l)
Set the lower bounds for all variables.
Definition: vnl_lbfgsb.h:53
void set_upper_bound(vnl_vector< double > const &u)
Set the upper bounds for all variables.
Definition: vnl_lbfgsb.h:64
vnl_nonlinear_minimizer is a base class for nonlinear optimization.
Limited memory Broyden Fletcher Goldfarb Shannon minimization with constraints.
Definition: vnl_lbfgsb.h:26
double projected_gradient_tolerance_
Definition: vnl_lbfgsb.h:114
double get_inf_norm_projected_gradient() const
Get the current infinity norm of the projected gradient.
Definition: vnl_lbfgsb.h:104
vnl_vector< double > lower_bound_
Definition: vnl_lbfgsb.h:109
Base class for nonlinear optimization.
double inf_norm_projected_gradient_
Definition: vnl_lbfgsb.h:115
double convergence_factor_
Definition: vnl_lbfgsb.h:113
void get_lower_bound(vnl_vector< double > &l) const
Get the lower bounds for all variables.
Definition: vnl_lbfgsb.h:57
vnl_vector< long > bound_selection_
Definition: vnl_lbfgsb.h:111
void set_projected_gradient_tolerance(double tol)
Set the projected gradient tolerance.
Definition: vnl_lbfgsb.h:96
void get_bound_selection(vnl_vector< long > &nbd) const
Get the bounds currently enforced on each variable.
Definition: vnl_lbfgsb.h:46
long get_max_variable_metric_corrections() const
Get the maximum number of variable metric corrections.
Definition: vnl_lbfgsb.h:78
double get_cost_function_convergence_factor() const
Get the cost function convergence factor.
Definition: vnl_lbfgsb.h:89
vnl_vector< double > upper_bound_
Definition: vnl_lbfgsb.h:110
void set_bound_selection(vnl_vector< long > const &nbd)
Set the bounds to be enforced on each variable.
Definition: vnl_lbfgsb.h:42
double get_projected_gradient_tolerance() const
Get the projected gradient tolerance.
Definition: vnl_lbfgsb.h:100