core/vnl/vnl_nonlinear_minimizer.cxx
Go to the documentation of this file.
00001 // This is core/vnl/vnl_nonlinear_minimizer.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \author Andrew W. Fitzgibbon, Oxford RRG, 22 Aug 99
00008 
00009 #include "vnl_nonlinear_minimizer.h"
00010 #include <vcl_iostream.h>
00011 #include <vcl_iomanip.h>
00012 
00013 //: Default ctor sets verbosity etc.
00014 vnl_nonlinear_minimizer::vnl_nonlinear_minimizer()
00015 : xtol(1e-8)           // Termination tolerance on X (solution vector)
00016 , maxfev(2000)         // Termination maximum number of iterations.
00017 , ftol(xtol * 0.01)    // Termination tolerance on F (sum of squared residuals)
00018 , gtol(1e-5)           // Termination tolerance on Grad(F)' * F = 0
00019 , epsfcn(xtol * 0.001) // Step length for FD Jacobian
00020 , num_iterations_(0)
00021 , num_evaluations_(0)
00022 , start_error_(0)
00023 , end_error_(0)
00024 , trace(false)
00025 , verbose_(false)
00026 , check_derivatives_(0)
00027 , failure_code_(ERROR_FAILURE)
00028 {
00029 }
00030 
00031 vnl_nonlinear_minimizer::~vnl_nonlinear_minimizer()
00032 {
00033 }
00034 
00035 vnl_matrix<double> const& vnl_nonlinear_minimizer::get_covariance()
00036 {
00037   static vnl_matrix<double> null;
00038   return null;
00039 }
00040 
00041 void vnl_nonlinear_minimizer::reset()
00042 {
00043   num_iterations_ = 0;
00044   num_evaluations_ = 0;
00045   start_error_ = 0;
00046   end_error_ = 0;
00047 }
00048 
00049 //: Called by derived classes after each function evaluation.
00050 void vnl_nonlinear_minimizer::report_eval(double f)
00051 {
00052   if (num_evaluations_ == 0) {
00053     start_error_ = f;
00054     end_error_ = f;
00055   }
00056   if (f < end_error_)
00057     end_error_ = f;
00058 
00059   ++num_evaluations_;
00060 }
00061 
00062 //: Called by derived classes after each iteration.
00063 bool vnl_nonlinear_minimizer::report_iter()
00064 {
00065   ++num_iterations_;
00066   if (verbose_)
00067     vcl_cerr << "Iter " << vcl_setw(4) << num_iterations_ << ", Eval "
00068              << vcl_setw(4) << num_evaluations_ << ": Best F = "
00069              << vcl_setw(10) << end_error_ << '\n';
00070   return false;
00071 }
00072 
00073 //: Return the name of the class
00074 //  Used by polymorphic IO
00075 vcl_string vnl_nonlinear_minimizer::is_a() const
00076 {
00077   static const vcl_string class_name_="vnl_nonlinear_minimizer";
00078   return class_name_;
00079 }
00080 
00081 //: Return true if the name of the class matches the argument
00082 //  Used by polymorphic IO
00083 bool vnl_nonlinear_minimizer::is_class(vcl_string const& s) const
00084 {
00085   return s==vnl_nonlinear_minimizer::is_a();
00086 }
00087