alpaqa 1.0.0a10
Nonconvex constrained optimization
Loading...
Searching...
No Matches
prox.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace alpaqa {
7
8/// Proximal mapping customization point.
9/// @see https://wg21.link/P1895R0
10struct prox_fn {
11 template <class T>
12 requires requires {
13 // The proximable function type T should define a valid
14 // configuration typedef.
15 typename T::config_t;
16 requires is_config_v<typename T::config_t>;
17 // The proximable function type T should opt in to the prox_fn
18 // tag to provide a custom implementation for the proximal operator.
19 requires alpaqa::tag_invocable<
20 prox_fn, T &, typename T::config_t::crmat,
21 typename T::config_t::rmat, typename T::config_t::real_t>;
22 // The return type of that proximal operator should be real_t.
23 requires std::is_same_v<
24 tag_invoke_result_t<prox_fn, T &, typename T::config_t::crmat,
25 typename T::config_t::rmat,
26 typename T::config_t::real_t>,
27 typename T::config_t::real_t>;
28 }
29 auto operator()(T &func, typename T::config_t::crmat in,
30 typename T::config_t::rmat out,
31 typename T::config_t::real_t γ = 1) const
33 prox_fn, T &, typename T::config_t::crmat,
34 typename T::config_t::rmat, typename T::config_t::real_t>) ->
35 typename T::config_t::real_t {
36 return alpaqa::alpaqa_tag_invoke(*this, func, std::move(in),
37 std::move(out), γ);
38 }
39}
40/**
41 * Compute the proximal mapping.
42 * @f[ \begin{aligned}
43 * \mathrm{out} &\leftarrow \prox_{\gamma\, \mathrm{func}}
44 * \left( \mathrm{in} \right).
45 * \end{aligned}
46 * @f]
47 * @param func
48 * The proximable function @f$ h : \Rn \to \Rn @f$ to apply the
49 * proximal mapping of.
50 * @param[in] in
51 * Input vector or matrix @f$ x @f$, e.g. current iterate.
52 * @param[out] out
53 * Proximal mapping of @f$ (\gamma\, h) @f$ at @f$ x @f$.
54 * @f$ \hat x \leftarrow \prox_{\gamma\, h}\left( x \right) @f$
55 * @param[in] γ
56 * Proximal step size @f$ \gamma @f$.
57 * @ingroup grp_Functions
58 */
59inline constexpr prox;
60
61/// Proximal mapping customization point for forward-backward steps.
62/// @see https://wg21.link/P1895R0
64 template <class T>
65 requires requires {
66 // The proximable function type T should define a valid
67 // configuration typedef.
68 typename T::config_t;
69 requires is_config_v<typename T::config_t>;
70 // The proximable function type T should opt in to the prox_step_fn
71 // tag to provide a custom implementation for the proximal operator.
72 requires alpaqa::tag_invocable<
73 prox_step_fn, T &, typename T::config_t::crmat,
74 typename T::config_t::crmat, typename T::config_t::rmat,
75 typename T::config_t::rmat, typename T::config_t::real_t,
76 typename T::config_t::real_t>;
77 // The return type of that proximal operator should be real_t.
78 requires std::is_same_v<
80 prox_step_fn, T &, typename T::config_t::crmat,
81 typename T::config_t::crmat, typename T::config_t::rmat,
82 typename T::config_t::rmat, typename T::config_t::real_t,
83 typename T::config_t::real_t>,
84 typename T::config_t::real_t>;
85 }
86 auto operator()(T &func, typename T::config_t::crmat in,
87 typename T::config_t::crmat fwd_step,
88 typename T::config_t::rmat out,
89 typename T::config_t::rmat fb_step,
90 typename T::config_t::real_t γ = 1,
91 typename T::config_t::real_t γ_fwd = -1) const
93 prox_step_fn, T &, typename T::config_t::crmat,
94 typename T::config_t::crmat, typename T::config_t::rmat,
95 typename T::config_t::rmat, typename T::config_t::real_t,
96 typename T::config_t::real_t>) ->
97 typename T::config_t::real_t {
98 return alpaqa::alpaqa_tag_invoke(*this, func, std::move(in),
99 std::move(fwd_step), std::move(out),
100 std::move(fb_step), γ, γ_fwd);
101 }
102
103 /// Default implementation for prox_step if only prox is provided.
104 template <class T>
105 requires requires {
106 typename T::config_t;
107 requires is_config_v<typename T::config_t>;
108 // Only enable if no implementation exists,
109 requires !alpaqa::tag_invocable<
110 prox_step_fn, T &, typename T::config_t::crmat,
111 typename T::config_t::crmat, typename T::config_t::rmat,
112 typename T::config_t::rmat, typename T::config_t::real_t,
113 typename T::config_t::real_t>;
114 // and only enable if prox is provided.
115 requires std::invocable<prox_fn, T &, typename T::config_t::crmat,
116 typename T::config_t::rmat,
117 typename T::config_t::real_t>;
118 }
119 auto operator()(T &func, typename T::config_t::crmat in,
120 typename T::config_t::crmat fwd_step,
121 typename T::config_t::rmat out,
122 typename T::config_t::rmat fb_step,
123 typename T::config_t::real_t γ = 1,
124 typename T::config_t::real_t γ_fwd = -1) const
125 noexcept(std::is_nothrow_invocable_v<
126 prox_fn, T &, typename T::config_t::crmat,
127 typename T::config_t::rmat, typename T::config_t::real_t>) ->
128 typename T::config_t::real_t {
129 fb_step = in + γ_fwd * fwd_step;
130 auto &&h_out = prox(func, fb_step, out, γ);
131 fb_step = out - in;
132 return h_out;
133 }
134}
135/**
136 * Compute a generalized forward-backward step
137 * @f[ \begin{aligned}
138 * \mathrm{out} &\leftarrow \prox_{\gamma\, \mathrm{func}}
139 * \left( \mathrm{in} + \gamma_\mathrm{fwd}\, \mathrm{fwd\_step} \right) \\
140 * \mathrm{fb\_step} &\leftarrow \mathrm{out} - \mathrm{in}.
141 * \end{aligned}
142 * @f]
143 * @param func
144 * The proximable function @f$ h : \Rn \to \Rn @f$ to apply the
145 * proximal mapping of.
146 * @param[in] in
147 * Input vector or matrix @f$ x @f$, e.g. current iterate.
148 * @param[in] fwd_step
149 * Step @f$ d @f$ to add to @f$ x @f$ before computing the
150 * proximal mapping. Scaled by @f$ \gamma_\text{fwd} @f$.
151 * @param[out] out
152 * Proximal mapping of @f$ (\gamma\, h) @f$ at
153 * @f$ x + \gamma_\text{fwd}\, d @f$.
154 * @f$ \hat x \leftarrow \prox_{\gamma\, h}\left(
155 * x + \gamma_\text{fwd}\, d \right) @f$
156 * @param[out] fb_step
157 * Forward-backward step @f$ p @f$.
158 * @f$ p = \hat x - \hat x @f$
159 * @param[in] γ
160 * Proximal step size @f$ \gamma @f$.
161 * @param[in] γ_fwd
162 * Forward step size @f$ \gamma_\mathrm{fwd} @f$.
163 * @ingroup grp_Functions
164 */
165inline constexpr prox_step;
166
167} // namespace alpaqa
struct alpaqa::prox_fn prox
Compute the proximal mapping.
struct alpaqa::prox_step_fn prox_step
Compute a generalized forward-backward step.
constexpr tag_invoke_fn_ns::tag_invoke_fn alpaqa_tag_invoke
Definition: tag-invoke.hpp:41
typename Conf::crmat crmat
Definition: config.hpp:73
typename Conf::rmat rmat
Definition: config.hpp:72
std::invoke_result_t< decltype(::alpaqa::alpaqa_tag_invoke), Tag, Args... > tag_invoke_result_t
Definition: tag-invoke.hpp:71
typename Conf::real_t real_t
Definition: config.hpp:63
constexpr bool is_nothrow_tag_invocable_v
Definition: tag-invoke.hpp:62
Proximal mapping customization point.
Definition: prox.hpp:10
auto operator()(T &func, typename T::config_t::crmat in, typename T::config_t::rmat out, typename T::config_t::real_t γ=1) const noexcept(alpaqa::is_nothrow_tag_invocable_v< prox_fn, T &, typename T::config_t::crmat, typename T::config_t::rmat, typename T::config_t::real_t >) -> typename T::config_t::real_t
Definition: prox.hpp:29
Proximal mapping customization point for forward-backward steps.
Definition: prox.hpp:63
auto operator()(T &func, typename T::config_t::crmat in, typename T::config_t::crmat fwd_step, typename T::config_t::rmat out, typename T::config_t::rmat fb_step, typename T::config_t::real_t γ=1, typename T::config_t::real_t γ_fwd=-1) const noexcept(std::is_nothrow_invocable_v< prox_fn, T &, typename T::config_t::crmat, typename T::config_t::rmat, typename T::config_t::real_t >) -> typename T::config_t::real_t
Default implementation for prox_step if only prox is provided.
Definition: prox.hpp:119
auto operator()(T &func, typename T::config_t::crmat in, typename T::config_t::crmat fwd_step, typename T::config_t::rmat out, typename T::config_t::rmat fb_step, typename T::config_t::real_t γ=1, typename T::config_t::real_t γ_fwd=-1) const noexcept(alpaqa::is_nothrow_tag_invocable_v< prox_step_fn, T &, typename T::config_t::crmat, typename T::config_t::crmat, typename T::config_t::rmat, typename T::config_t::rmat, typename T::config_t::real_t, typename T::config_t::real_t >) -> typename T::config_t::real_t
Definition: prox.hpp:86