SOPT
Sparse OPTimisation
Classes | Public Types | Public Member Functions | List of all members
sopt::algorithm::L2ForwardBackward< SCALAR > Class Template Reference

#include <l2_forward_backward.h>

Classes

struct  Diagnostic
 Values indicating how the algorithm ran. More...
 
struct  DiagnosticAndResult
 Holds result vector as well. More...
 

Public Types

using value_type = typename FB::value_type
 
using Scalar = typename FB::Scalar
 
using Real = typename FB::Real
 
using t_Vector = typename FB::t_Vector
 
using t_LinearTransform = typename FB::t_LinearTransform
 
template<typename T >
using t_Proximal = std::function< void(t_Vector &, const T &, const t_Vector &)>
 
using t_Gradient = typename FB::t_Gradient
 
using t_IsConverged = typename FB::t_IsConverged
 

Public Member Functions

template<typename DERIVED >
 L2ForwardBackward (Eigen::MatrixBase< DERIVED > const &target)
 
virtual ~L2ForwardBackward ()
 
 SOPT_MACRO (l2_proximal, t_Proximal< Real >)
 l2 proximal for regularizaiton More...
 
 SOPT_MACRO (l2_proximal_weighted, t_Proximal< Vector< Real >>)
 l2 proximal for regularizaiton with weights More...
 
 SOPT_MACRO (l2_proximal_weights, Vector< Real >)
 l2 proximal weights More...
 
 SOPT_MACRO (l2_gradient, t_Gradient)
 Gradient of the l2 norm. More...
 
 SOPT_MACRO (tight_frame, bool)
 Whether Ψ is a tight-frame or not. More...
 
 SOPT_MACRO (residual_tolerance, Real)
 Convergence of the relative variation of the objective functions. More...
 
 SOPT_MACRO (relative_variation, Real)
 Convergence of the relative variation of the objective functions. More...
 
 SOPT_MACRO (residual_convergence, t_IsConverged)
 Convergence of the residuals. More...
 
 SOPT_MACRO (objective_convergence, t_IsConverged)
 Convergence of the residuals. More...
 
 SOPT_MACRO (itermax, t_uint)
 Maximum number of iterations. More...
 
 SOPT_MACRO (regulariser_strength, Real)
 γ parameter. More...
 
 SOPT_MACRO (step_size, Real)
 γ parameter. More...
 
 SOPT_MACRO (sigma, Real)
 γ parameter. More...
 
 SOPT_MACRO (is_converged, t_IsConverged)
 A function verifying convergence. More...
 
 SOPT_MACRO (Phi, t_LinearTransform)
 Measurement operator. More...
 
t_Vector const & target () const
 Vector of target measurements. More...
 
Real objmin () const
 Minimun of objective_function. More...
 
template<typename DERIVED >
L2ForwardBackward< Scalar > & target (Eigen::MatrixBase< DERIVED > const &target)
 Sets the vector of target measurements. More...
 
Diagnostic operator() (t_Vector &out) const
 Calls Forward Backward. More...
 
Diagnostic operator() (t_Vector &out, std::tuple< t_Vector, t_Vector > const &guess) const
 Calls Forward Backward. More...
 
Diagnostic operator() (t_Vector &out, std::tuple< t_Vector const &, t_Vector const & > const &guess) const
 Calls Forward Backward. More...
 
DiagnosticAndResult operator() (std::tuple< t_Vector, t_Vector > const &guess) const
 Calls Forward Backward. More...
 
DiagnosticAndResult operator() (std::tuple< t_Vector const &, t_Vector const & > const &guess) const
 Calls Forward Backward. More...
 
DiagnosticAndResult operator() () const
 Calls Forward Backward. More...
 
DiagnosticAndResult operator() (DiagnosticAndResult const &warmstart) const
 Makes it simple to chain different calls to FB. More...
 
L2ForwardBackward &::type Phi (ARGS &&... args)
 
t_Proximal< Real > & l2_proximal ()
 L1 proximal used during calculation. More...
 
t_Proximal< Vector< Real > > & l2_proximal_weighted ()
 
t_Gradientl2_gradient ()
 Proximal of the L2 ball. More...
 
