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
52
56 using Method = enum class Method : Integer {ONE = 1, TWO = 2};
57
58 private:
59 Method m_method{Method::ONE};
60
61 public:
66
71 std::string name_impl() const
72 {
73 std::ostringstream os;
74 os << "Greenstadt";
75 if (this->m_method == Method::ONE) {
76 os << "1";
77 } else if (this->m_method == Method::TWO) {
78 os << "2";
79 }
80 return os.str();
81 }
82
87 Method method() const {return this->m_method;}
88
93 void method(Method t_method) {this->m_method = t_method;}
94
98 void enable_one_method() {this->m_method = Method::ONE;}
99
103 void enable_two_method() {this->m_method = Method::TWO;}
104
109 void set_method(Method t_method) {this->m_method = t_method;}
110
122 Vector const & /*delta_x_old*/, Vector const & /*delta_function_old*/, Matrix const & jacobian_old,
123 Vector const & delta_x_new, Vector const & delta_function_new, Vector const & function_new,
124 Matrix & jacobian_new
125 ) {
126 if (this->m_method == Method::ONE) {
127 // Greenstadt's 1st method
128 // J1 = J0 - (J0*DF1-DX1)/(C'*DF1)*C', where C = F1;
129 jacobian_new = jacobian_old - (jacobian_old*delta_function_new-delta_x_new)/(function_new.transpose()*delta_function_new)*function_new.transpose();
130 } else if (this->m_method == Method::TWO) {
131 // Greenstadt's 2nd method
132 // J1 = J0 - (J0*DF1-DX1)/(C'*DF1)*C', where C = J0'*J0*DF1;
133 Vector C(jacobian_old.transpose()*jacobian_old*delta_function_new);
134 jacobian_new = jacobian_old - (jacobian_old*delta_function_new-delta_x_new)/(C.transpose()*delta_function_new)*C.transpose();
135 }
136 }
137
138 }; // class Greenstadt
139
140 } // namespace RootFinder
141
142} // namespace Optimist
143
144#endif // OPTIMIST_ROOTFINDER_GREENSTADT_HH
#define OPTIMIST_BASIC_CONSTANTS(Real)
Definition Optimist.hh:71
void enable_two_method()
Definition Greenstadt.hh:103
void method(Method t_method)
Definition Greenstadt.hh:93
Method method() const
Definition Greenstadt.hh:87
enum class Method :Integer {ONE=1, TWO=2} Method
Definition Greenstadt.hh:56
std::string name_impl() const
Definition Greenstadt.hh:71
void set_method(Method t_method)
Definition Greenstadt.hh:109
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:98
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:121
Greenstadt()
Definition Greenstadt.hh:65
static constexpr bool requires_second_derivative
Definition Greenstadt.hh:46
Method m_method
Definition Greenstadt.hh:59
Class container for the QuasiNewton's method.
Definition QuasiNewton.hh:42
typename SolverBase< Real, N, N, Greenstadt< Real, N >, ForceEigen >::InputType Vector
Definition RootFinder.hh:61
typename SolverBase< Real, N, N, Greenstadt< Real, N >, ForceEigen >::FirstDerivativeType Matrix
Definition RootFinder.hh:64
Namespace for the Optimist library.
Definition Optimist.hh:88
OPTIMIST_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Optimist.hh:96