|
|
| Optimizer_ (const Options &_options={}) |
|
template<int FO = SolverType::FirstOrder, std::enable_if_t<!FO, int > = 0> |
| void | InitWith (const auto &g, const auto &h) |
| | Initialize solver with specific gradient and hessian.
|
|
template<int FO = SolverType::FirstOrder, std::enable_if_t< FO, int > = 0> |
| void | InitWith (const auto &g) |
| | Initialize solver with specific gradient.
|
|
void | reset () |
| | Reset the optimization and solver.
|
|
template<typename X_t> |
| std::variant< StopReason, bool > | ResizeIfNeeded (X_t &x) |
template<typename T, typename U, typename... Rest, typename Func>
requires (!std::is_same_v<std::remove_cvref_t<Func>, Options>) |
| Summary | Optimize (T &x, U &y, Rest &...rest, const Func &cost_or_acc) |
| | Performs optimization on the given parameters x using the provided cost or accumulation function cost_or_acc.
|
|
template<typename X_t, typename CostOrAccFunc> |
| Summary | Optimize (X_t &x, const CostOrAccFunc &cost_or_acc, int max_iters=-1) |
template<typename T, typename U, typename... Rest, typename Func>
requires (!std::is_same_v<std::remove_cvref_t<Func>, tinyopt::Options>) |
| Summary | operator() (T &x, U &y, Rest &...rest, const Func &cost_or_acc, int max_iters=-1) |
| | Performs optimization on the given parameters x using the provided cost or accumulation function cost_or_acc. See Optimize for more informations.
|
|
template<typename X_t, typename CostOrAccFunc> |
| Summary | operator() (X_t &x, const CostOrAccFunc &cost_or_acc, int max_iters=-1) |
| template<typename X_t, typename AccFunc> |
| Summary | OptimizeAcc (X_t &x, const AccFunc &acc, int max_iters=-1) |
| | Performs optimization on the given parameters x using the provided accumulation function acc.
|
| template<typename X_t, typename AccFunc> |
| std::pair< bool, std::optional< Vector< Scalar, Dims > > > | Step (X_t &x, const AccFunc &acc, Summary &sum) |
|
SolverType & | solver () |
|
const SolverType & | solver () const |
template<typename SolverType>
template<typename T, typename U, typename... Rest, typename Func>
requires (!std::is_same_v<std::remove_cvref_t<Func>, Options>)
Performs optimization on the given parameters x using the provided cost or accumulation function cost_or_acc.
This function is the primary interface for optimization within the library. It takes the variable to be optimized and a function (or functor) that calculates the cost function, its gradient, and optionally its Hessian. The optimization process attempts to find a value of x that minimizes the objective function.
- Template Parameters
-
| X_t | The type of the parameters x. This can be a scalar, a vector, or a more complex data structure (e.g., a matrix). The type must support the necessary arithmetic operations for the chosen optimization algorithm. |
| CostOrAccFunc | The type of the cost or accumulation function cost_or_acc. This can be a function pointer, a lambda expression, or a functor (an object that overloads the operator()). |
- Parameters
-
| x | The variable to be optimized. This is passed by reference, and the function will modify x in place to store the optimized value. |
| cost_or_acc | The cost or accumulation function. This function calculates the cost function and, optionally, its derivatives. The cost_or_acc function can have one of the following signatures:
- ResidualsType(const X_t& x): Only the cost function is calculated. In this case, the library will use automatic differentiation (if available and enabled) or numerical differentiation to estimate the gradient.
- ScalarCost(const X_t& x, GradientType grad): An accumulation function where the user must fill the gradient and return the final cost (scalar or scalar+number of residuals)
- ScalarCost(const X_t& x, GradientType grad, HessianType H): An accumulation function where the user must fill the gradient and Hessian and return the final cost (scalar or scalar+number of residuals)
|
The GradientType and HessianType will be deduced from the type of x. They can also be nullptr_t.
- ResidualsType is a scalar or Vector/Matrix of residuals (for NLLS).
- ScalarCost is the total cost/error or a pair (cost, number of residuals).
- Parameters
-
| max_iters | The maximum number of iterations to perform. If this is negative (the default), the optimization algorithm will run until a convergence criterion is met. A positive value limits the number of iterations, which can be useful for preventing infinite loops or for controlling the execution time. |
- Note
- If the cost_or_acc function only provides the cost function or residuals function, the library will automatically compute the gradient (and approx. Hessian) using either automatic differentiation (if available and enabled) or numerical differentiation. Automatic differentiation is generally more accurate and efficient, but numerical differentiation can be used as a fallback or when automatic differentiation is not supported.
template<typename SolverType>
template<typename X_t, typename AccFunc>
Performs optimization on the given parameters x using the provided accumulation function acc.
This function is the primary interface for optimization within the library when the user manually updates the Gradient (and Hessian, if any). The optimization process attempts to find a value of x that minimizes the objective function.
- Template Parameters
-
| X_t | The type of the parameters x. This can be a scalar, a vector, or a more complex data structure (e.g., a matrix). The type must support the necessary arithmetic operations for the chosen optimization algorithm. |
| AccFunc | The type of the accumulation function acc. This can be a function pointer, a lambda expression, or a functor (an object that overloads the operator()). |
- Parameters
-
| x | The variable to be optimized. This is passed by reference, and the function will modify x in place to store the optimized value. |
| acc | The accumulation function. This function returns the total cost must update the gradient(and Hessian, if any). The acc function must have one of the following signatures:
- ScalarCost(const X_t& x, GradientType grad): An accumulation function where the user must fill the gradient and return the final cost (scalar or scalar+number of residuals)
- ScalarCost(const X_t& x, GradientType grad, HessianType H): An accumulation function where the user must fill the gradient and Hessian and return the final cost (scalar or scalar+number of residuals)
|
The GradientType and HessianType will be deduced from the type of x. They can also be nullptr_t.
- ResidualsType is a scalar or Vector/Matrix of residuals (for NLLS).
- ScalarCost is the total cost/error or a pair (cost, number of residuals).
- Parameters
-
| max_iters | The maximum number of iterations to perform. If this is negative (the default), the optimization algorithm will run until a convergence criterion is met. A positive value limits the number of iterations, which can be useful for preventing infinite loops or for controlling the execution time. |