L2ForwardBackward< Scalar > & residual_convergence (Real const &tolerance)
 Helper function to set-up default residual convergence function. More...
 
L2ForwardBackward< Scalar > & objective_convergence (Real const &tolerance)
 Helper function to set-up default residual convergence function. More...
 
L2ForwardBackward< Scalar > & is_converged (std::function< bool(t_Vector const &x)> const &func)
 Convergence function that takes only the output as argument. More...
 

Detailed Description

template<typename SCALAR>
class sopt::algorithm::L2ForwardBackward< SCALAR >

Definition at line 24 of file l2_forward_backward.h.

Member Typedef Documentation

◆ Real

template<typename SCALAR >
using sopt::algorithm::L2ForwardBackward< SCALAR >::Real = typename FB::Real

Definition at line 31 of file l2_forward_backward.h.

◆ Scalar

template<typename SCALAR >
using sopt::algorithm::L2ForwardBackward< SCALAR >::Scalar = typename FB::Scalar

Definition at line 30 of file l2_forward_backward.h.

◆ t_Gradient

template<typename SCALAR >
using sopt::algorithm::L2ForwardBackward< SCALAR >::t_Gradient = typename FB::t_Gradient

Definition at line 36 of file l2_forward_backward.h.

◆ t_IsConverged

template<typename SCALAR >
using sopt::algorithm::L2ForwardBackward< SCALAR >::t_IsConverged = typename FB::t_IsConverged

Definition at line 37 of file l2_forward_backward.h.

◆ t_LinearTransform

template<typename SCALAR >
using sopt::algorithm::L2ForwardBackward< SCALAR >::t_LinearTransform = typename FB::t_LinearTransform

Definition at line 33 of file l2_forward_backward.h.

◆ t_Proximal

template<typename SCALAR >
template<typename T >
using sopt::algorithm::L2ForwardBackward< SCALAR >::t_Proximal = std::function<void(t_Vector &, const T &, const t_Vector &)>

Definition at line 35 of file l2_forward_backward.h.

◆ t_Vector

template<typename SCALAR >
using sopt::algorithm::L2ForwardBackward< SCALAR >::t_Vector = typename FB::t_Vector

Definition at line 32 of file l2_forward_backward.h.

◆ value_type

template<typename SCALAR >
using sopt::algorithm::L2ForwardBackward< SCALAR >::value_type = typename FB::value_type

Definition at line 29 of file l2_forward_backward.h.

Constructor & Destructor Documentation

◆ L2ForwardBackward()

template<typename SCALAR >
template<typename DERIVED >
sopt::algorithm::L2ForwardBackward< SCALAR >::L2ForwardBackward ( Eigen::MatrixBase< DERIVED > const &  target)
inline

Setups imaging wrapper for ForwardBackward

Parameters
[in]f_proximalproximal operator of the \(f\) function.
[in]g_proximalproximal operator of the \(g\) function

Definition at line 55 of file l2_forward_backward.h.

56  : l2_proximal_([](t_Vector &output, const t_real &regulariser_strength, const t_Vector &x) -> void {
57  proximal::l2_norm(output, regulariser_strength, x);
58  }),
59  l2_proximal_weighted_(
60  [](t_Vector &output, const Vector<Real> &regulariser_strength, const t_Vector &x) -> void {
61  proximal::l2_norm(output, regulariser_strength, x);
62  }),
63  l2_proximal_weights_(Vector<Real>::Ones(1)),
64  l2_gradient_([](t_Vector &output, t_Vector const &image, const t_Vector &residual, const t_LinearTransform &Phi) -> void {
65  output = Phi.adjoint()*residual;
66  }), // gradient of 1/2 * r^2 = r;
67  tight_frame_(false),
68  residual_tolerance_(0.),
69  relative_variation_(1e-4),
70  residual_convergence_(nullptr),
71  objective_convergence_(nullptr),
72  itermax_(std::numeric_limits<t_uint>::max()),
73  regulariser_strength_(1e-8),
74  step_size_(1),
75  sigma_(1),
76  is_converged_(),
77  Phi_(linear_transform_identity<Scalar>()),
78  target_(target) {}
sopt::Vector< Scalar > t_Vector
L2ForwardBackward &::type Phi(ARGS &&... args)
t_Vector const & target() const
Vector of target measurements.
sopt::t_real t_real
void l2_norm(Eigen::DenseBase< T0 > &out, typename real_type< typename T0::Scalar >::type gamma, Eigen::DenseBase< T1 > const &x)
Proximal of the l2 norm (note this is different from the l2 ball indicator function)
Definition: proximal.h:84
sopt::Vector< Scalar > Vector
Definition: inpainting.cc:28

