SOPT
Sparse OPTimisation
sdmm_warm_start.cc
Go to the documentation of this file.
1 #include <catch2/catch_all.hpp>
2 #include <random>
3 
4 #include <Eigen/Dense>
5 
6 #include "sopt/proximal.h"
7 #include "sopt/sdmm.h"
8 #include "sopt/types.h"
9 
13 
14 auto constexpr N = 30;
15 SCENARIO("SDMM with warm start", "[sdmm][integration]") {
16  using namespace sopt;
17 
18  GIVEN("An SDMM instance with its input") {
19  t_Matrix const Id = t_Matrix::Identity(N, N).eval();
20  t_Vector const target0 = t_Vector::Random(N);
21  t_Vector target1 = t_Vector::Random(N) * 4;
22 
23  auto convergence = [&target1, &target0](t_Vector const &x) -> bool {
24  t_Vector const segment = (target1 - target0).normalized();
25  t_real const alpha = (x - target0).transpose() * segment;
26  return alpha >= 0e0 and (target1 - target0).transpose() * segment >= alpha and
27  (x - target0 - alpha * segment).stableNorm() < 1e-8;
28  };
29 
30  auto sdmm = algorithm::SDMM<Scalar>()
31  .is_converged(convergence)
32  .itermax(5000)
33  .gamma(1)
34  .conjugate_gradient(std::numeric_limits<t_uint>::max(), 1e-12)
35  .append(proximal::translate(proximal::EuclidianNorm(), -target0), Id)
36  .append(proximal::translate(proximal::EuclidianNorm(), -target1), Id);
37  t_Vector const input = t_Vector::Random(N);
38 
39  WHEN("the algorithms runs") {
40  auto const full = sdmm(input);
41  THEN("it converges") {
42  CHECK(full.niters > 20);
43  CHECK(full.good);
44  }
45 
46  WHEN("It is set to stop before convergence") {
47  auto const first_half = sdmm.itermax(full.niters - 5)(input);
48  THEN("It is not converged") { CHECK(not first_half.good); }
49 
50  WHEN("A warm restart is attempted") {
51  auto const second_half = sdmm.itermax(5000)(first_half);
52  THEN("The warm restart is validated by the fast convergence") {
53  CHECK(second_half.niters < 10);
54  }
55  }
56  }
57  }
58  }
59 }
sopt::Vector< Scalar > t_Vector
sopt::t_real Scalar
sopt::Matrix< Scalar > t_Matrix
bool is_converged(t_Vector const &x) const
Forwards to convergence function parameter.
Definition: sdmm.h:172
Proximal of euclidian norm.
Definition: proximal.h:18
Translation< FUNCTION, VECTOR > translate(FUNCTION const &func, VECTOR const &translation)
Translates given proximal by given vector.
Definition: proximal.h:362
double t_real
Root of the type hierarchy for real numbers.
Definition: types.h:17
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
A vector of a given type.
Definition: types.h:24
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > Matrix
A matrix of a given type.
Definition: types.h:29
SCENARIO("SDMM with warm start", "[sdmm][integration]")
constexpr auto N