SOPT
Sparse OPTimisation
real_indicator.h
Go to the documentation of this file.
1 #ifndef SOPT_PROJECTION_PROXIMAL_H
2 #define SOPT_PROJECTION_PROXIMAL_H
3 
6 #include <complex>
7 
8 namespace sopt::algorithm {
9 
10 // Implementation of real indicator (non differentiable) function
11 // The proximal operator is just a real projection
12 // interface defined by NonDifferentiableFunc class
13 // Psi from the base class is redundant in this case
14 template <typename SCALAR>
15 class RealIndicator : public NonDifferentiableFunc<SCALAR>
16 {
17  public:
19  using Real = typename NDF::Real;
20  using t_Vector = typename NDF::t_Vector;
21  using t_Proximal = typename NDF::t_Proximal;
23 
25 
26  void log_message() const override
27  {
28  SOPT_HIGH_LOG("Using Real Indicator for g(x)");
29  }
30 
31  // Indicator function. This is usually only used for the
32  // objective function, so this will probably not be called.
33  Real function(t_Vector const &x) const override;
34 
35  // Real projection
36  t_Proximal proximal_operator() const override
37  {
38  return [this](t_Vector &out, Real gamma, t_Vector const &image) {
39  out = image.real();
40  };
41  }
42 
43  // Return the identity by default since the Psi operator
44  // should not be used in this case
45  t_LinearTransform const &Psi() const override
46  {
47  return linear_operator;
48  }
49 
50  t_LinearTransform linear_operator = sopt::linear_transform_identity<SCALAR>();
51 };
52 
53 template<typename SCALAR>
55 {
56  if constexpr (std::is_same<SCALAR, sopt::t_complex>::value)
57  {
58  for (auto &z : x) {
59  if (z.imag() != 0) {
60  SOPT_HIGH_LOG("Non-real vector in real indicator function; real projection has not been properly performed.");
61  return 1; // should in principle be inf but not sure how to model this
62  }
63  }
64  }
65  return 0;
66 }
67 
68 }
69 
70 #endif
sopt::Vector< Scalar > t_Vector
typename FB::t_Proximal t_Proximal
typename FB::t_Vector t_Vector
typename FB::t_LinearTransform t_LinearTransform
void log_message() const override
t_LinearTransform const & Psi() const override
t_Proximal proximal_operator() const override
typename NDF::t_Vector t_Vector
Real function(t_Vector const &x) const override
t_LinearTransform linear_operator
#define SOPT_HIGH_LOG(...)
High priority message.
Definition: logging.h:223