◆ ~L2ForwardBackward()

template<typename SCALAR >
virtual sopt::algorithm::L2ForwardBackward< SCALAR >::~L2ForwardBackward ( )
inlinevirtual

Definition at line 79 of file l2_forward_backward.h.

79 {}

Member Function Documentation

◆ is_converged()

template<typename SCALAR >
L2ForwardBackward<Scalar>& sopt::algorithm::L2ForwardBackward< SCALAR >::is_converged ( std::function< bool(t_Vector const &x)> const &  func)
inline

Convergence function that takes only the output as argument.

Definition at line 217 of file l2_forward_backward.h.

217  {
218  return is_converged([func](t_Vector const &x, t_Vector const &) { return func(x); });
219  }
L2ForwardBackward< Scalar > & is_converged(std::function< bool(t_Vector const &x)> const &func)
Convergence function that takes only the output as argument.

◆ l2_gradient()

template<typename SCALAR >
t_Gradient& sopt::algorithm::L2ForwardBackward< SCALAR >::l2_gradient ( )
inline

Proximal of the L2 ball.

Non-const version to setup the object.

Definition at line 206 of file l2_forward_backward.h.

206 { return l2_gradient_; }

◆ l2_proximal()

template<typename SCALAR >
t_Proximal<Real>& sopt::algorithm::L2ForwardBackward< SCALAR >::l2_proximal ( )
inline

L1 proximal used during calculation.

Non-const version to setup the object.

Definition at line 202 of file l2_forward_backward.h.

202 { return l2_proximal_; }

◆ l2_proximal_weighted()

template<typename SCALAR >
t_Proximal<Vector<Real> >& sopt::algorithm::L2ForwardBackward< SCALAR >::l2_proximal_weighted ( )
inline

Definition at line 203 of file l2_forward_backward.h.

203 { return l2_proximal_weighted_; }

◆ objective_convergence()

template<typename SCALAR >
L2ForwardBackward<Scalar>& sopt::algorithm::L2ForwardBackward< SCALAR >::objective_convergence ( Real const &  tolerance)
inline

Helper function to set-up default residual convergence function.

Definition at line 213 of file l2_forward_backward.h.

213  {
214  return objective_convergence(nullptr).relative_variation(tolerance);
215  }
L2ForwardBackward< Scalar > & objective_convergence(Real const &tolerance)
Helper function to set-up default residual convergence function.

◆ objmin()

template<typename SCALAR >
Real sopt::algorithm::L2ForwardBackward< SCALAR >::objmin ( ) const
inline

Minimun of objective_function.

Definition at line 138 of file l2_forward_backward.h.

138 { return objmin_; }

◆ operator()() [1/7]

template<typename SCALAR >
DiagnosticAndResult sopt::algorithm::L2ForwardBackward< SCALAR >::operator() ( ) const
inline

Calls Forward Backward.

Parameters
[in]guessinitial guess

Definition at line 179 of file l2_forward_backward.h.

179  {
180  DiagnosticAndResult result;
181  static_cast<Diagnostic &>(result) = operator()(
182  result.x, ForwardBackward<SCALAR>::initial_guess(target(), Phi()));
183  return result;
184  }

References sopt::target(), and sopt::algorithm::L2ForwardBackward< SCALAR >::DiagnosticAndResult::x.

◆ operator()() [2/7]

template<typename SCALAR >
DiagnosticAndResult sopt::algorithm::L2ForwardBackward< SCALAR >::operator() ( DiagnosticAndResult const &  warmstart) const
inline

Makes it simple to chain different calls to FB.

Definition at line 186 of file l2_forward_backward.h.

186  {
187  DiagnosticAndResult result = warmstart;
188  static_cast<Diagnostic &>(result) = operator()(result.x, warmstart.x, warmstart.residual);
189  return result;
190  }

