SOPT
Sparse OPTimisation
Functions
l1_proximal.cc File Reference
#include "sopt/l1_proximal.h"
#include "sopt/logging.h"
#include "sopt/types.h"
+ Include dependency graph for l1_proximal.cc:

Go to the source code of this file.

Functions

int main (int, char const **)
 

Function Documentation

◆ main()

int main ( int  ,
char const **   
)

Definition at line 5 of file l1_proximal.cc.

5  {
6 
7  using Scalar = sopt::t_complex;
9  auto const input = sopt::Vector<Scalar>::Random(10).eval();
10  auto const Psi = sopt::Matrix<Scalar>::Random(input.size(), input.size() * 10).eval();
11  sopt::Vector<Real> const weights =
12  sopt::Vector<Scalar>::Random(Psi.cols()).normalized().array().abs();
13 
14  auto const l1 = sopt::proximal::L1<Scalar>()
15  .tolerance(1e-12)
16  .itermax(100)
17  .fista_mixing(true)
18  .positivity_constraint(true)
19  .nu(1)
20  .Psi(Psi)
21  .weights(weights);
22 
23  // gamma should be sufficiently small. Or is it nu should not be 1?
24  // In any case, this seems to work.
25  Real const gamma = 1e-2 / Psi.array().abs().sum();
26  auto const result = l1(gamma, input);
27 
28  if (not result.good) SOPT_THROW("Did not converge");
29 
30  // Check the proximal is a minimum in any allowed direction (positivity constraint)
31  Real constexpr eps = 1e-4;
32  for (size_t i(0); i < 10; ++i) {
33  sopt::Vector<Scalar> const dir = sopt::Vector<Scalar>::Random(input.size()).normalized() * eps;
34  sopt::Vector<Scalar> const position = sopt::positive_quadrant(result.proximal + dir);
35  Real const dobj = l1.objective(input, position, gamma);
36  // Fuzzy logic
37  if (dobj < result.objective - 1e-8)
38  SOPT_THROW("This is not the minimum we are looking for: ")
39  << dobj << " <~ " << result.objective;
40  }
41 
42  return 0;
43 }
sopt::t_real Scalar
Computes inner-most element type.
Definition: real_type.h:42
Real nu() const
Bounds on the squared norm of the operator Ψ
Definition: l1_proximal.h:294
#define SOPT_THROW(MSG)
Definition: exception.h:46
Eigen::CwiseUnaryOp< const details::ProjectPositiveQuadrant< typename T::Scalar >, const T > positive_quadrant(Eigen::DenseBase< T > const &input)
Expression to create projection onto positive quadrant.
Definition: maths.h:60
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
A vector of a given type.
Definition: types.h:24
std::complex< t_real > t_complex
Root of the type hierarchy for (real) complex numbers.
Definition: types.h:19
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > Matrix
A matrix of a given type.
Definition: types.h:29

References sopt::proximal::L1< SCALAR >::nu(), sopt::positive_quadrant(), and SOPT_THROW.