tinyopt 700
Tinyopt, a lightweight, header only optimization library
Loading...
Searching...
No Matches
tinyopt::Summary Struct Reference

Classes

struct  History

Public Types

using Scalar = double

Public Member Functions

bool Succeeded () const
 Returns true if the stop reason is not a failure to solve or NaNs or missing residuals.
bool Converged () const
 Returns true if the optimization reached the specified minimal error, delta or gradient.
template<typename M = MatX>
std::optional< M > Covariance (bool rescaled=false) const
 Computes an approximation of the covariance matrix.
bool has_final_hessian () const
const auto & final_hessian_dense () const
const auto & final_hessian_sparse () const

Public Attributes

Cost final_cost = Cost(std::numeric_limits<Scalar>::max(), 0)
 Last valid error.
Scalar final_rerr_dec = std::numeric_limits<Scalar>::max()
StopReason stop_reason = StopReason::kNone
 Stop reason.
Statistics
uint16_t num_residuals = 0
 Final number of residuals.
uint16_t num_iters = 0
 Final number of iterations.
uint8_t num_failures = 0
 Final number of failures to decrease the error.
uint8_t num_consec_failures
 Final number of the last consecutive failures to decrease the error.
TimePoint start_time
float duration_ms = 0
 Cumulated optimization duration.
std::variant< std::monostate, MatX, SparseMat > final_hessian
 Final H, excluding any damping (only saved if options.hessian.save = true).
bool num_diff_used = false
 True if numerical derivatives were used.
Per iteration results
struct tinyopt::Summary::History hist

Member Function Documentation

◆ Covariance()

template<typename M = MatX>
std::optional< M > tinyopt::Summary::Covariance ( bool rescaled = false) const
inline

Computes an approximation of the covariance matrix.

This method calculates the covariance matrix, which is an approximation derived from the inverse of the Hessian matrix (H).

It is only meaningful at convergence, right Johan?

Parameters
rescaled(optional) If true, the covariance matrix is rescaled by ε² / (#ε - dims), where ε² is the sum of squared residuals (final_cost²), #ε is the number of residuals (num_residuals), and dims is the number of parameters (H.cols()). This rescaling is useful when observations lack explicit noise modeling and provides a more accurate estimate of the covariance. Defaults to false.
Returns
std::optional<H_t> Returns the computed covariance matrix if H is invertible, wrapped in a std::optional. Returns std::nullopt if H is not invertible, indicating that the covariance cannot be estimated.

The covariance matrix is calculated as:

  • If rescaled is false: (H)^-1
  • If rescaled is true and num_residuals > H.cols(): (H)^-1 * (ε² / (#ε - dims))

Where:

  • H is the approximated Hessian matrix.
  • ε (final_cost) is the sum of residuals.
  • #ε (num_residuals) is the number of residuals.
  • dims (H.cols()) is the number of parameters.

The rescaling is applied only when the number of residuals exceeds the number of parameters, indicating an overdetermined system. This rescaling provides a more statistically sound estimate of the covariance in such scenarios, especially when noise modeling was not explicitly included in the observations.

Note
The function relies on the InvCov(H) method to compute the inverse of H. If InvCov returns std::nullopt, indicating that H is not invertible, this method also returns std::nullopt.
Template Parameters
H_tThe type of the covariance matrix.

Member Data Documentation

◆ num_consec_failures

uint8_t tinyopt::Summary::num_consec_failures
Initial value:
=
0

Final number of the last consecutive failures to decrease the error.

◆ start_time

TimePoint tinyopt::Summary::start_time
Initial value:
=
TimePoint::min()

Starting time of the optimization or std::chrono::system_clock::time_point::min() if not started


The documentation for this struct was generated from the following file: