core/vnl/algo/vnl_brent.cxx
Go to the documentation of this file.
00001 // This is core/vnl/algo/vnl_brent.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 
00006 #include "vnl_brent.h"
00007 
00008 #include <vcl_cassert.h>
00009 
00010 #include <vnl/algo/vnl_bracket_minimum.h>
00011 
00012 
00013 vnl_brent::vnl_brent(vnl_cost_function* functor)
00014   : vnl_brent_minimizer( *functor )
00015 {
00016 }
00017 
00018 vnl_brent::~vnl_brent()
00019 {
00020 }
00021 
00022 double vnl_brent::minimize_given_bounds(double ax, double bx, double cx,
00023                                         double tol,
00024                                         double *xmin)
00025 {
00026   assert( xmin != NULL );
00027   this->set_x_tolerance( tol );
00028   *xmin = vnl_brent_minimizer::minimize_given_bounds( ax, bx, cx );
00029   return vnl_brent_minimizer::f_at_last_minimum();
00030 }
00031 
00032 double vnl_brent::minimize_given_bounds_and_1st_f(double ax, double bx,
00033                                                   double fb, double cx,
00034                                                   double tol, double *xmin)
00035 {
00036   assert( xmin != NULL );
00037   this->set_x_tolerance( tol );
00038   *xmin = vnl_brent_minimizer::minimize_given_bounds_and_one_f( ax, bx, cx, fb );
00039   return vnl_brent_minimizer::f_at_last_minimum();
00040 }
00041 
00042 
00043 void vnl_brent::bracket_minimum(double *ax, double *bx, double *cx)
00044 {
00045   double fa, fb, fc;
00046   bracket_minimum(ax,bx,cx,&fa,&fb,&fc);
00047 }
00048 
00049 void vnl_brent::bracket_minimum(double *ax, double *bx, double *cx,
00050                                 double *fa, double *fb, double *fc)
00051 {
00052   vnl_bracket_minimum( *f_, *cx, *bx, *ax, *fc, *fb, *fa );
00053 }
00054 
00055 
00056 double vnl_brent::minimize(double x)
00057 {
00058   double ax=x-1.0;
00059   double xx=x+1.0;
00060   double bx,fa,fx,fb;
00061   bracket_minimum(&ax,&xx,&bx,&fa,&fx,&fb);
00062   minimize_given_bounds(bx,xx,ax,ftol,&x);
00063   return x;
00064 }