Commit 75754761 authored by Max Lyon's avatar Max Lyon
Browse files

allow user to change verbosity of Newton Solver

parent 4a4f973f
Pipeline #12387 passed with stages
in 6 minutes and 40 seconds
......@@ -78,8 +78,6 @@ public:
// print result
virtual void store_result ( const double* _x )
{
std::cerr << "Energy: " << eval_f(_x) << std::endl;
std::cerr << "(x,y) = (" << _x[0] << "," << _x[1] << ")" << std::endl;
solution.resize(n_unknowns());
for (int i = 0; i < n_unknowns(); ++i)
solution[i] = _x[i];
......@@ -116,6 +114,7 @@ int main(void)
std::cout << "---------- 3) Solve with Newton Solver..." << std::endl;
COMISO::NewtonSolver nsolver;
nsolver.set_verbosity(15);
nsolver.solve(&problem, A, b);
std::cout << "---------- 4) Print solution..." << std::endl;
......
......@@ -45,7 +45,7 @@ solve(NProblemGmmInterface* _problem)
// check for convergence
if( gmm::vect_norm2(g) < eps_)
{
DEB_line(2, "Newton Solver converged after " << i << " iterations");
DEB_line(verbosity_, "Newton Solver converged after " << i << " iterations");
_problem->store_result(P(x));
return true;
}
......@@ -79,7 +79,7 @@ solve(NProblemGmmInterface* _problem)
f = f_new;
improvement = true;
DEB_line(2, "energy improved to " << f);
DEB_line(verbosity_, "energy improved to " << f);
}
}
......@@ -96,14 +96,14 @@ solve(NProblemGmmInterface* _problem)
else
{
_problem->store_result(P(x));
DEB_line(2, "Newton solver reached max regularization but did not "
DEB_line(verbosity_, "Newton solver reached max regularization but did not "
"converge");
return false;
}
}
}
_problem->store_result(P(x));
DEB_line(2, "Newton Solver did not converge!!! after iterations.");
DEB_line(verbosity_, "Newton Solver did not converge!!! after iterations.");
return false;
#else
......@@ -119,7 +119,7 @@ solve(NProblemGmmInterface* _problem)
int NewtonSolver::solve(NProblemInterface* _problem, const SMatrixD& _A,
const VectorD& _b)
{
DEB_time_func_def;
DEB_time_func(verbosity_);
const double KKT_res_eps = 1e-6;
const int max_KKT_regularization_iters = 40;
......@@ -131,7 +131,7 @@ int NewtonSolver::solve(NProblemInterface* _problem, const SMatrixD& _A,
// number of constraints
size_t m = _b.size();
DEB_line(2, "optimize via Newton with " << n << " unknowns and " << m <<
DEB_line(verbosity_, "optimize via Newton with " << n << " unknowns and " << m <<
" linear constraints");
// initialize vectors of unknowns
......@@ -188,7 +188,7 @@ int NewtonSolver::solve(NProblemInterface* _problem, const SMatrixD& _A,
// alternate hessian and constraints regularization
if(reg_iters % 2 == 0 || regularize_constraints >= regularize_constraints_limit)
{
DEB_line(2, "residual ^ 2 " << kkt_res2 << "->regularize hessian");
DEB_line(verbosity_, "residual ^ 2 " << kkt_res2 << "->regularize hessian");
if(regularize_hessian == 0.0)
regularize_hessian = 1e-6;
else
......@@ -196,7 +196,7 @@ int NewtonSolver::solve(NProblemInterface* _problem, const SMatrixD& _A,
}
else
{
DEB_line(2, "residual^2 " << kkt_res2 << " -> regularize constraints");
DEB_line(verbosity_, "residual^2 " << kkt_res2 << " -> regularize constraints");
if(regularize_constraints == 0.0)
regularize_constraints = 1e-8;
else
......@@ -242,7 +242,7 @@ int NewtonSolver::solve(NProblemInterface* _problem, const SMatrixD& _A,
}
DEB_line(2, "iter: " << iter
DEB_line(verbosity_, "iter: " << iter
<< ", f(x) = " << fx << ", t = " << t << " (tmax=" << t_max << ")"
<< (t < t_max ? " _clamped_" : "")
<< ", eps = [Newton decrement] = " << newton_decrement
......
......@@ -58,7 +58,7 @@ public:
/// Default constructor
NewtonSolver(const double _eps = 1e-6, const double _eps_line_search = 1e-9, const int _max_iters = 200, const double _alpha_ls=0.2, const double _beta_ls = 0.6)
: eps_(_eps), eps_ls_(_eps_line_search), max_iters_(_max_iters), alpha_ls_(_alpha_ls), beta_ls_(_beta_ls), solver_type_(LS_EigenLU), constant_hessian_structure_(false)
: eps_(_eps), eps_ls_(_eps_line_search), max_iters_(_max_iters), alpha_ls_(_alpha_ls), beta_ls_(_beta_ls), verbosity_(2), solver_type_(LS_EigenLU), constant_hessian_structure_(false)
{
//#if COMISO_SUITESPARSE_AVAILABLE
// solver_type_ = LS_Umfpack;
......@@ -84,6 +84,10 @@ public:
solver_type_ = _st;
}
// set verbosity level of the solver. Lower numbers are more verbose
void set_verbosity(int _verbosity) { verbosity_ = _verbosity; }
protected:
bool factorize(NProblemInterface* _problem, const SMatrixD& _A,
......@@ -132,6 +136,7 @@ private:
int max_iters_;
double alpha_ls_;
double beta_ls_;
int verbosity_;
VectorD x_ls_;
......@@ -147,6 +152,7 @@ private:
Eigen::UmfPackLU<SMatrixD> umfpack_solver_;
#endif
// deprecated
bool constant_hessian_structure_;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment