smooth
A C++ library for Lie theory
Loading...
Searching...
No Matches
tr_strategy.hpp
1// Copyright (C) 2023 Petter Nilsson. MIT License.
2
3#pragma once
4
5#include <algorithm>
6
7#include "smooth/version.hpp"
8
9SMOOTH_BEGIN_NAMESPACE
10
12{
13public:
14 virtual ~TrustRegionStrategy() = default;
16 virtual double get_delta() const = 0;
18 virtual bool step_and_update(const double rho) = 0;
19};
20
27{
28public:
29 inline double get_delta() const override { return m_delta; }
30 inline bool step_and_update(const double rho) override
31 {
32 if (rho > 1e-3) {
33 const double two_rho_min_1 = 2 * rho - 1;
34 m_delta /= std::max(1. / 3, 1 - two_rho_min_1 * two_rho_min_1 * two_rho_min_1);
35 m_reduce = 2;
36 return true;
37 } else {
38 m_delta /= m_reduce;
39 m_reduce *= 2;
40 return false;
41 }
42 }
43
44private:
45 double m_delta{10000};
46 double m_reduce{2};
47};
48
55{
56public:
57 inline double get_delta() const override { return m_delta; }
58
59 inline bool step_and_update(const double rho) override
60 {
61 if (rho > 0) {
62 m_delta = 1000;
63 return true;
64 } else {
65 m_delta /= 10;
66 return false;
67 }
68 }
69
70private:
71 double m_delta{1000};
72};
73
74SMOOTH_END_NAMESPACE
Trust region strategy used in the Ceres solver.
bool step_and_update(const double rho) override
Update trust region and determine if step is taken.
double get_delta() const override
Get trust region size.
Trust region strategy used in:
bool step_and_update(const double rho) override
Update trust region and determine if step is taken.
double get_delta() const override
Get trust region size.
virtual bool step_and_update(const double rho)=0
Update trust region and determine if step is taken.
virtual double get_delta() const =0
Get trust region size.