47 #include <Eigen/Dense>
48 #include <glog/logging.h>
120 iPiano(
const std::function<
float(
const Eigen::MatrixXf&)> f,
121 const std::function<
void(
const Eigen::MatrixXf&, Eigen::MatrixXf&)> df,
122 std::function<
float(
const Eigen::MatrixXf&)> g,
123 const std::function<
void(
const Eigen::MatrixXf&, Eigen::MatrixXf&,
float alpha)> prox_g,
125 const std::function<
void(
const Iteration&)> callback = [](
const Iteration &iteration) ->
void { });
134 void optimize(Eigen::MatrixXf &x_star,
float &f_x_star);
164 if (iteration.
n%n == 0)
166 std::cout <<
"[" << iteration.
n <<
"] "
168 <<
" (Delta_n = " << iteration.
Delta_n <<
"; L_n = " << iteration.
L_n
169 <<
"; alpha_n = " << iteration.
alpha_n <<
"; beta_n = " << iteration.
beta_n <<
")"
180 if (iteration.
n%n == 0)
182 std::cout <<
"[" << iteration.
n <<
"] "
184 <<
" (Delta_n = " << iteration.
Delta_n <<
")"
196 out.open(file, std::ios_base::app);
197 out <<
"iteration = " << iteration.
n <<
"; f_x_n = " << iteration.
f_x_n
198 <<
"; g_x_n = " << iteration.
g_x_n <<
"; alpha_n = " << iteration.
alpha_n
199 <<
"; beta_n = " << iteration.
beta_n <<
"; L_n = " << iteration.
L_n
200 <<
"; |df_x_n| = " << std::sqrt(iteration.
df_x_n.squaredNorm())
201 <<
"; Delta_n = " << iteration.
Delta_n << std::endl;
212 out.open(file, std::ios_base::app);
213 out << iteration.
n <<
"," << iteration.
f_x_n + iteration.
g_x_n
214 <<
"," << iteration.
f_x_n <<
"," << iteration.
g_x_n
216 <<
"," << iteration.
L_n <<
"," << iteration.
Delta_n << std::endl;
225 const std::function<
void(
const Eigen::MatrixXf&,Eigen::MatrixXf&)> df,
226 std::function<
float(
const Eigen::MatrixXf &)> g,
227 const std::function<
void(
const Eigen::MatrixXf&, Eigen::MatrixXf&,
float alpha)> prox_g,
230 :
nmiPiano(f, df, g, prox_g, options)
255 Eigen::MatrixXf x_np1;
263 float L_nm1 = estimateL(iteration);
268 LOG_IF(INFO, !
options_.
BOUND_L_N) <<
"Could not get starting value for local Lipschitz constant, using L_nm1 (L_n = " << L_nm1 <<
")";
269 L_nm1 = iteration.
L_n;
272 float delta_nm1 = iteration.
delta_n;
273 bool condition =
false;
280 LOG_IF(FATAL, std::isinf(iteration.
L_n) || std::isnan(iteration.
L_n))
281 <<
"Could not find the local Lipschitz constant - L_n = "
282 << iteration.
L_n << std::endl;
283 LOG_IF(INFO, l > 0 && l%1000 == 0)
284 <<
"Having a hard time finding the local Lipschitz constant (L_n = " << iteration.
L_n
285 <<
"; L_nm1 = " << L_nm1 <<
"; eta = " <<
options_.
eta <<
"; l = " << l <<
")" << std::endl;
288 float beta = (b - 1)/(b - 1.f/2.f);
296 float alpha = 2*(1 - iteration.
beta_n)/(iteration.
L_n);
299 <<
"Cannot choose alpha_n - it does not exist: c_1 = "
301 <<
" (L_n = " << iteration.
L_n <<
")!";
312 if (iteration.
delta_n < delta_nm1
338 iteration.
x_n = x_np1;
345 LOG_IF(FATAL, iteration.
x_n.rows() != iteration.
df_x_n.rows()
346 || iteration.
x_n.cols() != iteration.
df_x_n.cols()) <<
"Output dimensions of df invalid.";
357 x_star = iteration.
x_n;
358 f_x_star = iteration.
f_x_n;
376 LOG_IF(FATAL, iteration.
x_n.rows() != iteration.
df_x_n.rows()
377 || iteration.
x_n.cols() != iteration.
df_x_n.cols()) <<
"Output dimensions of df invalid.";
388 if (iteration.
df_x_n.squaredNorm() > 0.001)
390 iteration.
L_n = std::max(iteration.
L_n, estimateL(iteration));
400 float alpha = 2*(1 - iteration.
beta_n)/(iteration.
L_n);
403 <<
"Cannot choose alpha_n - it does not exist: c_1 = "
405 <<
" (L_n = " << iteration.
L_n <<
")!";
float L_n
L_n of current iterate (within iterations, this is also used to estimate L_np1 via backtracking)...
Definition: nmipiano.h:98
void initialize(Iteration &iteration)
Initialize the iteration structure (i.e. set iteration 0):
Definition: ipiano.h:365
std::function< float(const Eigen::MatrixXf &)> g_
Convex, nonsmooth part of objective.
Definition: nmipiano.h:182
float f_x_n
Smooth objective function at current iterate.
Definition: nmipiano.h:92
void optimize(Eigen::MatrixXf &x_star, float &f_x_star)
Optimize the given objective using the iPiano algorithm.
Definition: ipiano.h:249
Implementation of nmiPiano (algorithm 4) as proposed in [1]: [1] P. Ochs, Y. Chen, T. Brox, T. Pock. iPiano: Inertial Proximal Algorithm for Nonconvex Optimization. SIAM J. Imaging Sciences, vol. 7, no. 2, 2014.
Definition: nmipiano.h:56
int n
Current iteration.
Definition: nmipiano.h:102
Options of algorithm.
Definition: ipiano.h:63
iPiano(const std::function< float(const Eigen::MatrixXf &)> f, const std::function< void(const Eigen::MatrixXf &, Eigen::MatrixXf &)> df, std::function< float(const Eigen::MatrixXf &)> g, const std::function< void(const Eigen::MatrixXf &, Eigen::MatrixXf &, float alpha)> prox_g, Options options, const std::function< void(const Iteration &)> callback=[](const Iteration &iteration) -> void{})
Constructor.
Definition: ipiano.h:224
Structure representing an iteration, passed as is to a callback function to be able to monitor proces...
Definition: ipiano.h:77
float epsilon
Termination criterion; stop if Delta_n smaller than epsilon.
Definition: nmipiano.h:76
int steps
Number of dicsrete steps for alpha_n and beta_n to try.
Definition: ipiano.h:72
Eigen::MatrixXf df_x_n
Derivative of smooth objective at current iterate.
Definition: nmipiano.h:94
float c_2
Fixed c_2.
Definition: ipiano.h:70
float eta
Fixed eta for backtracking the local lipschitz constant.
Definition: nmipiano.h:70
float gamma_n
gamma_n of current iterate (within iterations, this is also used to estimate gamma_np1).
Definition: ipiano.h:84
std::function< void(const Eigen::MatrixXf &, Eigen::MatrixXf &)> df_
Gradient of smooth part of the objective function (i.e. derivative).
Definition: nmipiano.h:180
~iPiano()
Destructor.
Definition: ipiano.h:240
void iterate(Iteration &iteration, float beta, Eigen::MatrixXf &x_np1)
Do an iteration, i.e. compute x_np1.
Definition: nmipiano.h:425
float beta_n
beta_n of current iterate (within iterations, this is also used to estimate beta_np1).
Definition: ipiano.h:80
Eigen::MatrixXf x_nm1
Last iterate.
Definition: nmipiano.h:86
static void brief_callback(const Iteration &iteration, int n=10)
Brief callback to use with iPiano.
Definition: ipiano.h:178
float alpha_n
alpha_n of current iterate (within iterations, this is also used to estimate alpha_np1).
Definition: nmipiano.h:100
bool checkLipschitz(const Iteration &iteration, const Eigen::MatrixXf &x_np1)
Check the lipschitz condition for backtracking.
Definition: nmipiano.h:443
float g_x_n
Definition: nmipiano.h:96
Eigen::MatrixXf x_0
Initial iterate.
Definition: nmipiano.h:64
static void silent_callback(const Iteration &iteration)
Silent callback to use with iPiano.
Definition: ipiano.h:153
unsigned int max_iter
Maximum number of iterations.
Definition: nmipiano.h:66
static void plot_callback(const Iteration &iteration, const std::string &file)
File callback for plotting, writes CSV output of format: iteration,f,g,alpha_n,beta_n,L_n,Delta_n.
Definition: ipiano.h:209
float c_1
Fixed c_1.
Definition: ipiano.h:68
static void file_callback(const Iteration &iteration, const std::string &file)
File callback, used to write all information to the specified file.
Definition: ipiano.h:193
std::function< float(const Eigen::MatrixXf &)> f_
The smooth part of the objective function.
Definition: nmipiano.h:178
Implementation of iPiano (algorithm 5) as proposed in [1]: [1] P. Ochs, Y. Chen, T. Brox, T. Pock. iPiano: Inertial Proximal Algorithm for Nonconvex Optimization. SIAM J. Imaging Sciences, vol. 7, no. 2, 2014.
Definition: ipiano.h:58
std::function< void(const Iteration &)> callback_
Callback, note: overwrites nmiPiano::callback_!
Definition: ipiano.h:144
float Delta_n
Difference between two iterates.
Definition: nmipiano.h:90
Options of algorithm.
Definition: nmipiano.h:61
Eigen::MatrixXf x_n
Current iterate.
Definition: nmipiano.h:84
float delta_n
delta_n of current iterate (within iterations, this is also used to estimate delta_np1).
Definition: ipiano.h:82
float L_0m1
Initialization of loca Lipschitz.
Definition: nmipiano.h:72
float beta_0m1
beta_0m1 to initialize alpha_0m1, delta_0m1 and gamma_0m1 according to Equations (21) and (22)...
Definition: ipiano.h:66
bool BOUND_L_N
Whether to bound estimated Lipschitz constant below by the given L_n.
Definition: nmipiano.h:74
Options options_
Options (note: overwrites nmiPiano::options_!).
Definition: ipiano.h:146
Structure representing an iteration, passed as is to a callback function to be able to monitor proces...
Definition: nmipiano.h:81
static void default_callback(const Iteration &iteration, int n=10)
Default callback to use with iPiano.
Definition: ipiano.h:162