-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regularization and step size to diagnostics
- Loading branch information
Showing
5 changed files
with
71 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Sleipnir contributors | ||
|
||
#pragma once | ||
|
||
#include <chrono> | ||
#include <cmath> | ||
|
||
#include "sleipnir/util/Print.hpp" | ||
#include "util/ToMilliseconds.hpp" | ||
|
||
namespace sleipnir { | ||
|
||
/** | ||
* Prints diagnostics for the current iteration. | ||
* | ||
* @param iterations Number of iterations. | ||
* @param feasibilityRestoration Whether solver is in feasibility restoration | ||
* mode. | ||
* @param time The iteration duration. | ||
* @param error The error. | ||
* @param cost The cost. | ||
* @param infeasibility The infeasibility. | ||
* @param δ The Hessian regularization factor. | ||
* @param α The step size. | ||
*/ | ||
template <typename Rep, typename Period = std::ratio<1>> | ||
void PrintIterationDiagnostics(int iterations, bool feasibilityRestoration, | ||
const std::chrono::duration<Rep, Period>& time, | ||
double error, double cost, double infeasibility, | ||
double δ, double α) { | ||
if (iterations % 20 == 0) { | ||
sleipnir::println("{:^4} {:^9} {:^13} {:^13} {:^13} {:^8} {:^8}", | ||
"iter", "time (ms)", "error", "cost", "infeasibility", | ||
"log10(δ)", "-log2(α)"); // NOLINT | ||
sleipnir::println("{:=^81}", ""); | ||
} | ||
|
||
sleipnir::print("{:4}{} {:9.3f} {:13e} {:13e} {:13e} ", iterations, | ||
feasibilityRestoration ? "r" : " ", ToMilliseconds(time), | ||
error, cost, infeasibility); | ||
|
||
if (δ > 0.0) { | ||
sleipnir::print("{:8.2f} ", std::log10(δ)); | ||
} else { | ||
sleipnir::print("{:>8} ", "-∞"); | ||
} | ||
|
||
sleipnir::println("{:8d}", static_cast<int>(-std::log2(α))); | ||
} | ||
|
||
} // namespace sleipnir |