Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Related Functions
vnl_least_squares_function Class Reference

Abstract base for minimising functions. More...

#include <vnl_least_squares_function.h>

List of all members.

Public Types

enum  UseGradient { no_gradient, use_gradient }

Public Member Functions

 vnl_least_squares_function (unsigned int number_of_unknowns, unsigned int number_of_residuals, UseGradient g=use_gradient)
 Construct vnl_least_squares_function.
virtual ~vnl_least_squares_function ()
void throw_failure ()
void clear_failure ()
virtual void f (vnl_vector< double > const &x, vnl_vector< double > &fx)=0
 The main function.
virtual void gradf (vnl_vector< double > const &x, vnl_matrix< double > &jacobian)
 Calculate the Jacobian, given the parameter vector x.
void fdgradf (vnl_vector< double > const &x, vnl_matrix< double > &jacobian, double stepsize)
 Use this to compute a finite-difference gradient other than lmdif.
void ffdgradf (vnl_vector< double > const &x, vnl_matrix< double > &jacobian, double stepsize)
 Use this to compute a finite-forward-difference gradient other than lmdif.
virtual void trace (int iteration, vnl_vector< double > const &x, vnl_vector< double > const &fx)
 Called after each LM iteration to print debugging etc.
double rms (vnl_vector< double > const &x)
 Compute the rms error at x by calling f and returning the norm of the residual vector.
unsigned int get_number_of_unknowns () const
 Return the number of unknowns.
unsigned int get_number_of_residuals () const
 Return the number of residuals.
bool has_gradient () const
 Return true if the derived class has indicated that gradf has been implemented.

Public Attributes

bool failure

Protected Member Functions

void init (unsigned int number_of_unknowns, unsigned int number_of_residuals)

Protected Attributes

unsigned int p_
unsigned int n_
bool use_gradient_

Private Member Functions

void dim_warning (unsigned int n_unknowns, unsigned int n_residuals)

Related Functions

(Note that these are not member functions.)

bool vnl_discrete_diff_fwd (vnl_least_squares_function *lsf, double h, vnl_vector< double > const &x, vnl_matrix< double > &J)
 forward differences.
bool vnl_discrete_diff_fwd (vnl_least_squares_function *lsf, vnl_vector< double > const &h, vnl_vector< double > const &x, vnl_matrix< double > &J)
 forward differences.
bool vnl_discrete_diff_fwd (vnl_least_squares_function *lsf, vnl_vector< double > const &h, vnl_vector< double > const &x, vnl_vector< double > const &y, vnl_matrix< double > &J)
 forward differences.
bool vnl_discrete_diff_sym (vnl_least_squares_function *lsf, double h, vnl_vector< double > const &x, vnl_matrix< double > &J)
 symmetric differences.
bool vnl_discrete_diff_sym (vnl_least_squares_function *lsf, vnl_vector< double > const &h, vnl_vector< double > const &x, vnl_matrix< double > &J)
 symmetric differences.

Detailed Description

Abstract base for minimising functions.

vnl_least_squares_function is an abstract base for functions to be minimized by an optimizer. To define your own function to be minimized, subclass from vnl_least_squares_function, and implement the pure virtual f (and optionally grad_f).

Whether or not f ought to be const is a problem. Clients might well want to cache some information during the call, and if they're compute objects, will almost certainly be writing to members during the computation. For the moment it's non-const, but we'll see...

Definition at line 36 of file vnl_least_squares_function.h.


Member Enumeration Documentation

Enumerator:
no_gradient 
use_gradient 

Definition at line 39 of file vnl_least_squares_function.h.


Constructor & Destructor Documentation

vnl_least_squares_function::vnl_least_squares_function ( unsigned int  number_of_unknowns,
unsigned int  number_of_residuals,
UseGradient  g = use_gradient 
) [inline]

Construct vnl_least_squares_function.

Passing number of parameters (unknowns, domain dimension) and number of residuals (range dimension). The optional argument should be no_gradient if the gradf function has not been implemented. Default is use_gradient.

Definition at line 50 of file vnl_least_squares_function.h.

virtual vnl_least_squares_function::~vnl_least_squares_function ( ) [inline, virtual]

Definition at line 57 of file vnl_least_squares_function.h.


Member Function Documentation

void vnl_least_squares_function::clear_failure ( ) [inline]

Definition at line 61 of file vnl_least_squares_function.h.

void vnl_least_squares_function::dim_warning ( unsigned int  n_unknowns,
unsigned int  n_residuals 
) [private]

