STIR  6.2.0
PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2011-02-23, Hammersmith Imanet Ltd
3  Copyright (C) 2018, 2022, University College London
4  This file is part of STIR.
5 
6  SPDX-License-Identifier: Apache-2.0
7 
8  See STIR/LICENSE.txt for details
9 */
20 #ifndef __stir_recon_buildblock_PoissonLogLikelihoodWithLinearModelForMeanAndProjData_H__
21 #define __stir_recon_buildblock_PoissonLogLikelihoodWithLinearModelForMeanAndProjData_H__
22 
26 //#include "stir/ProjData.h"
28 //#include "stir/recon_buildblock/BinNormalisation.h"
30 #ifdef STIR_MPI
31 # include "stir/recon_buildblock/distributable.h" // for RPC_process_related_viewgrams_type
32 #endif
33 
34 START_NAMESPACE_STIR
35 
36 class DistributedCachingInformation;
37 
38 //#ifdef STIR_MPI_CLASS_DEFINITION
39 //#define PoissonLogLikelihoodWithLinearModelForMeanAndProjData PoissonLogLikelihoodWithLinearModelForMeanAndProjData_MPI
40 //#endif
41 
120 template <typename TargetT>
122  : public RegisteredParsingObject<PoissonLogLikelihoodWithLinearModelForMeanAndProjData<TargetT>,
123  GeneralisedObjectiveFunction<TargetT>,
124  PoissonLogLikelihoodWithLinearModelForMean<TargetT>>
125 {
126 private:
130  base_type;
131 
132 public:
134  static const char* const registered_name;
135 
136  //
143  DistributedCachingInformation* caching_info_ptr;
145  //#ifdef STIR_MPI
148  bool distributed_tests_enabled;
149  bool message_timings_enabled;
150  double message_timings_threshold;
151  bool rpc_timings_enabled;
152  //#endif
154 
157 
159 
162 
164 
167  TargetT* construct_target_ptr() const override;
168 
174  const ProjData& get_proj_data() const;
175  const shared_ptr<ProjData>& get_proj_data_sptr() const;
176  const int get_max_segment_num_to_process() const;
177  const int get_max_timing_pos_num_to_process() const;
178  const bool get_zero_seg0_end_planes() const;
179  const ProjData& get_additive_proj_data() const;
180  const shared_ptr<ProjData>& get_additive_proj_data_sptr() const;
181  const ProjectorByBinPair& get_projector_pair() const;
182  const shared_ptr<ProjectorByBinPair>& get_projector_pair_sptr() const;
183  const int get_time_frame_num() const;
184  const TimeFrameDefinitions& get_time_frame_definitions() const;
185  const BinNormalisation& get_normalisation() const;
186  const shared_ptr<BinNormalisation>& get_normalisation_sptr() const;
188 
196  int set_num_subsets(const int num_subsets) override;
197  void set_proj_data_sptr(const shared_ptr<ProjData>&);
198  void set_max_segment_num_to_process(const int);
199  void set_max_timing_pos_num_to_process(const int);
200  void set_zero_seg0_end_planes(const bool);
201  // N.E. Changed to ExamData
202  void set_additive_proj_data_sptr(const shared_ptr<ExamData>&) override;
203  void set_projector_pair_sptr(const shared_ptr<ProjectorByBinPair>&);
204  void set_frame_num(const int);
205  void set_frame_definitions(const TimeFrameDefinitions&);
206  void set_normalisation_sptr(const shared_ptr<BinNormalisation>&) override;
207 
208  void set_input_data(const shared_ptr<ExamData>&) override;
209  const ProjData& get_input_data() const override;
211 
212  void actual_compute_subset_gradient_without_penalty(TargetT& gradient,
213  const TargetT& current_estimate,
214  const int subset_num,
215  const bool add_sensitivity) override;
216 
217  std::unique_ptr<ExamInfo> get_exam_info_uptr_for_target() const override;
218 #if 0
219  // currently not used
220  float sum_projection_data() const;
221 #endif
222  void add_subset_sensitivity(TargetT& sensitivity, const int subset_num) const override;
223 
224 protected:
225  Succeeded set_up_before_sensitivity(shared_ptr<const TargetT> const& target_sptr) override;
226 
227  double actual_compute_objective_function_without_penalty(const TargetT& current_estimate, const int subset_num) override;
228 
262  Succeeded actual_add_multiplication_with_approximate_sub_Hessian_without_penalty(TargetT& output,
263  const TargetT& input,
264  const int subset_num) const override;
265 
283  Succeeded actual_accumulate_sub_Hessian_times_input_without_penalty(TargetT& output,
284  const TargetT& current_image_estimate,
285  const TargetT& input,
286  const int subset_num) const override;
287 
288 protected:
290  std::string input_filename;
291 
293  shared_ptr<ProjData> proj_data_sptr;
294 
296 
298 
300 
302 
303  /**********************/
304  ParseAndCreateFrom<TargetT, ProjData> target_parameter_parser;
305  /********************************/
306 
308  shared_ptr<ProjectorByBinPair> projector_pair_ptr;
309 
312 
315 
318 
319  shared_ptr<ProjData> additive_proj_data_sptr;
320 
321  shared_ptr<BinNormalisation> normalisation_sptr;
322 
323  // TODO doc
324  int frame_num;
325  std::string frame_definition_filename;
326  TimeFrameDefinitions frame_defs;
327 
328  // Loglikelihood computation parameters
329  // TODO rename and move higher up in the hierarchy
332 
335 
338 
340 
341  void set_defaults() override;
343 
344  void initialise_keymap() override;
346 
347  bool post_processing() override;
348 
350 
355  bool actual_subsets_are_approximately_balanced(std::string& warning_message) const override;
356 
357 private:
358  shared_ptr<DataSymmetriesForViewSegmentNumbers> symmetries_sptr;
359 
367  shared_ptr<BackProjectorByBin> sens_backprojector_sptr;
370 
371  shared_ptr<DataSymmetriesForViewSegmentNumbers> sens_symmetries_sptr;
373  mutable bool latest_setup_distributable_computation_was_with_orig_projectors;
375  mutable bool distributable_computation_already_setup;
377 
378  bool sensitivity_uses_same_projector() const;
380 
381  shared_ptr<const ProjDataInfo> sens_proj_data_info_sptr;
383  mutable bool latest_setup_norm_was_with_orig_data;
385  mutable bool norm_already_setup = false;
386 
388  void ensure_norm_is_set_up(bool for_original_data = true) const;
390  void ensure_norm_is_set_up_for_sensitivity() const;
392 #if 0
393  void
394  add_view_seg_to_sensitivity(TargetT& sensitivity, const ViewSegmentNumbers& view_seg_nums) const;
395 #endif
396 };
397 
398 #ifdef STIR_MPI
399 // made available to be called from DistributedWorker object
400 RPC_process_related_viewgrams_type RPC_process_related_viewgrams_gradient;
401 RPC_process_related_viewgrams_type RPC_process_related_viewgrams_accumulate_loglikelihood;
402 RPC_process_related_viewgrams_type RPC_process_related_viewgrams_sensitivity_computation;
403 #endif
404 
405 END_NAMESPACE_STIR
406 
407 //#include "stir/recon_buildblock/PoissonLogLikelihoodWithLinearModelForMean.inl"
408 
409 #endif
shared_ptr< ProjData > proj_data_sptr
points to the object for the total input projection data
Definition: PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h:293
Class used for storing time frame durations.
Definition: TimeFrameDefinitions.h:38
bool compute_total_loglikelihood
indicates whether to evaluate the loglikelihood function for all bins or the current subset ...
Definition: PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h:334
Definition of the stir::ParseAndCreateFrom class.
Declaration of class stir::TimeFrameDefinitions.
void RPC_process_related_viewgrams_type(const shared_ptr< ForwardProjectorByBin > &forward_projector_sptr, const shared_ptr< BackProjectorByBin > &back_projector_sptr, RelatedViewgrams< float > *measured_viewgrams_ptr, int &count, int &count2, double *log_likelihood_ptr, const RelatedViewgrams< float > *additive_binwise_correction_ptr, const RelatedViewgrams< float > *mult_viewgrams_ptr)
typedef for callback functions for distributable_computation()
Definition: distributable.h:93
This class implements the logic needed to support caching in a distributed manner.
Definition: DistributedCachingInformation.h:62
bool zero_seg0_end_planes
signals whether to zero the data in the end planes of the projection data
Definition: PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h:311
A base class for &#39;generalised&#39; objective functions, i.e. objective functions for which at least a &#39;gr...
Definition: GeneralisedObjectiveFunction.h:83
Declaration of the main functions that perform parallel processing.
Abstract base class for all projector pairs.
Definition: ProjectorByBinPair.h:44
std::string additive_projection_data_filename
name of file in which additive projection data are stored
Definition: PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h:317
template for adding keywords to a parser and creating an object
Definition: ParseAndCreateFrom.h:52
int max_timing_pos_num_to_process
the maximum absolute time-of-flight bin number to use in the reconstruction
Definition: PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h:301
shared_ptr< ProjectorByBinPair > projector_pair_ptr
Stores the projectors that are used for the computations.
Definition: PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h:308
bool distributed_cache_enabled
enable/disable key for distributed caching
Definition: PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h:147
static const char *const registered_name
Name which will be used when parsing a GeneralisedObjectiveFunction object.
Definition: PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h:134
Abstract base class for implementing bin-wise normalisation of data.
Definition: BinNormalisation.h:51
int loglikelihood_computation_interval
subiteration interval at which the loglikelihood function is evaluated
Definition: PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h:331
alias for ViewgramIndices
Definition: ViewSegmentNumbers.h:33
Declaration of class stir::PoissonLogLikelihoodWithLinearModelForMean.
int max_segment_num_to_process
the maximum absolute ring difference number to use in the reconstruction
Definition: PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h:297
Parent class for all leaves in a RegisteredObject hierarchy that do parsing of parameter files...
Definition: RegisteredParsingObject.h:77
std::string input_filename
Filename with input projection data.
Definition: PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h:290
bool use_tofsens
Triggers calculation of sensitivity using time-of-flight.
Definition: PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h:314
a base class for LogLikelihood of independent Poisson variables where the mean values are linear comb...
Definition: KOSMAPOSLReconstruction.h:39
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition: Succeeded.h:43
Declaration of class stir::RegisteredParsingObject.
An objective function class appropriate for PET emission data.
Definition: PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h:121
The (abstract) base class for the projection data.
Definition: ProjData.h:103
std::string loglikelihood_data_filename
name of file in which loglikelihood measurements are stored
Definition: PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h:337
Declares class stir::ProjectorByBinPair.