STIR
6.2.0
|
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"
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 ¤t_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 ¤t_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 ¤t_estimate) |
Compute the gradient of the objective function at the current_estimate. More... | |
virtual void | compute_gradient_without_penalty (TargetT &gradient, const TargetT ¤t_estimate) |
Compute the gradient of the unregularised objective function at the current_estimate. More... | |
virtual double | compute_objective_function_without_penalty (const TargetT ¤t_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 ¤t_estimate) |
Compute the value of the unregularised objective function at the current_estimate. More... | |
double | compute_penalty (const TargetT ¤t_estimate, const int subset_num) |
Compute the value of the sub-penalty at the current_estimate. More... | |
double | compute_penalty (const TargetT ¤t_estimate) |
Compute the value of the penalty at the current_estimate. More... | |
double | compute_objective_function (const TargetT ¤t_estimate, const int subset_num) |
Compute the value of the sub-objective function at the current_estimate. More... | |
double | compute_objective_function (const TargetT ¤t_estimate) |
Compute the value of the objective function at the current_estimate. More... | |
double | compute_value (const TargetT ¤t_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 ¤t_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< ExamInfo > | get_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 ExamData & | get_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 ¤t_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 ¤t_image_estimate, const TargetT &input) const |
Succeeded | accumulate_sub_Hessian_times_input (TargetT &output, const TargetT ¤t_image_estimate, const TargetT &input, const int subset_num) const |
Succeeded | accumulate_sub_Hessian_times_input_without_penalty (TargetT &output, const TargetT ¤t_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 &) | |
ParsingObject & | operator= (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 ¤t_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 ¤t_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 ®istered_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_less > | RegistryType |
The type of the registry. | |
Static Protected Member Functions inherited from stir::RegisteredObject< GeneralisedObjectiveFunction< TargetT > > | |
static RegistryType & | registry () |
Static function returning the registry. More... | |
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.
; specify prior, see GeneralisedObjectiveFunction<TargetT> hierarchy for possible values prior type :=
|
pure virtual |
Creates a suitable target as determined by the parameters.
already_set_up
(unfortunately), as it is currently called in Reconstruction::reconstruct() before calling set_up(). Implemented in stir::PoissonLogLikelihoodWithLinearModelForMeanAndProjData< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndListModeDataWithProjMatrixByBin< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndGatedProjDataWithMotion< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndGatedProjDataWithMotion< TargetT >, and stir::PoissonLogLikelihoodWithLinearKineticModelAndDynamicProjectionData< TargetT >.
|
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
.
References stir::error().
|
pure virtual |
This should compute the subset-gradient of the unregularised objective function at current_estimate.
Implemented in stir::PoissonLogLikelihoodWithLinearModelForMean< TargetT >, and stir::SumOfGeneralisedObjectiveFunctions< PoissonLogLikelihoodWithLinearModelForMeanAndProjData< TargetT >, TargetT, PoissonLogLikelihoodWithLinearModelForMean< TargetT > >.
|
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()
.
|
virtual |
Compute the gradient of the unregularised objective function at the current_estimate.
Computed by summing subset-gradients.
|
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().
|
virtual |
Compute the value of the unregularised objective function at the current_estimate.
Computed by summing over all subsets.
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
Implemented in terms of GeneralisedPrior::compute_value.
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().
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
.
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
.
|
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.
Reimplemented in stir::PoissonLogLikelihoodWithLinearModelForMean< 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().
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().
|
pure virtual |
Attempts to change the number of subsets.
Implemented in stir::PoissonLogLikelihoodWithLinearModelForMeanAndProjData< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndGatedProjDataWithMotion< TargetT >, stir::PoissonLogLikelihoodWithLinearKineticModelAndDynamicProjectionData< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndListModeDataWithProjMatrixByBin< TargetT >, and stir::SumOfGeneralisedObjectiveFunctions< PoissonLogLikelihoodWithLinearModelForMeanAndProjData< TargetT >, TargetT, PoissonLogLikelihoodWithLinearModelForMean< 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&).
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.
warning_message | A string variable. If the subsets are not (approx.) balanced, this function will append a warning message explaining why. |
References stir::error().
GeneralisedPrior< TargetT > *const stir::GeneralisedObjectiveFunction< TargetT >::get_prior_ptr | ( | ) | const |
Read-only access to the prior.
void stir::GeneralisedObjectiveFunction< TargetT >::set_prior_sptr | ( | const shared_ptr< GeneralisedPrior< TargetT >> & | arg | ) |
Change the prior.
|
pure virtual |
set_input_data
It can be used to set the data to be reconstructed within some other code, as opposed to via parsing.
Implemented in stir::PoissonLogLikelihoodWithLinearModelForMeanAndProjData< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndGatedProjDataWithMotion< TargetT >, stir::PoissonLogLikelihoodWithLinearKineticModelAndDynamicProjectionData< TargetT >, and stir::PoissonLogLikelihoodWithLinearModelForMeanAndListModeData< TargetT >.
|
pure virtual |
get input data
Will throw an exception if it wasn't set first
Implemented in stir::PoissonLogLikelihoodWithLinearModelForMeanAndProjData< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndGatedProjDataWithMotion< TargetT >, stir::PoissonLogLikelihoodWithLinearKineticModelAndDynamicProjectionData< TargetT >, and stir::PoissonLogLikelihoodWithLinearModelForMeanAndListModeData< TargetT >.
|
pure virtual |
set_additive_proj_data_sptr
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 >.
|
pure virtual |
set_normalisation_sptr
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 >.
|
overrideprotectedvirtual |
sets any default values
Has to be called by set_defaults in the leaf-class
Reimplemented from stir::ParsingObject.
Reimplemented in stir::PoissonLogLikelihoodWithLinearModelForMeanAndProjData< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMean< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndGatedProjDataWithMotion< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndListModeData< TargetT >, stir::PoissonLogLikelihoodWithLinearKineticModelAndDynamicProjectionData< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndDynamicProjData< TargetT >, and stir::PoissonLogLikelihoodWithLinearModelForMeanAndListModeDataWithProjMatrixByBin< TargetT >.
|
overrideprotectedvirtual |
sets parsing keys
Has to be called by initialise_keymap in the leaf-class
Reimplemented from stir::ParsingObject.
Reimplemented in stir::PoissonLogLikelihoodWithLinearModelForMeanAndProjData< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMean< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndGatedProjDataWithMotion< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndListModeData< TargetT >, stir::PoissonLogLikelihoodWithLinearKineticModelAndDynamicProjectionData< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndDynamicProjData< TargetT >, and stir::PoissonLogLikelihoodWithLinearModelForMeanAndListModeDataWithProjMatrixByBin< TargetT >.
|
protectedpure virtual |
Implementation of function that checks subset balancing.
The reason we have this function is that overloading subsets_are_approximately_balanced(std::string&) in a derived class would hide subsets_are_approximately_balanced().
Implemented in stir::PoissonLogLikelihoodWithLinearModelForMeanAndProjData< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndGatedProjDataWithMotion< TargetT >, stir::PoissonLogLikelihoodWithLinearKineticModelAndDynamicProjectionData< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndListModeDataWithProjMatrixByBin< TargetT >, stir::PoissonLogLikelihoodWithLinearModelForMeanAndDynamicProjData< TargetT >, and stir::SumOfGeneralisedObjectiveFunctions< PoissonLogLikelihoodWithLinearModelForMeanAndProjData< TargetT >, TargetT, PoissonLogLikelihoodWithLinearModelForMean< TargetT > >.
|
protectedpure virtual |
Implementation of function that computes the objective function for the current subset.
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 >.
|
protectedvirtual |
Implementation of the function that multiplies the approximate sub-Hessian with a vector.
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().
|
protectedvirtual |
Implementation of the function computes the sub-Hessian and multiplies by a vector.
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().