vnl_nonlinear_minimizer.cxx
Go to the documentation of this file.
1 // This is core/vnl/vnl_nonlinear_minimizer.cxx
2 //:
3 // \file
4 // \author Andrew W. Fitzgibbon, Oxford RRG, 22 Aug 99
5 
6 #include <iostream>
7 #include <iomanip>
9 
10 //: Default ctor sets verbosity etc.
12 : xtol(1e-8) // Termination tolerance on X (solution vector)
13 , maxfev(2000) // Termination maximum number of iterations.
14 , ftol(xtol * 0.01) // Termination tolerance on F (sum of squared residuals)
15 , gtol(1e-5) // Termination tolerance on Grad(F)' * F = 0
16 , epsfcn(xtol * 0.001) // Step length for FD Jacobian
17 , num_iterations_(0)
18 , num_evaluations_(0)
19 , start_error_(0)
20 , end_error_(0)
21 , trace(false)
22 , verbose_(false)
23 , check_derivatives_(0)
24 , failure_code_(ERROR_FAILURE)
25 {
26 }
27 
29 
31 {
32  static vnl_matrix<double> null;
33  return null;
34 }
35 
37 {
38  num_iterations_ = 0;
39  num_evaluations_ = 0;
40  start_error_ = 0;
41  end_error_ = 0;
42 }
43 
44 //: Called by derived classes after each function evaluation.
46 {
47  if (num_evaluations_ == 0) {
48  start_error_ = f;
49  end_error_ = f;
50  }
51  if (f < end_error_)
52  end_error_ = f;
53 
55 }
56 
57 //: Called by derived classes after each iteration.
59 {
61  if (verbose_)
62  std::cerr << "Iter " << std::setw(4) << num_iterations_ << ", Eval "
63  << std::setw(4) << num_evaluations_ << ": Best F = "
64  << std::setw(10) << end_error_ << '\n';
65  return false;
66 }
67 
68 //: Return the name of the class
69 // Used by polymorphic IO
70 std::string vnl_nonlinear_minimizer::is_a() const
71 {
72  static const std::string class_name_="vnl_nonlinear_minimizer";
73  return class_name_;
74 }
75 
76 //: Return true if the name of the class matches the argument
77 // Used by polymorphic IO
78 bool vnl_nonlinear_minimizer::is_class(std::string const& s) const
79 {
81 }
virtual std::string is_a() const
Return the name of the class.
vnl_nonlinear_minimizer()
Default ctor sets verbosity etc.
void report_eval(double f)
Called by derived classes after each function evaluation.
virtual bool report_iter()
Called by derived classes after each iteration.
virtual bool is_class(std::string const &s) const
Return true if the name of the class matches the argument.
Base class for nonlinear optimization.
virtual vnl_matrix< double > const & get_covariance()
Return the covariance of the estimate at the end.
virtual ~vnl_nonlinear_minimizer()