STIR 6.4.0
LogcoshPrior.h
Go to the documentation of this file.
1//
2//
3/*
4 Copyright (C) 2000- 2011, Hammersmith Imanet Ltd
5 Copyright (C) 2016, 2020, UCL
6 This file is part of STIR.
7
8 SPDX-License-Identifier: Apache-2.0
9
10 See STIR/LICENSE.txt for details.
11 */
23
24#ifndef __stir_recon_buildblock_LogcoshPrior_H__
25#define __stir_recon_buildblock_LogcoshPrior_H__
26
29#include "stir/Array.h"
31#include "stir/shared_ptr.h"
32#include <string>
33
34START_NAMESPACE_STIR
35
80template <typename elemT>
81class LogcoshPrior : public RegisteredParsingObject<LogcoshPrior<elemT>,
82 GeneralisedPrior<DiscretisedDensity<3, elemT>>,
83 PriorWithParabolicSurrogate<DiscretisedDensity<3, elemT>>>
84{
85private:
89 base_type;
90
91public:
93 static const char* const registered_name;
94
97
99 LogcoshPrior(const bool only_2D, float penalization_factor);
100
102 LogcoshPrior(const bool only_2D, float penalization_factor, const float scalar);
103
104 bool parabolic_surrogate_curvature_depends_on_argument() const override { return false; }
105
106 bool is_convex() const override;
107
109 double compute_value(const DiscretisedDensity<3, elemT>& current_image_estimate) override;
110
112 void compute_gradient(DiscretisedDensity<3, elemT>& prior_gradient,
113 const DiscretisedDensity<3, elemT>& current_image_estimate) override;
114
116 void parabolic_surrogate_curvature(DiscretisedDensity<3, elemT>& parabolic_surrogate_curvature,
117 const DiscretisedDensity<3, elemT>& current_image_estimate) override;
118
119 void compute_Hessian(DiscretisedDensity<3, elemT>& prior_Hessian_for_single_densel,
120 const BasicCoordinate<3, int>& coords,
121 const DiscretisedDensity<3, elemT>& current_image_estimate) const override;
122
124 void accumulate_Hessian_times_input(DiscretisedDensity<3, elemT>& output,
125 const DiscretisedDensity<3, elemT>& current_estimate,
126 const DiscretisedDensity<3, elemT>& input) const override;
127
129 Array<3, float> get_weights() const;
130
132 void set_weights(const Array<3, float>&);
133
135
139 shared_ptr<DiscretisedDensity<3, elemT>> get_kappa_sptr() const;
140
142 void set_kappa_sptr(const shared_ptr<DiscretisedDensity<3, elemT>>&);
143
145 float get_scalar() const;
146
148 void set_scalar(float scalar_v);
149
150protected:
153
155 float scalar;
156
158
163
165
170
172 std::string kappa_filename;
173
174 void set_defaults() override;
175 void initialise_keymap() override;
176 bool post_processing() override;
177
179 void check(DiscretisedDensity<3, elemT> const& current_image_estimate) const override;
180
181private:
183 shared_ptr<DiscretisedDensity<3, elemT>> kappa_ptr;
184
186
191 static inline float logcosh(const float d)
192 {
193 const float x = fabs(d);
194 if (x < 30.f)
195 {
196 return log(cosh(x));
197 }
198 else
199 {
200 return x + log(0.5f);
201 }
202 }
203
205
211 static inline float surrogate(const float d, const float scalar)
212 {
213 const float eps = 0.01;
214 const float x = d * scalar;
215 // If abs(x) is less than eps,
216 // use Taylor approximatation of tanh: tanh(x)/x ~= (x - x^3/3)/x = 1- x^2/3.
217 // Prevents divide by zeros
218 if (fabs(x) < eps)
219 {
220 return 1 - square(x) / 3;
221 }
222 else
223 {
224 return tanh(x) / x;
225 }
226 }
227
229
237 elemT derivative_20(const elemT x_j, const elemT x_k) const;
238 elemT derivative_11(const elemT x_j, const elemT x_k) const;
240};
241
242END_NAMESPACE_STIR
243
244#endif
defines the stir::Array class for multi-dimensional (numeric) arrays
defines the stir::DiscretisedDensity class
Declaration of class stir::PriorWithParabolicSurrogate.
Declaration of class stir::RegisteredParsingObject.
This class defines multi-dimensional (numeric) arrays.
Definition Array.h:78
class BasicCoordinate<int num_dimensions, typename coordT> defines num_dimensions -dimensional coordi...
Definition BasicCoordinate.h:57
This abstract class is the basis for all image representations.
Definition DiscretisedDensity.h:99
A base class for 'generalised' priors, i.e. priors for which at least a 'gradient' is defined.
Definition GeneralisedPrior.h:44
static const char *const registered_name
Name which will be used when parsing a GeneralisedPrior object.
Definition LogcoshPrior.h:93
std::string kappa_filename
Filename for the image that will be read by post_processing()
Definition LogcoshPrior.h:172
bool only_2D
can be set during parsing to restrict the weights to the 2D case
Definition LogcoshPrior.h:152
bool post_processing() override
This will be called at the end of the parsing.
Definition LogcoshPrior.cxx:57
LogcoshPrior()
Default constructor.
Definition LogcoshPrior.cxx:123
void initialise_keymap() override
sets key for penalisation factor
Definition LogcoshPrior.cxx:43
float scalar
controls the transition between the quadratic (smooth) and linear (edge-preserving) nature of the pri...
Definition LogcoshPrior.h:155
void check(DiscretisedDensity< 3, elemT > const &current_image_estimate) const override
Check that the prior is ready to be used.
Definition LogcoshPrior.cxx:148
bool parabolic_surrogate_curvature_depends_on_argument() const override
A function that allows skipping some computations if the curvature is independent of the current_esti...
Definition LogcoshPrior.h:104
std::string gradient_filename_prefix
filename prefix for outputting the gradient whenever compute_gradient() is called.
Definition LogcoshPrior.h:162
Array< 3, float > weights
penalty weights
Definition LogcoshPrior.h:169
void set_defaults() override
sets value for penalisation factor
Definition LogcoshPrior.cxx:110
this class implements priors with a parabolic surrogate curvature
Definition PriorWithParabolicSurrogate.h:40
Parent class for all leaves in a RegisteredObject hierarchy that do parsing of parameter files.
Definition RegisteredParsingObject.h:78
NUMBER square(const NUMBER &x)
returns the square of a number, templated.
Definition common.h:154
Import of std::shared_ptr, std::dynamic_pointer_cast and std::static_pointer_cast into the stir names...