Applies forward-backward splitting (FBS) to a lasso problem.
Applies forward-backward splitting (FBS) to a lasso problem. Demonstrates the use of the alpaqa::prox_step function.
1#include <alpaqa/example-util.hpp>
11using std::cout, std::ranges::generate;
17 auto rng = std::mt19937(12345);
18 auto uni = std::uniform_real_distribution<real_t>(-1, 1);
21 generate(A.reshaped(), [&] { return uni(rng); });
22 generate(x.reshaped(), [&] { return uni(rng); });
23 generate(b.reshaped(), [&] { return 1e-2 * uni(rng); });
27 return std::make_tuple(std::move(A), std::move(x), std::move(b), λ);
34 auto [A, x_exact, b, λ] = build_problem();
41 vec x = vec::Zero(n), x_next(n), grad(n), err(n), step(n);
44 cout <<
"iteration\t least squares loss\t fixed-point residual\n";
45 for (index_t i = 0; i < 1'000; ++i) {
47 err.noalias() = A * x - b;
48 grad.noalias() = A.transpose() * err;
49 real_t f = 0.5 * err.squaredNorm();
58 real_t residual = step.norm() / γ;
int main(int argc, const char *argv[])
#define USING_ALPAQA_CONFIG(Conf)
struct alpaqa::prox_step_fn prox_step
Compute a generalized forward-backward step.
std::ostream & print_python(std::ostream &os, const Eigen::DenseBase< Derived > &M, Args &&...args)
std::string float_to_str(F value, int precision)
Double-precision double configuration.