STIR  6.2.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
stir::GeneralisedObjectiveFunction< TargetT > Class Template Referenceabstract

A base class for 'generalised' objective functions, i.e. objective functions for which at least a 'gradient' is defined. More...

#include "stir/recon_buildblock/GeneralisedObjectiveFunction.h"

Inheritance diagram for stir::GeneralisedObjectiveFunction< TargetT >:
Inheritance graph
[legend]

Public Member Functions

virtual TargetT * construct_target_ptr () const =0
 Creates a suitable target as determined by the parameters. More...
 
virtual Succeeded set_up (shared_ptr< TargetT > const &target_sptr)
 Has to be called before using this object.
 
virtual void compute_sub_gradient (TargetT &gradient, const TargetT &current_estimate, const int subset_num)
 Compute the subset-gradient of the objective function at current_estimate. More...
 
virtual void compute_sub_gradient_without_penalty (TargetT &gradient, const TargetT &current_estimate, const int subset_num)=0
 This should compute the subset-gradient of the unregularised objective function at current_estimate. More...
 
virtual void compute_gradient (TargetT &gradient, const TargetT &current_estimate)
 Compute the gradient of the objective function at the current_estimate. More...
 
virtual void compute_gradient_without_penalty (TargetT &gradient, const TargetT &current_estimate)
 Compute the gradient of the unregularised objective function at the current_estimate. More...
 
virtual double compute_objective_function_without_penalty (const TargetT &current_estimate, const int subset_num)
 Compute the value of the unregularised sub-objective function at the current_estimate. More...
 
virtual double compute_objective_function_without_penalty (const TargetT &current_estimate)
 Compute the value of the unregularised objective function at the current_estimate. More...
 
double compute_penalty (const TargetT &current_estimate, const int subset_num)
 Compute the value of the sub-penalty at the current_estimate. More...
 
double compute_penalty (const TargetT &current_estimate)
 Compute the value of the penalty at the current_estimate. More...
 
double compute_objective_function (const TargetT &current_estimate, const int subset_num)
 Compute the value of the sub-objective function at the current_estimate. More...
 
double compute_objective_function (const TargetT &current_estimate)
 Compute the value of the objective function at the current_estimate. More...
 
double compute_value (const TargetT &current_estimate)
 Alias for compute_objective_function(const TargetT&)
 
virtual void fill_nonidentifiable_target_parameters (TargetT &target, const float value) const
 Fill any elements that we cannot estimate with a fixed value. More...
 
std::string get_objective_function_values_report (const TargetT &current_estimate)
 Construct a string with info on the value of objective function with and without penalty.
 
int get_num_subsets () const
 Return the number of subsets in-use.
 
virtual std::unique_ptr< ExamInfoget_exam_info_uptr_for_target () const
 
virtual int set_num_subsets (const int num_subsets)=0
 Attempts to change the number of subsets. More...
 
bool subsets_are_approximately_balanced () const
 Checks of the current subset scheme is approximately balanced. More...
 
bool subsets_are_approximately_balanced (std::string &warning_message) const
 Checks of the current subset scheme is approximately balanced and constructs a warning message. More...
 
bool prior_is_zero () const
 check if the prior is set (or the penalisation factor is 0)
 
GeneralisedPrior< TargetT > *const get_prior_ptr () const
 Read-only access to the prior. More...
 
shared_ptr< GeneralisedPrior< TargetT > > get_prior_sptr ()
 
void set_prior_sptr (const shared_ptr< GeneralisedPrior< TargetT >> &)
 Change the prior. More...
 
virtual void set_input_data (const shared_ptr< ExamData > &)=0
 set_input_data More...
 
virtual const ExamDataget_input_data () const =0
 get input data More...
 
virtual void set_additive_proj_data_sptr (const shared_ptr< ExamData > &)=0
 set_additive_proj_data_sptr More...
 
virtual void set_normalisation_sptr (const shared_ptr< BinNormalisation > &)=0
 set_normalisation_sptr More...
 
multiplication with approximate (sub)Hessian
Succeeded add_multiplication_with_approximate_sub_Hessian_without_penalty (TargetT &output, const TargetT &input, const int subset_num) const
 Functions that multiply the approximate (sub)Hessian with a \'vector\'. More...
 
Succeeded add_multiplication_with_approximate_sub_Hessian (TargetT &output, const TargetT &input, const int subset_num) const
 
Succeeded add_multiplication_with_approximate_Hessian_without_penalty (TargetT &output, const TargetT &input) const
 
Succeeded add_multiplication_with_approximate_Hessian (TargetT &output, const TargetT &input) const
 
