Public Member Functions | Protected Member Functions | List of all members
mirtk::ObjectiveFunction Class Referenceabstract

#include <ObjectiveFunction.h>

Inheritance diagram for mirtk::ObjectiveFunction:
Inheritance graph
Collaboration diagram for mirtk::ObjectiveFunction:
Collaboration graph

Public Member Functions

virtual void AddConstraintGradient (double *dx, double step=.0, bool *sgn_chg=nullptr)
 
virtual void DataFidelityGradient (double *dx, double step=.0, bool *sgn_chg=nullptr)
 
virtual double Evaluate (double *dx=NULL, double step=.0, bool *sgn_chg=NULL)
 
virtual double Get (int i) const =0
 
virtual void Get (double *x) const =0
 
virtual void Gradient (double *dx, double step=.0, bool *sgn_chg=nullptr)=0
 
virtual double GradientNorm (const double *dx) const =0
 
virtual void GradientStep (const double *dx, double &min, double &max) const
 
virtual int NumberOfDOFs () const =0
 
virtual void Put (const double *x)=0
 
virtual double Step (double *dx)=0
 
virtual void Update (bool gradient=true)
 
virtual bool Upgrade ()
 
virtual double Value ()=0
 Evaluate objective function value.
 
virtual ~ObjectiveFunction ()=0
 Destructor.
 
- Public Member Functions inherited from mirtk::Observable
void AddObserver (Observer &)
 Add observer.
 
void Broadcast (Event, const void *=NULL)
 Broadcast event to observers.
 
void ClearObservers ()
 Delete all observers.
 
void DeleteObserver (Observer &)
 Delete observer.
 
void NotifyObservers (Event, const void *=NULL)
 Notify all observers about given event if this object has changed.
 
int NumberOfObservers () const
 Number of current observers.
 
virtual ~Observable ()
 Destructor.
 
- Public Member Functions inherited from mirtk::Object
virtual const char * NameOfClass () const =0
 Get name of class, which this object is an instance of.
 
virtual ParameterList Parameter () const
 Get parameter name/value pairs.
 
bool Parameter (const ParameterList &)
 Set parameters from name/value pairs.
 
virtual bool Set (const char *name, const char *value)
 
virtual ~Object ()
 Destructor.
 

Protected Member Functions

 mirtkAttributeMacro (double, StepLength)
 Default step length used for gradient approximation.
 
- Protected Member Functions inherited from mirtk::Observable
 Observable ()
 Default constructor.
 
 Observable (const Observable &)
 Copy constructor.
 
Observableoperator= (const Observable &)
 Assignment operator.
 
- Protected Member Functions inherited from mirtk::Object
template<typename... Args>
void Throw (ErrorType err, const char *func, Args... args) const
 

Additional Inherited Members

- Static Public Member Functions inherited from mirtk::Object
static const char * NameOfType ()
 Get name of this class type.
 
- Static Protected Member Functions inherited from mirtk::Object
template<typename... Args>
static void ThrowStatic (ErrorType err, const char *cls, const char *func, Args... args)
 

Detailed Description

Interface for objective function of an optimization problem.

An objective function can be minimized/maximized using a specialization of the irtkLocalOptimizer base class.

Definition at line 35 of file ObjectiveFunction.h.

Member Function Documentation

§ AddConstraintGradient()

void mirtk::ObjectiveFunction::AddConstraintGradient ( double *  dx,
double  step = .0,
bool *  sgn_chg = nullptr 
)
inlinevirtual

Add model constraint gradient of objective function w.r.t its DoFs

Parameters
[in]stepStep length for finite differences.
[out]dxGradient of objective function, e.g., either initialised to zero or the data fidelity gradient computed beforehand using DataFidelityGradient.
[out]sgn_chgWhether function parameter value is allowed to change sign when stepping along the computed gradient.

Reimplemented in mirtk::RegistrationEnergy.

Definition at line 226 of file ObjectiveFunction.h.

§ DataFidelityGradient()

void mirtk::ObjectiveFunction::DataFidelityGradient ( double *  dx,
double  step = .0,
bool *  sgn_chg = nullptr 
)
inlinevirtual

Evaluate data fidelity gradient of objective function w.r.t its DoFs

Parameters
[in]stepStep length for finite differences.
[out]dxData fidelity gradient of objective function.
[out]sgn_chgWhether function parameter value is allowed to change sign when stepping along the computed gradient.

Reimplemented in mirtk::RegistrationEnergy.

Definition at line 219 of file ObjectiveFunction.h.

§ Evaluate()

double mirtk::ObjectiveFunction::Evaluate ( double *  dx = NULL,
double  step = .0,
bool *  sgn_chg = NULL 
)
inlinevirtual

Evaluate objective function

This function first updates the internal state of the function object if required due to a previous change of the function parameters and then evaluates the current function value. If dx is not NULL, the gradient of the objective function is computed as well.

Parameters
[in]stepStep length for finite differences.
[out]dxGradient of objective function. If NULL, only the function value is computed.
[out]sgn_chgWhether function parameter value is allowed to change sign when stepping along the computed gradient. Ignord if dx is NULL.
Returns
Value of the objective function.

Reimplemented in mirtk::DeformableSurfaceModel, and mirtk::RegistrationEnergy.

