1 #include <catch2/catch_all.hpp>
16 #include "tools_for_tests/directories.h"
20 extern std::unique_ptr<std::mt19937_64>
mersenne;
21 std::uniform_int_distribution<sopt::t_int> uniform_dist(min, max);
31 TEST_CASE(
"Forward Backward with ||x - x0||_2^2 function",
"[fb]") {
33 t_Vector const target0 = t_Vector::Random(
N);
34 t_real constexpr beta = 0.2;
35 t_real constexpr regulariser_strength = 0.1;
36 int constexpr itermax = 300;
42 const t_Vector x_guess = t_Vector::Random(target0.size());
43 const t_Vector res = x_guess - target0;
44 auto const convergence = [&target0](
const t_Vector &x,
const t_Vector &res) ->
bool {
45 return x.isApprox(target0, 1e-9);
50 auto fb = algorithm::ForwardBackward<Scalar>(grad, g0, target0)
52 .regulariser_strength(regulariser_strength)
54 .is_converged(convergence);
55 auto const result = fb(std::make_tuple(x_guess, res));
56 CAPTURE(result.niters);
58 CAPTURE(result.residual);
59 CHECK(result.x.isApprox(target0, 1e-9));
61 CHECK(result.niters < itermax);
65 :
public std::is_same<sopt::algorithm::ImagingForwardBackward<double> &, T> {};
67 :
public std::is_same<sopt::algorithm::L1GProximal<double> &, T> {};
69 TEST_CASE(
"Check type returned on setting variables") {
89 auto gp = std::make_shared<sopt::algorithm::L1GProximal<Scalar>>(
false);
sopt::Vector< Scalar > t_Vector
ImagingForwardBackward< Scalar > & is_converged(std::function< bool(t_Vector const &x)> const &func)
Convergence function that takes only the output as argument.
ImagingForwardBackward< Scalar > & residual_convergence(Real const &tolerance)
Helper function to set-up default residual convergence function.
t_Vector const & target() const
Vector of target measurements.
std::unique_ptr< std::mt19937_64 > mersenne(new std::mt19937_64(0))
sopt::t_int random_integer(sopt::t_int min, sopt::t_int max)
TEST_CASE("Forward Backward with ||x - x0||_2^2 function", "[fb]")
void id(Eigen::DenseBase< T0 > &out, typename real_type< typename T0::Scalar >::type gamma, Eigen::DenseBase< T1 > const &x)
Proximal of a function that is always zero, the identity.
int t_int
Root of the type hierarchy for signed integers.
double t_real
Root of the type hierarchy for real numbers.
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
A vector of a given type.
std::function< bool(Vector< SCALAR > const &)> ConvergenceFunction
Typical function signature for convergence.