References sopt::algorithm::L2ForwardBackward< SCALAR >::DiagnosticAndResult::x.

◆ operator()() [3/7]

template<typename SCALAR >
DiagnosticAndResult sopt::algorithm::L2ForwardBackward< SCALAR >::operator() ( std::tuple< t_Vector const &, t_Vector const & > const &  guess) const
inline

Calls Forward Backward.

Parameters
[in]guessinitial guess

Definition at line 171 of file l2_forward_backward.h.

172  {
173  DiagnosticAndResult result;
174  static_cast<Diagnostic &>(result) = operator()(result.x, guess);
175  return result;
176  }

References sopt::algorithm::L2ForwardBackward< SCALAR >::DiagnosticAndResult::x.

◆ operator()() [4/7]

template<typename SCALAR >
DiagnosticAndResult sopt::algorithm::L2ForwardBackward< SCALAR >::operator() ( std::tuple< t_Vector, t_Vector > const &  guess) const
inline

Calls Forward Backward.

Parameters
[in]guessinitial guess

Definition at line 166 of file l2_forward_backward.h.

166  {
167  return operator()(std::tie(std::get<0>(guess), std::get<1>(guess)));
168  }
DiagnosticAndResult operator()() const
Calls Forward Backward.

◆ operator()() [5/7]

template<typename SCALAR >
Diagnostic sopt::algorithm::L2ForwardBackward< SCALAR >::operator() ( t_Vector out) const
inline

Calls Forward Backward.

Parameters
[out]outOutput vector x

Definition at line 148 of file l2_forward_backward.h.

148  {
149  return operator()(out, ForwardBackward<SCALAR>::initial_guess(target(), Phi()));
150  }

References sopt::target().

◆ operator()() [6/7]

template<typename SCALAR >
Diagnostic sopt::algorithm::L2ForwardBackward< SCALAR >::operator() ( t_Vector out,
std::tuple< t_Vector const &, t_Vector const & > const &  guess 
) const
inline

Calls Forward Backward.

Parameters
[out]outOutput vector x
[in]guessinitial guess

Definition at line 160 of file l2_forward_backward.h.

161  {
162  return operator()(out, std::get<0>(guess), std::get<1>(guess));
163  }

◆ operator()() [7/7]

template<typename SCALAR >
Diagnostic sopt::algorithm::L2ForwardBackward< SCALAR >::operator() ( t_Vector out,
std::tuple< t_Vector, t_Vector > const &  guess 
) const
inline

Calls Forward Backward.

Parameters
[out]outOutput vector x
[in]guessinitial guess

Definition at line 154 of file l2_forward_backward.h.

154  {
155  return operator()(out, std::get<0>(guess), std::get<1>(guess));
156  }

◆ Phi()

template<typename SCALAR >
L2ForwardBackward& ::type sopt::algorithm::L2ForwardBackward< SCALAR >::Phi ( ARGS &&...  args)
inline

Definition at line 194 of file l2_forward_backward.h.

195  {
196  Phi_ = linear_transform(std::forward<ARGS>(args)...);
197  return *this;
198  }
LinearTransform< VECTOR > linear_transform(OperatorFunction< VECTOR > const &direct, OperatorFunction< VECTOR > const &indirect, std::array< t_int, 3 > const &sizes={{1, 1, 0}})

References sopt::linear_transform().

Referenced by main().

◆ residual_convergence()

template<typename SCALAR >
L2ForwardBackward<Scalar>& sopt::algorithm::L2ForwardBackward< SCALAR >::residual_convergence ( Real const &  tolerance)
inline

Helper function to set-up default residual convergence function.

Definition at line 209 of file l2_forward_backward.h.

209  {
210  return residual_convergence(nullptr).residual_tolerance(tolerance);
211  }
L2ForwardBackward< Scalar > & residual_convergence(Real const &tolerance)
Helper function to set-up default residual convergence function.

◆ SOPT_MACRO() [1/15]

template<typename SCALAR >
sopt::algorithm::L2ForwardBackward< SCALAR >::SOPT_MACRO ( is_converged  ,
t_IsConverged   
)

A function verifying convergence.

◆ SOPT_MACRO() [2/15]

template<typename SCALAR >
sopt::algorithm::L2ForwardBackward< SCALAR >::SOPT_MACRO ( itermax  ,
t_uint   
)