Definition at line 14 of file vnl_least_squares_function.cxx.

virtual void vnl_least_squares_function::f ( vnl_vector< double > const &  x,
vnl_vector< double > &  fx 
) [pure virtual]

The main function.

Given the parameter vector x, compute the vector of residuals fx. Fx has been sized appropriately before the call.

void vnl_least_squares_function::fdgradf ( vnl_vector< double > const &  x,
vnl_matrix< double > &  jacobian,
double  stepsize 
)

Use this to compute a finite-difference gradient other than lmdif.

Compute finite differences gradient using central differences.

Definition at line 30 of file vnl_least_squares_function.cxx.

void vnl_least_squares_function::ffdgradf ( vnl_vector< double > const &  x,
vnl_matrix< double > &  jacobian,
double  stepsize 
)

Use this to compute a finite-forward-difference gradient other than lmdif.

Compute finite differences gradient using forward differences.

This takes about half as many estimates as fdgradf

Definition at line 64 of file vnl_least_squares_function.cxx.

unsigned int vnl_least_squares_function::get_number_of_residuals ( ) const [inline]

Return the number of residuals.

Definition at line 92 of file vnl_least_squares_function.h.

unsigned int vnl_least_squares_function::get_number_of_unknowns ( ) const [inline]

Return the number of unknowns.

Definition at line 89 of file vnl_least_squares_function.h.

void vnl_least_squares_function::gradf ( vnl_vector< double > const &  x,
vnl_matrix< double > &  jacobian 
) [virtual]

Calculate the Jacobian, given the parameter vector x.

Definition at line 23 of file vnl_least_squares_function.cxx.

bool vnl_least_squares_function::has_gradient ( ) const [inline]

Return true if the derived class has indicated that gradf has been implemented.

Definition at line 95 of file vnl_least_squares_function.h.

void vnl_least_squares_function::init ( unsigned int  number_of_unknowns,
unsigned int  number_of_residuals 
) [inline, protected]

Definition at line 102 of file vnl_least_squares_function.h.

double vnl_least_squares_function::rms ( vnl_vector< double > const &  x)

Compute the rms error at x by calling f and returning the norm of the residual vector.

Definition at line 100 of file vnl_least_squares_function.cxx.

void vnl_least_squares_function::throw_failure ( ) [inline]

Definition at line 60 of file vnl_least_squares_function.h.

void vnl_least_squares_function::trace ( int  iteration,
vnl_vector< double > const &  x,
vnl_vector< double > const &  fx 
) [virtual]

Called after each LM iteration to print debugging etc.

Definition at line 93 of file vnl_least_squares_function.cxx.


Friends And Related Function Documentation

bool vnl_discrete_diff_fwd ( vnl_least_squares_function lsf,
double  h,
vnl_vector< double > const &  x,
vnl_matrix< double > &  J 
) [related]

forward differences.

Definition at line 8 of file vnl_discrete_diff.cxx.

bool vnl_discrete_diff_fwd ( vnl_least_squares_function lsf,
vnl_vector< double > const &  h,
vnl_vector< double > const &  x,
vnl_matrix< double > &  J 
) [related]

forward differences.

Definition at line 22 of file vnl_discrete_diff.cxx.

bool vnl_discrete_diff_fwd ( vnl_least_squares_function lsf,
vnl_vector< double > const &  h,
vnl_vector< double > const &  x,
vnl_vector< double > const &  y,
vnl_matrix< double > &  J 
) [related]

forward differences.

Definition at line 34 of file vnl_discrete_diff.cxx.

bool vnl_discrete_diff_sym ( vnl_least_squares_function lsf,
double  h,
vnl_vector< double > const &  x,
vnl_matrix< double > &  J 
) [related]

symmetric differences.

Definition at line 62 of file vnl_discrete_diff.cxx.

bool vnl_discrete_diff_sym ( vnl_least_squares_function lsf,
vnl_vector< double > const &  h,
vnl_vector< double > const &  x,
vnl_matrix< double > &  J 
) [related]

symmetric differences.

Definition at line 72 of file vnl_discrete_diff.cxx.


Member Data Documentation

Definition at line 43 of file vnl_least_squares_function.h.

unsigned int vnl_least_squares_function::n_ [protected]

Definition at line 99 of file vnl_least_squares_function.h.

unsigned int vnl_least_squares_function::p_ [protected]

Definition at line 98 of file vnl_least_squares_function.h.

Definition at line 100 of file vnl_least_squares_function.h.


The documentation for this class was generated from the following files: