-
Notifications
You must be signed in to change notification settings - Fork 111
MLEstimateComponentBasedNormalisation refactor #1499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 27 commits
3035db8
bc58f39
0dca08e
9fed40f
2579f81
5d89071
86f6a82
880e530
dd711b1
2bcdc80
0fa8455
90ea81b
f0c788b
e5e2cc7
8adb620
9ff77fe
5c1a0f7
a114d14
b0e05c9
1d6ca9b
0aae32e
ca1140c
2935b99
3c11502
7c18bc7
42340f2
f424ca8
a5f4b91
1eefeff
dcee251
63f8560
3d7e9ff
55e5f1a
55897ee
cbe81ec
fd194fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -34,7 +34,7 @@ START_NAMESPACE_STIR | |||||
| Components currently supported are crystal efficiencies, geometric factors | ||||||
| (constrained by symmetry) and block data. The latter were introduced to | ||||||
| cope with timing alignment issues between blocks, but are generally | ||||||
| not recommended in the current estimation process (by ML_estimate_component_based_normalisation) | ||||||
| not recommended in the current estimation process (by MLEstimateComponentBasedNormalisation) | ||||||
| as the model allows for too much freedom. | ||||||
|
|
||||||
| The detection efficiency of a crystal pair is modelled as | ||||||
|
|
@@ -126,15 +126,33 @@ class BinNormalisationPETFromComponents : public BinNormalisation | |||||
| void | ||||||
| allocate(shared_ptr<const ProjDataInfo>, bool do_eff, bool do_geo, bool do_block = false, bool do_symmetry_per_block = false); | ||||||
|
|
||||||
| DetectorEfficiencies& crystal_efficiencies() | ||||||
|
|
||||||
| void set_crystal_efficiencies(const DetectorEfficiencies& eff) | ||||||
| { | ||||||
| efficiencies = eff; | ||||||
| } | ||||||
|
|
||||||
| DetectorEfficiencies& get_crystal_efficiencies() | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok for changing to
Suggested change
or would this break something? However, cannot change backwards compatibility in a minor version update, so keep #if STIR_VERSION < 070000
STIR_DEPRECATED DetectorEfficiencies& crystal_efficiencies()
...
#endif
Obviously the same for the others. |
||||||
| { | ||||||
| return efficiencies; | ||||||
| } | ||||||
| GeoData3D& geometric_factors() | ||||||
|
|
||||||
| void set_geometric_factors(const GeoData3D& geo) | ||||||
| { | ||||||
| geo_data = geo; | ||||||
| } | ||||||
|
|
||||||
| GeoData3D& get_geometric_factors() | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also |
||||||
| { | ||||||
| return geo_data; | ||||||
| } | ||||||
| BlockData3D& block_factors() | ||||||
|
|
||||||
| void set_block_factors(const BlockData3D& block) | ||||||
| { | ||||||
| block_data = block; | ||||||
| } | ||||||
|
|
||||||
| BlockData3D& get_block_factors() | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also |
||||||
| { | ||||||
| return block_data; | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,200 @@ | ||||||||||
| /* | ||||||||||
| Copyright (C) 2022, University College London | ||||||||||
| Copyright (C) 2024, Robert Twyman Skelly | ||||||||||
| This file is part of STIR. | ||||||||||
|
|
||||||||||
| SPDX-License-Identifier: Apache-2.0 | ||||||||||
|
|
||||||||||
| See STIR/LICENSE.txt for details | ||||||||||
| */ | ||||||||||
| /*! | ||||||||||
| \file | ||||||||||
| \ingroup recon_buildblock | ||||||||||
| \brief Declaration of stir::ML_estimate_component_based_normalisation | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. obviously, need to adjust when keeping |
||||||||||
| \author Kris Thielemans | ||||||||||
| \author Robert Twyman Skelly | ||||||||||
| */ | ||||||||||
| #include "BinNormalisationPETFromComponents.h" | ||||||||||
| #include "stir/common.h" | ||||||||||
| #include <string> | ||||||||||
| #include "stir/ProjData.h" | ||||||||||
| #include "stir/ML_norm.h" | ||||||||||
| #include "stir/ProjDataInMemory.h" | ||||||||||
|
|
||||||||||
| START_NAMESPACE_STIR | ||||||||||
|
|
||||||||||
| /*! | ||||||||||
| \brief Find normalisation factors using a maximum likelihood approach | ||||||||||
| \ingroup recon_buildblock | ||||||||||
| \param out_filename_prefix The prefix for the output files | ||||||||||
| \param measured_data The measured projection data | ||||||||||
| \param model_data The model projection data | ||||||||||
| \param num_eff_iterations The number of (sub-)efficiency iterations to perform per iteration of the algorithm | ||||||||||
| \param num_iterations The number of algorithm iterations to perform | ||||||||||
| \param do_geo Whether to perform geo normalization calculations | ||||||||||
| \param do_block Whether to perform block normalization calculations | ||||||||||
| \param do_symmetry_per_block Whether to perform block normalization calculations with symmetry | ||||||||||
| \param do_KL Whether to perform Kullback-Leibler divergence calculations and display the KL value. This can be slow. | ||||||||||
| \param do_display Whether to display the progress of the algorithm. | ||||||||||
| \param do_save_to_file Whether to save the each iteration of the efficiencies, geo data and block data to file. | ||||||||||
| */ | ||||||||||
| void ML_estimate_component_based_normalisation(const std::string& out_filename_prefix, | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function was in a different file. It needs to remain there for backwards compatibility. However, it could be deprecated there. |
||||||||||
| const ProjData& measured_projdata, | ||||||||||
| const ProjData& model_projdata, | ||||||||||
| int num_eff_iterations, | ||||||||||
| int num_iterations, | ||||||||||
| bool do_geo, | ||||||||||
| bool do_block, | ||||||||||
| bool do_symmetry_per_block, | ||||||||||
| bool do_KL, | ||||||||||
| bool do_display, | ||||||||||
| bool do_save_to_file = true); | ||||||||||
|
|
||||||||||
| /*! | ||||||||||
| \brief Find normalisation factors using a maximum likelihood approach | ||||||||||
| \ingroup recon_buildblock | ||||||||||
| */ | ||||||||||
| class MLEstimateComponentBasedNormalisation | ||||||||||
| { | ||||||||||
| public: | ||||||||||
| /*! | ||||||||||
| \brief Constructor | ||||||||||
| \param out_filename_prefix_v The prefix for the output files | ||||||||||
| \param measured_projdata_v The measured projection data | ||||||||||
| \param model_projdata_v The model projection data | ||||||||||
| \param num_eff_iterations_v The number of (sub-)efficiency iterations to perform per iteration of the algorithm | ||||||||||
| \param num_iterations_v The number of algorithm iterations to perform | ||||||||||
| \param do_geo_v Whether to perform geo normalization calculations | ||||||||||
| \param do_block_v Whether to perform block normalization calculations | ||||||||||
| \param do_symmetry_per_block_v Whether to perform block normalization calculations with symmetry | ||||||||||
| \param do_KL_v Whether to perform Kullback-Leibler divergence calculations and display the KL value. This can be slow. | ||||||||||
| \param do_display_v Whether to display the progress of the algorithm. | ||||||||||
| \param do_save_to_file_v Whether to save the each iteration of the efficiencies, geo data and block data to file. | ||||||||||
|
Comment on lines
+65
to
+72
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not so sure that having all these as part of the constructor is useful. It creates quite some dependency on order, which is unsafe in C++ (no named arguments). I'd remove them. Also |
||||||||||
| */ | ||||||||||
| MLEstimateComponentBasedNormalisation(std::string out_filename_prefix_v, | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. generally STIR uses |
||||||||||
| const ProjData& measured_projdata_v, | ||||||||||
| const ProjData& model_projdata_v, | ||||||||||
| int num_eff_iterations_v, | ||||||||||
| int num_iterations_v, | ||||||||||
| bool do_geo_v, | ||||||||||
| bool do_block_v, | ||||||||||
| bool do_symmetry_per_block_v, | ||||||||||
| bool do_KL_v, | ||||||||||
| bool do_display_v, | ||||||||||
| bool do_save_to_file_v); | ||||||||||
|
|
||||||||||
| /*! | ||||||||||
| \brief Run the normalisation estimation algorithm using the parameters provided in the constructor. | ||||||||||
| */ | ||||||||||
| void process(); | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Many STIR classes have Also, we need a |
||||||||||
|
|
||||||||||
| //! Check if the data has been processed | ||||||||||
| bool has_processed_data() const; | ||||||||||
|
robbietuk marked this conversation as resolved.
Outdated
|
||||||||||
|
|
||||||||||
| //! Get the efficiencies, requires process() to be called first | ||||||||||
| DetectorEfficiencies get_efficiencies() const; | ||||||||||
| //! Get the geo data, requires process() to be called first and do_geo to be true | ||||||||||
| GeoData3D get_geo_data() const; | ||||||||||
| //! Get the block data, requires process() to be called first and do_block to be true | ||||||||||
| BlockData3D get_block_data() const; | ||||||||||
|
Comment on lines
+95
to
+99
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be fairly large arrays. return |
||||||||||
|
|
||||||||||
| //! Construct a BinNormalisationPETFromComponents from the calculated efficiencies, geo data and block data | ||||||||||
| BinNormalisationPETFromComponents construct_bin_normfactors_from_components() const; | ||||||||||
|
|
||||||||||
| private: | ||||||||||
| /*! | ||||||||||
| \brief Performs an efficiency iteration to update the efficiancies from the data_fan_sums and model. | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| Additionally, handles the saving of the efficiencies iteration to file, KL calculation and display. | ||||||||||
| \param[in] iter_num The iteration number | ||||||||||
| \param[in] eff_iter_num The efficiency iteration number | ||||||||||
|
Comment on lines
+222
to
+223
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| */ | ||||||||||
| void efficiency_iteration(int iter_num, int eff_iter_num); | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the naming would be slightly less confusion when we'd call this |
||||||||||
|
|
||||||||||
| /*! | ||||||||||
| \brief Performs a geo normalization iteration to update the geo data from the measured_geo_data and model_data. | ||||||||||
| Additionally, handles the saving of the geo data iteration to file, KL calculation and display. | ||||||||||
| \param[in] iter_num The iteration number | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| */ | ||||||||||
| void geo_normalization_iteration(int iter_num); | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| /*! | ||||||||||
| \brief Performs a block normalization iteration to update the block data from the measured_block_data and model_data. | ||||||||||
| Additionally, handles the saving of the block data iteration to file, KL calculation and display. | ||||||||||
| * @param iter_num The iteration number | ||||||||||
| */ | ||||||||||
| void block_normalization_iteration(int iter_num); | ||||||||||
|
|
||||||||||
| /*! | ||||||||||
| \brief Write the efficiencies to a file (regardless of the value of do_save_to_file) | ||||||||||
| \param[in] iter_num The iteration number | ||||||||||
| \param[in] eff_iter_num The efficiency iteration number | ||||||||||
| */ | ||||||||||
| void write_efficiencies_to_file(int iter_num, int eff_iter_num) const; | ||||||||||
|
|
||||||||||
| /*! | ||||||||||
| \brief Write the efficiencies to a file (regardless of the value of do_save_to_file) | ||||||||||
| \param[in] iter_num The iteration number | ||||||||||
| */ | ||||||||||
| void write_geo_data_to_file(int iter_num) const; | ||||||||||
|
|
||||||||||
| /*! | ||||||||||
| \brief Write the efficiencies to a file (regardless of the value of do_save_to_file) | ||||||||||
| \param[in] iter_num The iteration number | ||||||||||
| */ | ||||||||||
| void write_block_data_to_file(int iter_num) const; | ||||||||||
|
|
||||||||||
| /*! | ||||||||||
| \brief Computes the threshold for the Kullback-Leibler divergence calculation. This is a purely heuristic value. | ||||||||||
| \return The threshold value | ||||||||||
| */ | ||||||||||
| float compute_threshold_for_KL(); | ||||||||||
|
|
||||||||||
| // Constructor parameters | ||||||||||
| //! The prefix for the output files | ||||||||||
| std::string out_filename_prefix; | ||||||||||
| //! The number of (sub-)efficiency iterations to perform per iteration of the algorithm | ||||||||||
| int num_eff_iterations; | ||||||||||
| //! The number of algorithm iterations to perform | ||||||||||
| int num_iterations; | ||||||||||
| //! Whether to perform geo normalization calculations | ||||||||||
| bool do_geo; | ||||||||||
| //! Whether to perform block normalization calculations | ||||||||||
| bool do_block; | ||||||||||
| //! Whether to perform block normalization calculations with symmetry | ||||||||||
| bool do_symmetry_per_block; | ||||||||||
| //! Whether to perform Kullback-Leibler divergence calculations and display the KL value. This can be slow. | ||||||||||
| bool do_KL; | ||||||||||
| //! Whether to display the progress of the algorithm. | ||||||||||
| bool do_display; | ||||||||||
| //! Whether to save the each iteration of the efficiencies, geo data and block data to file. | ||||||||||
| bool do_save_to_file; | ||||||||||
|
|
||||||||||
| //! The projdata info of the measured data | ||||||||||
| std::shared_ptr<const ProjDataInfo> projdata_info; | ||||||||||
|
|
||||||||||
| // Calculated variables | ||||||||||
| //! The efficiencies calculated by the algorithm | ||||||||||
| DetectorEfficiencies norm_efficiencies; | ||||||||||
| //! The geo data calculated by the algorithm, if do_geo is true | ||||||||||
| BlockData3D norm_block_data; | ||||||||||
| //! The block data calculated by the algorithm, if do_block is true | ||||||||||
| GeoData3D norm_geo_data; | ||||||||||
|
|
||||||||||
| //! The threshold for the Kullback-Leibler divergence calculation | ||||||||||
| float threshold_for_KL; | ||||||||||
| FanProjData model_fan_data; | ||||||||||
| FanProjData fan_data; | ||||||||||
| DetectorEfficiencies data_fan_sums; | ||||||||||
| BlockData3D measured_block_data; | ||||||||||
| GeoData3D measured_geo_data; | ||||||||||
|
|
||||||||||
| bool data_processed = false; | ||||||||||
|
robbietuk marked this conversation as resolved.
|
||||||||||
|
|
||||||||||
| // do_KL specific varaibles | ||||||||||
| FanProjData measured_fan_data; | ||||||||||
| DetectorEfficiencies fan_sums; | ||||||||||
| GeoData3D geo_data; | ||||||||||
| BlockData3D block_data; | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| END_NAMESPACE_STIR | ||||||||||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.