Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
Rosenbrock.hh
Go to the documentation of this file.
1
2
3#pragma once
4
5#ifndef OPTIMIST_TESTSET_ROSENBROCK_HH
6#define OPTIMIST_TESTSET_ROSENBROCK_HH
7
9
10namespace Optimist {
11
12 namespace TestSet {
13
32 template <typename Vector, Integer N>
33 requires(N % 2 == 0)
35 : public DenseSystemFunction<Vector, N, Rosenbrock<Vector, N>> {
36 public:
38 using typename Base::Dense;
39 using typename Base::DenseMatrix;
40 using typename Base::Scalar;
41
46 Dense x0(N);
47 for (Integer i{0}; i < N; i += 2) {
48 x0(i) = -1.2;
49 x0(i + 1) = 1.0;
50 }
51 this->add_solution(Dense::Ones(N));
52 this->add_guess(x0);
53 }
54
59 constexpr std::string name_impl() const {
60 return "Rosenbrock<" + std::to_string(N) + ">";
61 }
62
63 void residual(const Dense &x, Dense &F) const {
64 for (Integer i{0}; i < N; i += 2) {
65 F(i) = 10 * (x(i + 1) - x(i) * x(i));
66 F(i + 1) = 1 - x(i);
67 }
68 }
69
70 void jacobian(const Dense &x, DenseMatrix &J) const {
71 J.setZero();
72 for (Integer i{0}; i < N; i += 2) {
73 J(i, i) = -20 * x(i);
74 J(i, i + 1) = 10;
75 J(i + 1, i) = -1;
76 }
77 }
78
79 void hessian([[maybe_unused]] const Dense &x,
80 const Integer i,
81 DenseMatrix &H) const {
82 H.setZero();
83 if (i % 2 == 0) {
84 H(i, i) = -20;
85 }
86 }
87
88 }; // class Rosenbrock
89
90 template <typename Vector>
92
93 template <typename Vector>
95
96 template <typename Vector>
98
99 template <typename Vector>
101
102 template <typename Vector>
104
105 } // namespace TestSet
106
107} // namespace Optimist
108
109#endif // OPTIMIST_TESTSET_ROSENBROCK_HH
Helper base class for nonlinear systems written once in terms of dense vectors (square by default).
Definition DenseFunction.hh:151
void add_guess(const Dense &x)
Definition DenseFunction.hh:225
Utils::DenseMatrix< Vector > DenseMatrix
Definition DenseFunction.hh:156
typename Vector::Scalar Scalar
Definition DenseFunction.hh:154
Utils::DenseVector< Vector > Dense
Definition DenseFunction.hh:155
void add_solution(const Dense &x)
Definition DenseFunction.hh:218
Class container for the extended Rosenbrock function.
Definition Rosenbrock.hh:35
void residual(const Dense &x, Dense &F) const
Definition Rosenbrock.hh:63
constexpr std::string name_impl() const
Definition Rosenbrock.hh:59
void hessian(const Dense &x, const Integer i, DenseMatrix &H) const
Definition Rosenbrock.hh:79
Rosenbrock()
Definition Rosenbrock.hh:45
void jacobian(const Dense &x, DenseMatrix &J) const
Definition Rosenbrock.hh:70
DenseSystemFunction< Vector, N, Rosenbrock< Vector, N > > Base
Definition Rosenbrock.hh:37
Rosenbrock< Vector, 6 > Rosenbrock6
Definition Rosenbrock.hh:97
Rosenbrock< Vector, 2 > Rosenbrock2
Definition Rosenbrock.hh:91
Rosenbrock< Vector, 10 > Rosenbrock10
Definition Rosenbrock.hh:103
Rosenbrock< Vector, 8 > Rosenbrock8
Definition Rosenbrock.hh:100
Rosenbrock< Vector, 4 > Rosenbrock4
Definition Rosenbrock.hh:94
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