multiplication (sub)Hessian times input
Succeeded accumulate_Hessian_times_input (TargetT &output, const TargetT &current_image_estimate, const TargetT &input) const
 Functions that multiply the True (sub)Hessian with a \'vector\'. More...
 
Succeeded accumulate_Hessian_times_input_without_penalty (TargetT &output, const TargetT &current_image_estimate, const TargetT &input) const
 
Succeeded accumulate_sub_Hessian_times_input (TargetT &output, const TargetT &current_image_estimate, const TargetT &input, const int subset_num) const
 
Succeeded accumulate_sub_Hessian_times_input_without_penalty (TargetT &output, const TargetT &current_image_estimate, const TargetT &input, const int subset_num) const
 
- Public Member Functions inherited from stir::RegisteredObjectBase
virtual std::string get_registered_name () const =0
 Returns the name of the type of the object. More...
 
- Public Member Functions inherited from stir::ParsingObject
 ParsingObject (const ParsingObject &)
 
ParsingObjectoperator= (const ParsingObject &)
 
void ask_parameters ()
 
virtual std::string parameter_info ()
 
bool parse (std::istream &f)
 
bool parse (const char *const filename)
 

Protected Member Functions

void set_defaults () override
 sets any default values More...
 
void initialise_keymap () override
 sets parsing keys More...
 
virtual bool actual_subsets_are_approximately_balanced (std::string &warning_message) const =0
 Implementation of function that checks subset balancing. More...
 
virtual double actual_compute_objective_function_without_penalty (const TargetT &current_estimate, const int subset_num)=0
 Implementation of function that computes the objective function for the current subset. More...
 
virtual Succeeded actual_add_multiplication_with_approximate_sub_Hessian_without_penalty (TargetT &output, const TargetT &input, const int subset_num) const
 Implementation of the function that multiplies the approximate sub-Hessian with a vector. More...
 
virtual Succeeded actual_accumulate_sub_Hessian_times_input_without_penalty (TargetT &output, const TargetT &current_image_estimate, const TargetT &input, const int subset_num) const
 Implementation of the function computes the sub-Hessian and multiplies by a vector. More...
 
- Protected Member Functions inherited from stir::ParsingObject
virtual bool post_processing ()
 This will be called at the end of the parsing. More...
 
virtual void set_key_values ()
 This will be called before parsing or parameter_info is called. More...
 

Protected Attributes

int num_subsets
 
bool already_set_up
 
shared_ptr< GeneralisedPrior< TargetT > > prior_sptr
 
- Protected Attributes inherited from stir::ParsingObject
KeyParser parser
 

Additional Inherited Members

- Static Public Member Functions inherited from stir::RegisteredObject< GeneralisedObjectiveFunction< TargetT > >
static GeneralisedObjectiveFunction< TargetT > * read_registered_object (std::istream *in, const std::string &registered_name)
 Construct a new object (of a type derived from Root, its actual type determined by the registered_name parameter) by parsing the istream. More...
 
static GeneralisedObjectiveFunction< TargetT > * ask_type_and_parameters ()
 ask the user for the type, and then calls read_registered_object(0, type) More...
 
static void list_registered_names (std::ostream &stream)
 List all possible registered names to the stream. More...
 
- Protected Types inherited from stir::RegisteredObject< GeneralisedObjectiveFunction< TargetT > >
typedef GeneralisedObjectiveFunction< TargetT > *(* RootFactory) (std::istream *)
 The type of a root factory is a function, taking an istream* as argument, and returning a Root*.
 
typedef FactoryRegistry< std::string, RootFactory, interfile_lessRegistryType
 The type of the registry.
 
- Static Protected Member Functions inherited from stir::RegisteredObject< GeneralisedObjectiveFunction< TargetT > >
static RegistryTyperegistry ()
 Static function returning the registry. More...
 

Detailed Description

template<typename TargetT>
class stir::GeneralisedObjectiveFunction< TargetT >

A base class for 'generalised' objective functions, i.e. objective functions for which at least a 'gradient' is defined.

Some iterative algorithms use an 'objective function' only in a loose sense. They might for instance allow generalisations which no longer optimise a function. For example in the case of PoissonLogLikelihoodWithLinearModelForMeanAndProjData with non-matching forward and back projectors, the 'gradient' that is computed is generally not the gradient of the log-likelihood that corresponds to the forward projector. However, one hopes that it still points towards the optimum.

Often, one includes a penalty (or prior) in the objective function. This class uses a GeneralisedPrior object for this. Note that we use the convention that the objective function is maximised. The penalty is expected to be a function that increases with higher penalty, so it will be subtracted from the unregularised case.

