Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Related Functions | List of all members
vnl_least_squares_function Class Referenceabstract

Abstract base for minimising functions. More...

#include <vnl_least_squares_function.h>

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

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_ALGO_EXPORT vnl_discrete_diff_fwd (vnl_least_squares_function *lsf, double h, vnl_vector< double > const &x, vnl_matrix< double > &J)
 forward differences. More...
 
bool VNL_ALGO_EXPORT 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. More...
 
bool VNL_ALGO_EXPORT 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. More...
 
bool VNL_ALGO_EXPORT vnl_discrete_diff_sym (vnl_least_squares_function *lsf, double h, vnl_vector< double > const &x, vnl_matrix< double > &J)
 symmetric differences. More...
 
bool VNL_ALGO_EXPORT 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. More...
 

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 35 of file vnl_least_squares_function.h.

Member Enumeration Documentation

◆ UseGradient

Enumerator
no_gradient 
use_gradient 

Definition at line 38 of file vnl_least_squares_function.h.

Constructor & Destructor Documentation

◆ vnl_least_squares_function()

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 49 of file vnl_least_squares_function.h.

◆ ~vnl_least_squares_function()

virtual vnl_least_squares_function::~vnl_least_squares_function ( )
virtualdefault

Member Function Documentation

◆ clear_failure()

void vnl_least_squares_function::clear_failure ( )
inline

Definition at line 60 of file vnl_least_squares_function.h.

◆ dim_warning()

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

Definition at line 11 of file vnl_least_squares_function.cxx.

◆ f()

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.

◆ fdgradf()

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 27 of file vnl_least_squares_function.cxx.

◆ ffdgradf()

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 61 of file vnl_least_squares_function.cxx.

◆ get_number_of_residuals()

unsigned int vnl_least_squares_function::get_number_of_residuals ( ) const
inline

Return the number of residuals.

Definition at line 91 of file vnl_least_squares_function.h.

◆ get_number_of_unknowns()

unsigned int vnl_least_squares_function::get_number_of_unknowns ( ) const
inline

Return the number of unknowns.

Definition at line 88 of file vnl_least_squares_function.h.

◆ gradf()

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 20 of file vnl_least_squares_function.cxx.

◆ has_gradient()

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 94 of file vnl_least_squares_function.h.

◆ init()

void vnl_least_squares_function::init ( unsigned int  number_of_unknowns,
unsigned int  number_of_residuals 
)
inlineprotected

Definition at line 101 of file vnl_least_squares_function.h.

◆ rms()

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 97 of file vnl_least_squares_function.cxx.

◆ throw_failure()

void vnl_least_squares_function::throw_failure ( )
inline

Definition at line 59 of file vnl_least_squares_function.h.

◆ trace()

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 90 of file vnl_least_squares_function.cxx.

Friends And Related Function Documentation

◆ vnl_discrete_diff_fwd() [1/3]

bool VNL_ALGO_EXPORT 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 10 of file vnl_discrete_diff.cxx.

◆ vnl_discrete_diff_fwd() [2/3]

bool VNL_ALGO_EXPORT 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 24 of file vnl_discrete_diff.cxx.

◆ vnl_discrete_diff_fwd() [3/3]

bool VNL_ALGO_EXPORT 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 36 of file vnl_discrete_diff.cxx.

◆ vnl_discrete_diff_sym() [1/2]

bool VNL_ALGO_EXPORT 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 64 of file vnl_discrete_diff.cxx.

◆ vnl_discrete_diff_sym() [2/2]

bool VNL_ALGO_EXPORT 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 74 of file vnl_discrete_diff.cxx.

Member Data Documentation

◆ failure

bool vnl_least_squares_function::failure

Definition at line 42 of file vnl_least_squares_function.h.

◆ n_

unsigned int vnl_least_squares_function::n_
protected

Definition at line 98 of file vnl_least_squares_function.h.

◆ p_

unsigned int vnl_least_squares_function::p_
protected

Definition at line 97 of file vnl_least_squares_function.h.

◆ use_gradient_

bool vnl_least_squares_function::use_gradient_
protected

Definition at line 99 of file vnl_least_squares_function.h.


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