Definition at line 232 of file ObjectiveFunction.h.

§ Get() [1/2]

virtual double mirtk::ObjectiveFunction::Get ( int  i) const
pure virtual

Get function parameter value

Parameters
[in]iFunction parameter (DoF) index.
Returns
Value of specified function parameter (DoF).

Implemented in mirtk::DeformableSurfaceModel, mirtk::RegistrationEnergy, and mirtk::TransformationApproximationError.

§ Get() [2/2]

virtual void mirtk::ObjectiveFunction::Get ( double *  x) const
pure virtual

Get function parameter values

This function can be used to store a backup of the current funtion parameter values before an update such that these can be restored using the Put member function if the update did not result in the desired change of the overall objective function value.

Parameters
[in]xFunction parameter (DoF) values.

Implemented in mirtk::DeformableSurfaceModel, mirtk::RegistrationEnergy, and mirtk::TransformationApproximationError.

§ Gradient()

virtual void mirtk::ObjectiveFunction::Gradient ( double *  dx,
double  step = .0,
bool *  sgn_chg = nullptr 
)
pure virtual

Evaluate gradient of objective function w.r.t its DoFs

When the data fidelity and/or gradient of model constraints need to be evaluated separately, use the following code instead:

double *gradient; // allocate with number of DoFs
ObjectiveFunction *func; // pointer to objective function instance
func->DataFideltiyGradient(gradient);
func->AddConstraintGradient(gradient);
Parameters
[in]stepStep length for finite differences.
[out]dxGradient of objective function.
[out]sgn_chgWhether function parameter value is allowed to change sign when stepping along the computed gradient.

Implemented in mirtk::DeformableSurfaceModel, mirtk::RegistrationEnergy, and mirtk::TransformationApproximationError.

§ GradientNorm()

virtual double mirtk::ObjectiveFunction::GradientNorm ( const double *  dx) const
pure virtual

Compute norm of gradient of objective function

This norm is used to define a unit for the step length used by gradient descent methods. It is, for example, the maximum absolute value norm for linear transformations and the maximum control point displacement for FFDs. The computation of the norm may be done after conjugating the gradient vector obtained using the Gradient member function.

Parameters
[in]dxGradient of objective function.

Implemented in mirtk::DeformableSurfaceModel, mirtk::RegistrationEnergy, and mirtk::TransformationApproximationError.

§ GradientStep()

void mirtk::ObjectiveFunction::GradientStep ( const double *  dx,
double &  min,
double &  max 
) const
inlinevirtual

Adjust step length range

Parameters
[in]dxGradient of objective function.
[in,out]minMinimum step length.
[in,out]maxMaximum step length.

Reimplemented in mirtk::DeformableSurfaceModel, and mirtk::RegistrationEnergy.

Definition at line 213 of file ObjectiveFunction.h.

§ NumberOfDOFs()

virtual int mirtk::ObjectiveFunction::NumberOfDOFs ( ) const
pure virtual

Get number of DoFs

Returns
Number of free function parameters.

Implemented in mirtk::DeformableSurfaceModel, mirtk::RegistrationEnergy, and mirtk::TransformationApproximationError.

§ Put()

virtual void mirtk::ObjectiveFunction::Put ( const double *  x)
pure virtual

Set function parameter values

This is function can be used to set the parameters of the objective function to particular values. In particular, it can be used to restore the function parameters after a failed incremental update which did not result in the desired improvement.

Parameters
[in]xFunction parameter (DoF) values.

Implemented in mirtk::DeformableSurfaceModel, mirtk::RegistrationEnergy, and mirtk::TransformationApproximationError.

§ Step()

virtual double mirtk::ObjectiveFunction::Step ( double *  dx)
pure virtual

Add change (i.e., scaled gradient) to each parameter value

This function updates each DoF of the objective function given a vector of corresponding changes, i.e., the computed gradient of the objective function w.r.t. these parameters or a desired change computed otherwise.

Parameters
[in,out]dxChange of each function parameter (DoF) as computed by the Gradient member function and scaled by a chosen step length. The change of a parameter may be modified by this function in order to satisfy the hard constraints (if any).
Returns
Maximum change of function parameter.

Implemented in mirtk::DeformableSurfaceModel, mirtk::RegistrationEnergy, and mirtk::TransformationApproximationError.

§ Update()

void mirtk::ObjectiveFunction::Update ( bool  gradient = true)
inlinevirtual

Update internal state after change of parameters

Parameters
[in]gradientUpdate also internal state required for evaluation of gradient of objective function.

Reimplemented in mirtk::DeformableSurfaceModel, mirtk::RegistrationEnergy, and mirtk::TransformationApproximationError.

Definition at line 202 of file ObjectiveFunction.h.

§ Upgrade()

bool mirtk::ObjectiveFunction::Upgrade ( )
inlinevirtual

Update objective function after convergence

This function may be called by the optimizer after the optimization of the current objective function has converged or the improvement is insignificant. It allows the objective function to modify itself considering the current estimate of the parameters (DoFs). For example, the fiducial registration error term of a registration energy function could update the point correspondences.

Returns
Whether the objective function has changed.

Reimplemented in mirtk::DeformableSurfaceModel, and mirtk::RegistrationEnergy.

Definition at line 207 of file ObjectiveFunction.h.


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