Maximum number of iterations.

◆ SOPT_MACRO() [3/15]

template<typename SCALAR >
sopt::algorithm::L2ForwardBackward< SCALAR >::SOPT_MACRO ( l2_gradient  ,
t_Gradient   
)

Gradient of the l2 norm.

◆ SOPT_MACRO() [4/15]

template<typename SCALAR >
sopt::algorithm::L2ForwardBackward< SCALAR >::SOPT_MACRO ( l2_proximal  ,
t_Proximal< Real  
)

l2 proximal for regularizaiton

◆ SOPT_MACRO() [5/15]

template<typename SCALAR >
sopt::algorithm::L2ForwardBackward< SCALAR >::SOPT_MACRO ( l2_proximal_weighted  ,
t_Proximal< Vector< Real >>   
)

l2 proximal for regularizaiton with weights

◆ SOPT_MACRO() [6/15]

template<typename SCALAR >
sopt::algorithm::L2ForwardBackward< SCALAR >::SOPT_MACRO ( l2_proximal_weights  ,
Vector< Real  
)

l2 proximal weights

◆ SOPT_MACRO() [7/15]

template<typename SCALAR >
sopt::algorithm::L2ForwardBackward< SCALAR >::SOPT_MACRO ( objective_convergence  ,
t_IsConverged   
)

Convergence of the residuals.

If negative, this convergence criteria is disabled.

◆ SOPT_MACRO() [8/15]

template<typename SCALAR >
sopt::algorithm::L2ForwardBackward< SCALAR >::SOPT_MACRO ( Phi  ,
t_LinearTransform   
)

Measurement operator.

◆ SOPT_MACRO() [9/15]

template<typename SCALAR >
sopt::algorithm::L2ForwardBackward< SCALAR >::SOPT_MACRO ( regulariser_strength  ,
Real   
)

γ parameter.

◆ SOPT_MACRO() [10/15]

template<typename SCALAR >
sopt::algorithm::L2ForwardBackward< SCALAR >::SOPT_MACRO ( relative_variation  ,
Real   
)

Convergence of the relative variation of the objective functions.

If negative, this convergence criteria is disabled.

◆ SOPT_MACRO() [11/15]

template<typename SCALAR >
sopt::algorithm::L2ForwardBackward< SCALAR >::SOPT_MACRO ( residual_convergence  ,
t_IsConverged   
)

Convergence of the residuals.

If negative, this convergence criteria is disabled.

◆ SOPT_MACRO() [12/15]

template<typename SCALAR >
sopt::algorithm::L2ForwardBackward< SCALAR >::SOPT_MACRO ( residual_tolerance  ,
Real   
)

Convergence of the relative variation of the objective functions.

If negative, this convergence criteria is disabled.

◆ SOPT_MACRO() [13/15]

template<typename SCALAR >
sopt::algorithm::L2ForwardBackward< SCALAR >::SOPT_MACRO ( sigma  ,
Real   
)

γ parameter.

◆ SOPT_MACRO() [14/15]

template<typename SCALAR >
sopt::algorithm::L2ForwardBackward< SCALAR >::SOPT_MACRO ( step_size  ,
Real   
)

γ parameter.

◆ SOPT_MACRO() [15/15]

template<typename SCALAR >
sopt::algorithm::L2ForwardBackward< SCALAR >::SOPT_MACRO ( tight_frame  ,
bool   
)

Whether Ψ is a tight-frame or not.

◆ target() [1/2]

template<typename SCALAR >
t_Vector const& sopt::algorithm::L2ForwardBackward< SCALAR >::target ( ) const
inline

Vector of target measurements.

Definition at line 136 of file l2_forward_backward.h.

136 { return target_; }

◆ target() [2/2]

template<typename SCALAR >
template<typename DERIVED >
L2ForwardBackward<Scalar>& sopt::algorithm::L2ForwardBackward< SCALAR >::target ( Eigen::MatrixBase< DERIVED > const &  target)
inline

Sets the vector of target measurements.

Definition at line 141 of file l2_forward_backward.h.

141  {
142  target_ = target;
143  return *this;
144  }

References sopt::target().


The documentation for this class was generated from the following file: