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, Mattia Piazza and Enrico Bertolazzi. *
3 * *
4 * The Optimist project is distributed under the BSD 2-Clause License. *
5 * *
6 * Davide Stocco Mattia Piazza Enrico Bertolazzi *
7 * University of Trento University of Trento University of Trento *
8 * davide.stocco@unitn.it mattia.piazza@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{
20 namespace RootFinder
21 {
22
23 /*\
24 | ____ _ _ _
25 | / ___|_ __ ___ ___ _ __ ___| |_ __ _ __| | |_
26 | | | _| '__/ _ \/ _ \ '_ \/ __| __/ _` |/ _` | __|
27 | | |_| | | | __/ __/ | | \__ \ || (_| | (_| | |_
28 | \____|_| \___|\___|_| |_|___/\__\__,_|\__,_|\__|
29 |
30 \*/
31
40 template <typename Real, Integer N>
41 class Greenstadt : public QuasiNewton<Real, N, Greenstadt<Real, N>>
42 {
43 public:
44 static constexpr bool requires_function{true};
45 static constexpr bool requires_first_derivative{true};
46 static constexpr bool requires_second_derivative{false};
47
49
50 using Method = enum class Method : Integer {ONE = 1, TWO = 2};
56
57 private:
58 Method m_method{Method::ONE};
59
60 public:
65
70 std::string name_impl() const
71 {
72 std::ostringstream os;
73 os << "Greenstadt";
74 if (this->m_method == Method::ONE) {
75 os << "1";
76 } else if (this->m_method == Method::TWO) {
77 os << "2";
78 }
79 return os.str();
80 }
81
86 Method method() const {return this->m_method;}
87
92 void method(Method t_method) {this->m_method = t_method;}
93
97 void enable_one_method() {this->m_method = Method::ONE;}
98
102 void enable_two_method() {this->m_method = Method::TWO;}
103
108 void set_method(Method t_method) {this->m_method = t_method;}
109
121 Vector const & /*delta_x_old*/, Vector const & /*delta_function_old*/, Matrix const & jacobian_old,
122 Vector const & delta_x_new, Vector const & delta_function_new, Vector const & function_new,
123 Matrix & jacobian_new
124 ) {
125 if (this->m_method == Method::ONE) {
126 // Greenstadt's 1st method
127 // J1 = J0 - (J0*DF1-DX1)/(C'*DF1)*C', where C = F1;
128 jacobian_new = jacobian_old - (jacobian_old*delta_function_new-delta_x_new)/(function_new.transpose()*delta_function_new)*function_new.transpose();
129 } else if (this->m_method == Method::TWO) {
130 // Greenstadt's 2nd method
131 // J1 = J0 - (J0*DF1-DX1)/(C'*DF1)*C', where C = J0'*J0*DF1;
132 Vector C(jacobian_old.transpose()*jacobian_old*delta_function_new);
133 jacobian_new = jacobian_old - (jacobian_old*delta_function_new-delta_x_new)/(C.transpose()*delta_function_new)*C.transpose();
134 }
135 }
136
137 }; // class Greenstadt
138
139 } // namespace RootFinder
140
141} // namespace Optimist
142
143#endif // OPTIMIST_ROOTFINDER_GREENSTADT_HH
#define OPTIMIST_BASIC_CONSTANTS(Real)
Definition Optimist.hh:70
typename QuasiNewton< Real, N, Greenstadt< Real, N > >::Matrix Matrix
Definition Greenstadt.hh:52
void enable_two_method()
Definition Greenstadt.hh:102
typename QuasiNewton< Real, N, Greenstadt< Real, N > >::Vector Vector
Definition Greenstadt.hh:51
void method(Method t_method)
Definition Greenstadt.hh:92
Method method() const
Definition Greenstadt.hh:86
enum class Method :Integer {ONE=1, TWO=2} Method
Definition Greenstadt.hh:50
typename QuasiNewton< Real, N, Greenstadt< Real, N > >::JacobianWrapper JacobianWrapper
Definition Greenstadt.hh:54
typename QuasiNewton< Real, N, Greenstadt< Real, N > >::FunctionWrapper FunctionWrapper
Definition Greenstadt.hh:53
std::string name_impl() const
Definition Greenstadt.hh:70
void set_method(Method t_method)
Definition Greenstadt.hh:108
static constexpr bool requires_function
Definition Greenstadt.hh:44
static constexpr bool requires_first_derivative
Definition Greenstadt.hh:45
void enable_one_method()
Definition Greenstadt.hh:97
void update_impl(Vector const &, Vector const &, Matrix const &jacobian_old, Vector const &delta_x_new, Vector const &delta_function_new, Vector const &function_new, Matrix &jacobian_new)
Definition Greenstadt.hh:120
Greenstadt()
Definition Greenstadt.hh:64
static constexpr bool requires_second_derivative
Definition Greenstadt.hh:46
Method m_method
Definition Greenstadt.hh:58
bool solve(FunctionWrapper function, Vector const &x_ini, Vector &x_sol)
Definition RootFinder.hh:164
Namespace for the Optimist library.
Definition Optimist.hh:87
OPTIMIST_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Optimist.hh:95