In tomography, we often use subsets, where the objective function is written as a sum of sub-objective functions. This class has some subset functionality. When using subsets, the penalty will be distributed evenly over all subsets. While this increases the computational cost, it makes the subsets more 'balanced' which is best for most algorithms.

See also
IterativeReconstruction
Todo:
Currently, there is subset code in both IterativeReconstruction and here. This is confusing and leads to repetition. It probably should all be moved here.
Parameters for parsing
; specify prior, see GeneralisedObjectiveFunction<TargetT> hierarchy for possible values
prior type :=

Member Function Documentation

◆ construct_target_ptr()

template<typename TargetT>
virtual TargetT* stir::GeneralisedObjectiveFunction< TargetT >::construct_target_ptr ( ) const
pure virtual

◆ compute_sub_gradient()

template<typename TargetT >
void stir::GeneralisedObjectiveFunction< TargetT >::compute_sub_gradient ( TargetT &  gradient,
const TargetT &  current_estimate,
const int  subset_num 
)
virtual

Compute the subset-gradient of the objective function at current_estimate.

The subset-gradient is the gradient of the objective function restricted to the subset specified. What this means depends on how this function is implemented later on in the hierarchy.

Computed as the difference of compute_sub_gradient_without_penalty and get_prior_ptr()->compute_gradient()/num_subsets.

Warning
Any data in gradient will be overwritten.

References stir::error().

◆ compute_sub_gradient_without_penalty()

template<typename TargetT>
virtual void stir::GeneralisedObjectiveFunction< TargetT >::compute_sub_gradient_without_penalty ( TargetT &  gradient,
const TargetT &  current_estimate,
const int  subset_num 
)
pure virtual

This should compute the subset-gradient of the unregularised objective function at current_estimate.

Warning
The derived class should overwrite any data in gradient.

Implemented in stir::PoissonLogLikelihoodWithLinearModelForMean< TargetT >, and stir::SumOfGeneralisedObjectiveFunctions< PoissonLogLikelihoodWithLinearModelForMeanAndProjData< TargetT >, TargetT, PoissonLogLikelihoodWithLinearModelForMean< TargetT > >.

◆ compute_gradient()

template<typename TargetT >
void stir::GeneralisedObjectiveFunction< TargetT >::compute_gradient ( TargetT &  gradient,
const TargetT &  current_estimate 
)
virtual

Compute the gradient of the objective function at the current_estimate.

Computed as the difference of compute_gradient_without_penalty and get_prior_ptr()->compute_gradient().

Warning
Any data in gradient will be overwritten.

◆ compute_gradient_without_penalty()

template<typename TargetT >
void stir::GeneralisedObjectiveFunction< TargetT >::compute_gradient_without_penalty ( TargetT &  gradient,
const TargetT &  current_estimate 
)
virtual

Compute the gradient of the unregularised objective function at the current_estimate.

Computed by summing subset-gradients.

Warning
Any data in gradient will be overwritten.

◆ compute_objective_function_without_penalty() [1/2]

template<typename TargetT >
double stir::GeneralisedObjectiveFunction< TargetT >::compute_objective_function_without_penalty ( const TargetT &  current_estimate,
const int  subset_num 
)
virtual

Compute the value of the unregularised sub-objective function at the current_estimate.

Implemented in terms of actual_compute_objective_function_without_penalty.

References stir::error().

◆ compute_objective_function_without_penalty() [2/2]

template<typename TargetT >
double stir::GeneralisedObjectiveFunction< TargetT >::compute_objective_function_without_penalty ( const TargetT &  current_estimate)
virtual

Compute the value of the unregularised objective function at the current_estimate.

Computed by summing over all subsets.

◆ compute_penalty() [1/2]

template<typename TargetT >
double stir::GeneralisedObjectiveFunction< TargetT >::compute_penalty ( const TargetT &  current_estimate,
const int  subset_num 
)

Compute the value of the sub-penalty at the current_estimate.

As each subset contains the same penalty, this function returns the same as

compute_penalty(current_estimate)/num_subsets

Implemented in terms of GeneralisedPrior::compute_value.

See also
compute_objective_function(const TargetT&) for sign conventions.

◆ compute_penalty() [2/2]

template<typename TargetT >
double stir::GeneralisedObjectiveFunction< TargetT >::compute_penalty ( const TargetT &  current_estimate)

Compute the value of the penalty at the current_estimate.

Implemented in terms of GeneralisedPrior::compute_value.

References stir::GeneralisedObjectiveFunction< TargetT >::compute_value().

◆ compute_objective_function() [1/2]

