CASToR  1.1
Tomographic Reconstruction (PET/SPECT)
 All Classes Files Functions Variables Typedefs Macros Groups Pages
iOptimizerLandweber.cc
Go to the documentation of this file.
1 
2 /*
3  Implementation of class iOptimizerLandweber
4 
5  - separators: X
6  - doxygen: X
7  - default initialization: X
8  - CASTOR_DEBUG:
9  - CASTOR_VERBOSE:
10 */
11 
18 #include "iOptimizerLandweber.hh"
19 #include "sOutputManager.hh"
20 
21 // =====================================================================
22 // ---------------------------------------------------------------------
23 // ---------------------------------------------------------------------
24 // =====================================================================
25 
27 {
28  // ---------------------------
29  // Mandatory member parameters
30  // ---------------------------
31 
32  // Initial value at 0
33  m_initialValue = 0.;
34  // Only one backward image for Landweber
36  // Landweber does not accept penalties
37  //m_penaltyEnergyFunctionDerivativesOrder = 0;
38  // Landweber is not compatible with listmode data
40  // Landweber is compatible with histogram data only
42 
43  // --------------------------
44  // Specific member parameters
45  // --------------------------
46 
47  m_relaxationFactor = -1.;
48 }
49 
50 // =====================================================================
51 // ---------------------------------------------------------------------
52 // ---------------------------------------------------------------------
53 // =====================================================================
54 
56 {
57 }
58 
59 // =====================================================================
60 // ---------------------------------------------------------------------
61 // ---------------------------------------------------------------------
62 // =====================================================================
63 
65 {
66  cout << "This optimizer implements the standard Landweber algorithm for least-squares optimization." << endl;
67  cout << "No penalty can be used with this algorithm." << endl;
68  cout << "Be aware that the relaxation parameter is not automatically set, so it often requires some" << endl;
69  cout << "trials and errors to find an optimal setting. Also, remember that this algorithm is particularly" << endl;
70  cout << "slow to converge." << endl;
71  cout << "The following options can be used (in this particular order when provided as a list):" << endl;
72  cout << " initial image value: to set the uniform voxel value for the initial image" << endl;
73  cout << " relaxation factor: to set the relaxation factor applied to the update" << endl;
74 }
75 
76 // =====================================================================
77 // ---------------------------------------------------------------------
78 // ---------------------------------------------------------------------
79 // =====================================================================
80 
81 int iOptimizerLandweber::ReadConfigurationFile(const string& a_configurationFile)
82 {
83  string key_word = "";
84  // Read the initial image value option
85  key_word = "initial image value";
86  if (ReadDataASCIIFile(a_configurationFile, key_word, &m_initialValue, 1, KEYWORD_MANDATORY))
87  {
88  Cerr("***** iOptimizerLandweber::ReadAndCheckConfigurationFile() -> Failed to get the '" << key_word << "' keyword !" << endl);
89  return 1;
90  }
91  // Read the relaxation factor option
92  key_word = "relaxation factor";
93  if (ReadDataASCIIFile(a_configurationFile, key_word, &m_relaxationFactor, 1, KEYWORD_MANDATORY))
94  {
95  Cerr("***** iOptimizerLandweber::ReadAndCheckConfigurationFile() -> Failed to get the '" << key_word << "' keyword !" << endl);
96  return 1;
97  }
98  // Normal end
99  return 0;
100 }
101 
102 // =====================================================================
103 // ---------------------------------------------------------------------
104 // ---------------------------------------------------------------------
105 // =====================================================================
106 
107 int iOptimizerLandweber::ReadOptionsList(const string& a_optionsList)
108 {
109  // There are 2 floating point variables as options
110  FLTNB options[4];
111 
112  // Read them
113  if (ReadStringOption(a_optionsList, options, 2, ",", "Landweber configuration"))
114  {
115  Cerr("***** iOptimizerLandweber::ReadAndCheckConfigurationFile() -> Failed to correctly read the list of options !" << endl);
116  return 1;
117  }
118  // Affect options
119  m_initialValue = options[0];
120  m_relaxationFactor = options[1];
121 
122  // Normal end
123  return 0;
124 }
125 
126 // =====================================================================
127 // ---------------------------------------------------------------------
128 // ---------------------------------------------------------------------
129 // =====================================================================
130 
132 {
133  // Check that relaxation factor value is strictly positive
134  if (m_relaxationFactor<=0.)
135  {
136  Cerr("***** iOptimizerLandweber->Initialize() -> Provided relaxation factor (" << m_relaxationFactor << ") must be strictly positive !" << endl);
137  return 1;
138  }
139  // Normal end
140  return 0;
141 }
142 
143 // =====================================================================
144 // ---------------------------------------------------------------------
145 // ---------------------------------------------------------------------
146 // =====================================================================
147 
149 {
150  // Verbose
151  if (m_verbose>=2)
152  {
153  Cout("iOptimizerLandweber::Initialize() -> Use the Landweber algorithm" << endl);
154  if (m_verbose>=3)
155  {
156  Cout(" --> Initial image value: " << m_initialValue << endl);
157  Cout(" --> Relaxation factor: " << m_relaxationFactor << endl);
158  }
159  }
160  // Normal end
161  return 0;
162 }
163 
164 // =====================================================================
165 // ---------------------------------------------------------------------
166 // ---------------------------------------------------------------------
167 // =====================================================================
168 
169 int iOptimizerLandweber::SensitivitySpecificOperations( FLTNB a_data, FLTNB a_forwardModel, FLTNB* ap_weight,
170  FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections,
171  FLTNB a_quantificationFactor, oProjectionLine* ap_Line )
172 {
173  // Line weight here is simply 1
174  *ap_weight = 1.;
175  // That's all
176  return 0;
177 }
178 
179 // =====================================================================
180 // ---------------------------------------------------------------------
181 // ---------------------------------------------------------------------
182 // =====================================================================
183 
184 int iOptimizerLandweber::DataSpaceSpecificOperations( FLTNB a_data, FLTNB a_forwardModel, FLTNB* ap_backwardValues,
185  FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections,
186  FLTNB a_quantificationFactor, oProjectionLine* ap_Line )
187 {
188  // Simply subtract the model from the data
189  *ap_backwardValues = (a_data - a_forwardModel);
190  // That's all
191  return 0;
192 }
193 
194 // =====================================================================
195 // ---------------------------------------------------------------------
196 // ---------------------------------------------------------------------
197 // =====================================================================
198 
199 int iOptimizerLandweber::ImageSpaceSpecificOperations( FLTNB a_currentImageValue, FLTNB* ap_newImageValue,
200  FLTNB a_sensitivity, FLTNB* ap_correctionValues )
201 {
202  // Compute image update factor
203  FLTNB image_update_factor = *ap_correctionValues * m_relaxationFactor / a_sensitivity;
204  // Update image
205  *ap_newImageValue = a_currentImageValue + image_update_factor;
206  // End
207  return 0;
208 }
209 
210 // =====================================================================
211 // ---------------------------------------------------------------------
212 // ---------------------------------------------------------------------
213 // =====================================================================
int ReadOptionsList(const string &a_optionsList)
A function used to read options from a list of options.
void ShowHelpSpecific()
A function used to show help about the child optimizer.
#define FLTNB
Definition: gVariables.hh:55
FLTNB m_initialValue
Definition: vOptimizer.hh:587
bool m_listmodeCompatibility
Definition: vOptimizer.hh:588
int DataSpaceSpecificOperations(FLTNB a_data, FLTNB a_forwardModel, FLTNB *ap_backwardValues, FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections, FLTNB a_quantificationFactor, oProjectionLine *ap_Line)
This function performs the data space operations specific to the optimizer (computes the values to be...
int ReadConfigurationFile(const string &a_configurationFile)
A function used to read options from a configuration file.
~iOptimizerLandweber()
The destructor of iOptimizerLandweber.
int ImageSpaceSpecificOperations(FLTNB a_currentImageValue, FLTNB *ap_newImageValue, FLTNB a_sensitivity, FLTNB *ap_correctionValues)
This function perform the image update step specific to the optimizer.
int InitializeSpecific()
This function is used to initialize specific stuff to the child optimizer.
#define Cerr(MESSAGE)
int SensitivitySpecificOperations(FLTNB a_data, FLTNB a_forwardModel, FLTNB *ap_weight, FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections, FLTNB a_quantificationFactor, oProjectionLine *ap_Line)
This function compute the weight associated to the provided event (for sensitivity computation) ...
int CheckSpecificParameters()
A private function used to check the parameters settings specific to the child optimizer.
int m_nbBackwardImages
Definition: vOptimizer.hh:583
int ReadDataASCIIFile(const string &a_file, const string &a_keyword, T *ap_return, int a_nbElts, bool a_mandatoryFlag)
Look for "a_nbElts" elts in the "a_file" file matching the "a_keyword" string passed as parameter a...
Definition: gOptions.cc:111
bool m_histogramCompatibility
Definition: vOptimizer.hh:589
#define KEYWORD_MANDATORY
Definition: gOptions.hh:25
Declaration of class iOptimizerLandweber.
This class is designed to generically described any iterative optimizer.
Definition: vOptimizer.hh:36
This class is designed to manage and store system matrix elements associated to a vEvent...
iOptimizerLandweber()
The constructor of iOptimizerLandweber.
Declaration of class sOutputManager.
#define Cout(MESSAGE)
int ReadStringOption(const string &a_input, T *ap_return, int a_nbElts, const string &sep, const string &a_option)
Parse the 'a_input' string corresponding to the 'a_option' into 'a_nbElts' elements, using the 'sep' separator. The results are returned in the templated 'ap_return' dynamic templated array. Call "ConvertFromString()" to perform the correct conversion depending on the type of the data to convert.
Definition: gOptions.cc:50