Commit 8c831c18 authored by David Frank's avatar David Frank
Browse files

Concise logging output for couple of solvers

For each iterator the output will now also output the time took for the
iteration and the aggregated time from the start of the solver. Also
some information, which doesn't change are written once and not again.
parent 9d79319f
Pipeline #847389 passed with stages
in 38 minutes and 48 seconds
#include "CG.h"
#include "Logger.h"
#include "TypeCasts.hpp"
#include "spdlog/stopwatch.h"
namespace elsa
{
......@@ -33,6 +34,8 @@ namespace elsa
if (iterations == 0)
iterations = _defaultIterations;
spdlog::stopwatch aggregate_time;
// get references to some variables in the Quadric
auto& x = _problem->getCurrentSolution();
const auto& gradientExpr =
......@@ -61,11 +64,15 @@ namespace elsa
auto deltaNew = r.dot(d);
auto deltaZero = deltaNew;
Logger::get("CG")->info("epsilon: {}", _epsilon);
Logger::get("CG")->info("delta zero: {}", std::sqrt(deltaZero));
// log history legend
Logger::get("CG")->info("{:*^20}|{:*^20}|{:*^20}|{:*^20}|{:*^20}", "iteration", "deltaNew",
"deltaZero", "epsilon", "objval");
Logger::get("CG")->info("{:^6}|{:*^16}|{:*^16}|{:*^8}|{:*^8}|", "iter", "deltaNew",
"deltaZero", "time", "elapsed");
for (index_t it = 0; it != iterations; ++it) {
spdlog::stopwatch iter_time;
auto Ad = A ? A->apply(d) : d;
data_t alpha = deltaNew / d.dot(Ad);
......@@ -88,8 +95,8 @@ namespace elsa
objVal = static_cast<data_t>(-0.5) * x.dot(*b + r);
}
Logger::get("CG")->info(" {:<19}| {:<19}| {:<19}| {:<19}| {:<19}", it,
std::sqrt(deltaNew), std::sqrt(deltaZero), _epsilon, objVal);
Logger::get("CG")->info("{:>5} |{:>15} |{:>15} | {:>6.3} |{:>6.3}s |", it,
std::sqrt(deltaNew), objVal, iter_time, aggregate_time);
if (deltaNew <= _epsilon * _epsilon * deltaZero) {
// check that we are not stopping prematurely due to accumulated roundoff error
......
#include "FISTA.h"
#include "SoftThresholding.h"
#include "Logger.h"
#include <Logger.h>
#include "spdlog/stopwatch.h"
namespace elsa
{
......@@ -32,6 +33,8 @@ namespace elsa
if (iterations == 0)
iterations = _defaultIterations;
spdlog::stopwatch aggregate_time;
SoftThresholding<data_t> shrinkageOp{getCurrentSolution().getDataDescriptor()};
data_t lambda = _problem->getRegularizationTerms()[0].getWeight();
......@@ -52,9 +55,12 @@ namespace elsa
DataContainer<data_t> Atb = A.applyAdjoint(b);
DataContainer<data_t> gradient = A.applyAdjoint(A.apply(yPrev)) - Atb;
Logger::get("FISTA")->info("{:^6}|{:*^16}|{:*^8}|{:*^8}|", "iter", "gradient", "time",
"elapsed");
auto deltaZero = gradient.squaredL2Norm();
for (index_t iter = 0; iter < iterations; ++iter) {
Logger::get("FISTA")->info("iteration {} of {}", iter + 1, iterations);
spdlog::stopwatch iter_time;
gradient = A.applyAdjoint(A.apply(yPrev)) - Atb;
x = shrinkageOp.apply(yPrev - _mu * gradient, geometry::Threshold{_mu * lambda});
......@@ -66,6 +72,9 @@ namespace elsa
yPrev = y;
tPrev = t;
Logger::get("FISTA")->info("{:>5} |{:>15} | {:>6.3} |{:>6.3}s |", iter,
gradient.squaredL2Norm(), iter_time, aggregate_time);
if (gradient.squaredL2Norm() <= _epsilon * _epsilon * deltaZero) {
Logger::get("FISTA")->info("SUCCESS: Reached convergence at {}/{} iteration",
iter + 1, iterations);
......
#include "ISTA.h"
#include "SoftThresholding.h"
#include "TypeCasts.hpp"
#include "Logger.h"
#include <Logger.h>
#include "spdlog/stopwatch.h"
namespace elsa
{
......@@ -31,6 +32,8 @@ namespace elsa
if (iterations == 0)
iterations = _defaultIterations;
spdlog::stopwatch aggregate_time;
SoftThresholding<data_t> shrinkageOp{getCurrentSolution().getDataDescriptor()};
data_t lambda = _problem->getRegularizationTerms()[0].getWeight();
......@@ -45,14 +48,19 @@ namespace elsa
DataContainer<data_t> Atb = A.applyAdjoint(b);
DataContainer<data_t> gradient = A.applyAdjoint(A.apply(x)) - Atb;
Logger::get("ISTA")->info("{:^6}|{:*^16}|{:*^8}|{:*^8}|", "iter", "gradient", "time",
"elapsed");
auto deltaZero = gradient.squaredL2Norm();
for (index_t iter = 0; iter < iterations; ++iter) {
Logger::get("ISTA")->info("iteration {} of {}", iter + 1, iterations);
spdlog::stopwatch iter_time;
gradient = A.applyAdjoint(A.apply(x)) - Atb;
x = shrinkageOp.apply(x - _mu * gradient, geometry::Threshold{_mu * lambda});
Logger::get("ISTA")->info("{:>5} |{:>15} | {:>6.3} |{:>6.3}s |", iter,
gradient.squaredL2Norm(), iter_time, aggregate_time);
if (gradient.squaredL2Norm() <= _epsilon * _epsilon * deltaZero) {
Logger::get("ISTA")->info("SUCCESS: Reached convergence at {}/{} iteration",
iter + 1, iterations);
......
Markdown is supported
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