Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
Greenstadt.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2 * Copyright (c) 2025, Davide Stocco and Enrico Bertolazzi. *
3 * *
4 * The Optimist project is distributed under the BSD 2-Clause License. *
5 * *
6 * Davide Stocco Enrico Bertolazzi *
7 * University of Trento University of Trento *
8 * davide.stocco@unitn.it enrico.bertolazzi@unitn.it *
9\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
10
11#pragma once
12
13#ifndef OPTIMIST_ROOTFINDER_GREENSTADT_HH
14#define OPTIMIST_ROOTFINDER_GREENSTADT_HH
15
17
18namespace Optimist {
19 namespace RootFinder {
20
21 /*\
22 | ____ _ _ _
23 | / ___|_ __ ___ ___ _ __ ___| |_ __ _ __| | |_
24 | | | _| '__/ _ \/ _ \ '_ \/ __| __/ _` |/ _` | __|
25 | | |_| | | | __/ __/ | | \__ \ || (_| | (_| | |_
26 | \____|_| \___|\___|_| |_|___/\__\__,_|\__,_|\__|
27 |
28 \*/
29
37 template <typename Vector>
38 requires TypeTrait<Vector>::IsEigen &&
39 (!TypeTrait<Vector>::IsFixed || TypeTrait<Vector>::Dimension > 0)
40 class Greenstadt : public QuasiNewton<Vector, Greenstadt<Vector>> {
41 public:
42 static constexpr bool RequiresFunction{true};
43 static constexpr bool RequiresFirstDerivative{true};
44 static constexpr bool RequiresSecondDerivative{false};
45
49
51
52
55 using Method = enum class Method : Integer {
56 ONE = 1,
57 TWO = 2
58 };
59
60 private:
61 Method m_method{Method::ONE};
62
63 public:
68
73 constexpr std::string name_impl() const {
74 return "Greenstadt";
75 }
76
81 Method method() const {
82 return this->m_method;
83 }
84
89 void method(Method t_method) {
90 this->m_method = t_method;
91 }
92
97 this->m_method = Method::ONE;
98 }
99
104 this->m_method = Method::TWO;
105 }
106
111 void set_method(Method t_method) {
112 this->m_method = t_method;
113 }
114
125 void update_impl(const Vector & /*delta_x_old*/,
126 const Vector & /*delta_function_old*/,
127 const FirstDerivative &jacobian_old,
128 const Vector &delta_x_new,
129 const Vector &delta_function_new,
130 const Vector &function_new,
131 FirstDerivative &jacobian_new) {
132 if (this->m_method == Method::ONE) {
133 // Greenstadt's 1st method
134 // J1 = J0 - (J0*DF1-DX1)/(C'*DF1)*C', where C = F1;
135 jacobian_new =
136 jacobian_old - (jacobian_old * delta_function_new - delta_x_new) /
137 (function_new.dot(delta_function_new)) *
138 function_new.transpose();
139 } else if (this->m_method == Method::TWO) {
140 // Greenstadt's 2nd method
141 // J1 = J0 - (J0*DF1-DX1)/(C'*DF1)*C', where C = J0'*J0*DF1;
142 Vector C(jacobian_old.transpose() * jacobian_old *
143 delta_function_new);
144 jacobian_new =
145 jacobian_old - (jacobian_old * delta_function_new - delta_x_new) /
146 (C.dot(delta_function_new)) * C.transpose();
147 }
148 }
149
150 }; // class Greenstadt
151
152 } // namespace RootFinder
153
154} // namespace Optimist
155
156#endif // OPTIMIST_ROOTFINDER_GREENSTADT_HH
#define OPTIMIST_BASIC_CONSTANTS(Scalar)
Definition Optimist.hh:70
constexpr std::string name_impl() const
Definition Greenstadt.hh:73
enum class Method :Integer { ONE=1, TWO=2 } Method
Definition Greenstadt.hh:55
Method method() const
Definition Greenstadt.hh:81
static constexpr bool RequiresSecondDerivative
Definition Greenstadt.hh:44
void enable_two_method()
Definition Greenstadt.hh:103
static constexpr bool RequiresFunction
Definition Greenstadt.hh:42
void update_impl(const Vector &, const Vector &, const FirstDerivative &jacobian_old, const Vector &delta_x_new, const Vector &delta_function_new, const Vector &function_new, FirstDerivative &jacobian_new)
Definition Greenstadt.hh:125
void set_method(Method t_method)
Definition Greenstadt.hh:111
void enable_one_method()
Definition Greenstadt.hh:96
typename TypeTrait< Vector >::Scalar Scalar
Definition Greenstadt.hh:47
TypeTrait< Vector > VectorTrait
Definition Greenstadt.hh:46
Method m_method
Definition Greenstadt.hh:61
Greenstadt()
Definition Greenstadt.hh:67
void method(Method t_method)
Definition Greenstadt.hh:89
static constexpr bool RequiresFirstDerivative
Definition Greenstadt.hh:43
std::conditional_t< InputTrait::IsEigen||OutputTrait::IsEigen, std::conditional_t< InputTrait::IsSparse||OutputTrait::IsSparse, Eigen::SparseMatrix< Scalar >, Eigen::Matrix< Scalar, OutputTrait::Dimension, InputTrait::Dimension > >, Scalar > FirstDerivative
Definition SolverBase.hh:80
Namespace for the Optimist library.
Definition Optimist.hh:90
OPTIMIST_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Optimist.hh:98
Definition Optimist.hh:114