template<typename TargetT >
double stir::GeneralisedObjectiveFunction< TargetT >::compute_objective_function ( const TargetT &  current_estimate,
const int  subset_num 
)

Compute the value of the sub-objective function at the current_estimate.

Computed as the difference of compute_objective_function_without_penalty and compute_penalty.

◆ compute_objective_function() [2/2]

template<typename TargetT >
double stir::GeneralisedObjectiveFunction< TargetT >::compute_objective_function ( const TargetT &  current_estimate)

Compute the value of the objective function at the current_estimate.

Computed as the difference of compute_objective_function_without_penalty and compute_penalty.

◆ fill_nonidentifiable_target_parameters()

template<typename TargetT>
virtual void stir::GeneralisedObjectiveFunction< TargetT >::fill_nonidentifiable_target_parameters ( TargetT &  target,
const float  value 
) const
inlinevirtual

Fill any elements that we cannot estimate with a fixed value.

In many cases, it is easier to use a larger target than what we can actually estimate. For instance, using a rectangular image while we estimate only a circular region.

For some algorithms, it is important that the parameters that cannot be estimate are set to 0 (or some other value). For example, if the outer voxels contribute to the forward projection of an image, but not to a backprojection.

This function allows you to do that. Its default implementation is to do nothing. It is up to the derived class to implement this sensible.

Todo:
The type of the value should really be derived from e.g. TargetT::full_iterator.

Reimplemented in stir::PoissonLogLikelihoodWithLinearModelForMean< TargetT >.

◆ add_multiplication_with_approximate_sub_Hessian_without_penalty()

template<typename TargetT >
Succeeded stir::GeneralisedObjectiveFunction< TargetT >::add_multiplication_with_approximate_sub_Hessian_without_penalty ( TargetT &  output,
const TargetT &  input,
const int  subset_num 
) const

Functions that multiply the approximate (sub)Hessian with a \'vector\'.

All these functions add their result to any existing data in output.

They all call actual_add_multiplication_with_approximate_sub_Hessian_without_penalty.

References stir::error(), and stir::warning().

◆ accumulate_Hessian_times_input()

template<typename TargetT >
Succeeded stir::GeneralisedObjectiveFunction< TargetT >::accumulate_Hessian_times_input ( TargetT &  output,
const TargetT &  current_image_estimate,
const TargetT &  input 
) const

Functions that multiply the True (sub)Hessian with a \'vector\'.

All these functions add their result to any existing data in output.

They all call actual_accumulate_sub_Hessian_times_input_without_penalty.

References stir::GeneralisedObjectiveFunction< TargetT >::accumulate_Hessian_times_input(), stir::error(), and stir::warning().

Referenced by stir::GeneralisedObjectiveFunction< TargetT >::accumulate_Hessian_times_input().

◆ set_num_subsets()

template<typename TargetT>
virtual int stir::GeneralisedObjectiveFunction< TargetT >::set_num_subsets ( const int  num_subsets)
pure virtual

◆ subsets_are_approximately_balanced() [1/2]

template<typename TargetT >
bool stir::GeneralisedObjectiveFunction< TargetT >::subsets_are_approximately_balanced ( ) const

Checks of the current subset scheme is approximately balanced.

Balanced subsets means that the sub-gradients point all roughly in the same direction (at least when far from the optimum).

This function tests if this is approximately true, such that a reconstruction algorithm can either adapt or abort.

Implemented in terms of actual_subsets_are_approximately_balanced(std::string&).

◆ subsets_are_approximately_balanced() [2/2]

template<typename TargetT >
bool stir::GeneralisedObjectiveFunction< TargetT >::subsets_are_approximately_balanced ( std::string &  warning_message) const

Checks of the current subset scheme is approximately balanced and constructs a warning message.

See also
subsets_are_approximately_balanced()
Parameters
warning_messageA string variable. If the subsets are not (approx.) balanced, this function will append a warning message explaining why.

References stir::error().

◆ get_prior_ptr()

template<typename TargetT >
GeneralisedPrior< TargetT > *const stir::GeneralisedObjectiveFunction< TargetT >::get_prior_ptr ( ) const

Read-only access to the prior.

Todo:
It would be nicer to not return a pointer.

◆ set_prior_sptr()

template<typename TargetT >
void stir::GeneralisedObjectiveFunction< TargetT >::set_prior_sptr ( const shared_ptr< GeneralisedPrior< TargetT >> &  arg)

Change the prior.

Warning
You should call set_up() again after using this function.

◆ set_input_data()

template<typename TargetT>
virtual void stir::GeneralisedObjectiveFunction< TargetT >::set_input_data ( const shared_ptr< ExamData > &  )
pure virtual

◆ get_input_data()

