Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
EllipticParaboloid.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_TESTSET_ELLIPTICPARABOLOID_HH
14#define OPTIMIST_TESTSET_ELLIPTICPARABOLOID_HH
15
16#include "Optimist/TestSet.hh"
17
18namespace Optimist
19{
20
21 namespace TestSet
22 {
23
35 template <typename Real>
36 class EllipticParaboloid : public Function<Real, 2, 1, EllipticParaboloid<Real>>
37 {
38 Real m_a{1.0};
39 Real m_b{1.0};
40
41 public:
43
44 using Vector = typename Function<Real, 2, 1, EllipticParaboloid<Real>>::Vector;
45 using RowVector = typename Function<Real, 2, 1, EllipticParaboloid<Real>>::RowVector;
46 using Matrix = typename Function<Real, 2, 1, EllipticParaboloid<Real>>::Matrix;
47
52 {
53 this->m_solutions.emplace_back(0.0, 0.0);
54 for (Real x{-100}; x < 100 + EPSILON; x += 100/25.0) {
55 for (Real y{-100}; y < 100 + EPSILON; y += 100/25.0) {
56 this->m_guesses.emplace_back(x, y);
57 }
58 }
59 }
60
65 std::string name_impl() const {return "EllipticParaboloid";}
66
72 void evaluate_impl(const Vector & x, Real & out) const
73 {
74 out = this->m_a*x(0)*x(0) + this->m_b*x(1)*x(1);
75 }
76
82 void first_derivative_impl(const Vector & x, RowVector & out) const
83 {
84 out(0) = 2.0*this->m_a*x(0);
85 out(1) = 2.0*this->m_b*x(1);
86 }
87
93 void second_derivative_impl(const Vector & /*x*/, Matrix & out) const
94 {
95 out(0, 0) = 2.0*this->m_a;
96 out(0, 1) = 0.0;
97 out(1, 0) = 0.0;
98 out(1, 1) = 2.0*this->m_b;
99 }
100
101 }; // class EllipticParaboloid
102
103 } // namespace TestSet
104
105} // namespace Optimist
106
107#endif // OPTIMIST_TESTSET_ELLIPTICPARABOLOID_HH
#define OPTIMIST_BASIC_CONSTANTS(Real)
Definition Optimist.hh:70
std::vector< InputType > m_guesses
Definition Function.hh:63
std::vector< InputType > m_solutions
Definition Function.hh:62
void second_derivative_impl(const Vector &, Matrix &out) const
Definition EllipticParaboloid.hh:93
Real m_b
Definition EllipticParaboloid.hh:39
void first_derivative_impl(const Vector &x, RowVector &out) const
Definition EllipticParaboloid.hh:82
typename Function< Real, 2, 1, EllipticParaboloid< Real > >::Vector Vector
Definition EllipticParaboloid.hh:44
std::string name_impl() const
Definition EllipticParaboloid.hh:65
Real m_a
Definition EllipticParaboloid.hh:38
typename Function< Real, 2, 1, EllipticParaboloid< Real > >::Matrix Matrix
Definition EllipticParaboloid.hh:46
EllipticParaboloid()
Definition EllipticParaboloid.hh:51
void evaluate_impl(const Vector &x, Real &out) const
Definition EllipticParaboloid.hh:72
typename Function< Real, 2, 1, EllipticParaboloid< Real > >::RowVector RowVector
Definition EllipticParaboloid.hh:45
Namespace for the Optimist library.
Definition Optimist.hh:87