alpaqa 1.0.0a15
Nonconvex constrained optimization
Loading...
Searching...
No Matches
extra-stats.hpp
Go to the documentation of this file.
1#pragma once
2
5#include "solver-driver.hpp"
6#include <map>
7#include <memory>
8#include <string>
9#include <variant>
10
11template <alpaqa::Config Conf>
14 static constexpr real_t NaN = alpaqa::NaN<Conf>;
15 struct Record {
17 real_t gamma = NaN, eps = NaN, delta = NaN, psi = NaN, psi_hat = NaN,
18 fbe = NaN, tau = NaN, radius = NaN, rho = NaN;
19 };
20 std::vector<Record> stats{};
21
22 void update_iter(const auto &progress_info) {
23 Record r{
24 .outer_iter = progress_info.outer_iter,
25 .inner_iter = progress_info.k,
26 };
27 if constexpr (requires { progress_info.γ; })
28 r.gamma = progress_info.γ;
29 if constexpr (requires { progress_info.ε; })
30 r.eps = progress_info.ε;
31 if constexpr (requires { progress_info.ψ; })
32 r.psi = progress_info.ψ;
33 if constexpr (requires { progress_info.ψ_hat; })
34 r.psi_hat = progress_info.ψ_hat;
35 if constexpr (requires { progress_info.φγ; })
36 r.fbe = progress_info.φγ;
37 if constexpr (requires { progress_info.τ; })
38 r.tau = progress_info.τ;
39 if constexpr (requires { progress_info.Δ; })
40 r.radius = progress_info.Δ;
41 if constexpr (requires { progress_info.ρ; })
42 r.rho = progress_info.ρ;
43 if constexpr (requires {
44 progress_info.y;
45 progress_info.ŷ;
46 progress_info.Σ;
47 })
48 r.delta = (progress_info.Σ.asDiagonal().inverse() *
49 (progress_info.ŷ - progress_info.y))
50 .template lpNorm<Eigen::Infinity>();
51 stats.push_back(r);
52 }
53};
54
55template <alpaqa::Config Conf>
59 std::shared_ptr<const AlpaqaSolverStatsCollector<config_t>>;
63 [[nodiscard]] bool has_statistics() const override {
64 return collector && !collector->stats.empty();
65 }
66 void write_statistics_to_stream(std::ostream &os) override {
67 std::array<char, 64> buf;
68 os << "outer_iter,inner_iter,gamma,eps,delta,psi,psi_hat,fbe,tau,"
69 "radius,rho\n";
70 for (const auto &r : collector->stats) {
71 os << r.outer_iter << ',' << r.inner_iter << ','
72 << alpaqa::float_to_str_vw(buf, r.gamma) << ','
73 << alpaqa::float_to_str_vw(buf, r.eps) << ','
74 << alpaqa::float_to_str_vw(buf, r.delta) << ','
75 << alpaqa::float_to_str_vw(buf, r.psi) << ','
76 << alpaqa::float_to_str_vw(buf, r.psi_hat) << ','
77 << alpaqa::float_to_str_vw(buf, r.fbe) << ','
78 << alpaqa::float_to_str_vw(buf, r.tau) << ','
79 << alpaqa::float_to_str_vw(buf, r.radius) << ','
80 << alpaqa::float_to_str_vw(buf, r.rho) << '\n';
81 }
82 }
83};
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:56
constexpr const auto inf
Definition config.hpp:85
std::string_view float_to_str_vw(auto &buf, double value, int precision=std::numeric_limits< double >::max_digits10)
Definition print.tpp:39
std::function< solver_free_func_t > solver_func_t
void update_iter(const auto &progress_info)
static constexpr real_t NaN
std::vector< Record > stats
AlpaqaSolverWrapperStats(solver_func_t run, collector_t collector)
void write_statistics_to_stream(std::ostream &os) override
std::shared_ptr< const AlpaqaSolverStatsCollector< config_t > > collector_t
bool has_statistics() const override
solver_func_t run