template<typename TargetT>
virtual const ExamData& stir::GeneralisedObjectiveFunction< TargetT >::get_input_data ( ) const
pure virtual

◆ set_additive_proj_data_sptr()

template<typename TargetT>
virtual void stir::GeneralisedObjectiveFunction< TargetT >::set_additive_proj_data_sptr ( const shared_ptr< ExamData > &  )
pure virtual

set_additive_proj_data_sptr

Author
Nikos Efthimiou

In the case the reconstruction process is called from another piece of code, the user should be able to set any additive sinogram

Implemented in stir::PoissonLogLikelihoodWithLinearModelForMeanAndProjData< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndGatedProjDataWithMotion< TargetT >, stir::PoissonLogLikelihoodWithLinearKineticModelAndDynamicProjectionData< TargetT >, and stir::PoissonLogLikelihoodWithLinearModelForMeanAndListModeData< TargetT >.

◆ set_normalisation_sptr()

template<typename TargetT>
virtual void stir::GeneralisedObjectiveFunction< TargetT >::set_normalisation_sptr ( const shared_ptr< BinNormalisation > &  )
pure virtual

◆ set_defaults()

template<typename TargetT >
void stir::GeneralisedObjectiveFunction< TargetT >::set_defaults ( )
overrideprotectedvirtual

◆ initialise_keymap()

template<typename TargetT >
void stir::GeneralisedObjectiveFunction< TargetT >::initialise_keymap ( )
overrideprotectedvirtual

◆ actual_subsets_are_approximately_balanced()

template<typename TargetT>
virtual bool stir::GeneralisedObjectiveFunction< TargetT >::actual_subsets_are_approximately_balanced ( std::string &  warning_message) const
protectedpure virtual

◆ actual_compute_objective_function_without_penalty()

template<typename TargetT>
virtual double stir::GeneralisedObjectiveFunction< TargetT >::actual_compute_objective_function_without_penalty ( const TargetT &  current_estimate,
const int  subset_num 
)
protectedpure virtual

Implementation of function that computes the objective function for the current subset.

See also
compute_objective_function_without_penalty(const Target&,const int)
Developer\'s note

The reason we have this function is that overloading a function in a derived class, hides all functions of the same name.

Implemented in stir::PoissonLogLikelihoodWithLinearModelForMeanAndProjData< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndGatedProjDataWithMotion< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndListModeDataWithProjMatrixByBin< TargetT >, and stir::PoissonLogLikelihoodWithLinearKineticModelAndDynamicProjectionData< TargetT >.

◆ actual_add_multiplication_with_approximate_sub_Hessian_without_penalty()

template<typename TargetT >
Succeeded stir::GeneralisedObjectiveFunction< TargetT >::actual_add_multiplication_with_approximate_sub_Hessian_without_penalty ( TargetT &  output,
const TargetT &  input,
const int  subset_num 
) const
protectedvirtual

Implementation of the function that multiplies the approximate sub-Hessian with a vector.

See also
multiplication_with_approximate_sub_Hessian_without_penalty(TargetT&,const TargetT&, const int).
Warning
The default implementation just calls error(). This behaviour has to be overloaded by the derived classes.
Developer\'s note

The reason we have this function is that overloading a function in a derived class, hides all functions of the same name.

Reimplemented in stir::PoissonLogLikelihoodWithLinearModelForMeanAndProjData< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndGatedProjDataWithMotion< TargetT >, and stir::PoissonLogLikelihoodWithLinearKineticModelAndDynamicProjectionData< TargetT >.

References stir::error().

◆ actual_accumulate_sub_Hessian_times_input_without_penalty()

template<typename TargetT >
Succeeded stir::GeneralisedObjectiveFunction< TargetT >::actual_accumulate_sub_Hessian_times_input_without_penalty ( TargetT &  output,
const TargetT &  current_image_estimate,
const TargetT &  input,
const int  subset_num 
) const
protectedvirtual

Implementation of the function computes the sub-Hessian and multiplies by a vector.

See also
accumulate_sub_Hessian_times_input_without_penalty(TargetT&,const TargetT&, TargetT&, const int).
Warning
The default implementation just calls error(). This behaviour has to be overloaded by the derived classes.
Developer\'s note

The reason we have this function is that overloading a function in a derived class, hides all functions of the same name.

Reimplemented in stir::PoissonLogLikelihoodWithLinearModelForMeanAndProjData< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndGatedProjDataWithMotion< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndListModeDataWithProjMatrixByBin< TargetT >, and stir::PoissonLogLikelihoodWithLinearKineticModelAndDynamicProjectionData< TargetT >.

References stir::error().


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