Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
Brown.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_BROWN_HH
14#define OPTIMIST_TESTSET_BROWN_HH
15
16#include "Optimist/TestSet.hh"
17
18namespace Optimist
19{
20
21 namespace TestSet
22 {
23
35 template <typename Real>
36 class Brown : public Function<Real, 2, 3, Brown<Real>>
37 {
38 private:
39 Real m_a{1.0e-6};
40
41 public:
43
48
53 {
54 this->m_solutions.emplace_back(this->m_a, 2.0*this->m_a);
55 this->m_guesses.emplace_back(1.0, 1.0);
56 }
57
62 std::string name_impl() const {return "Brown";}
63
70 bool evaluate_impl(const InputVector & x, OutputVector & out) const
71 {
72 out << x(0) - this->m_a,
73 x(1) - 2.0*this->m_a,
74 x(0)*x(1) - 2.0;
75 return out.allFinite();
76 }
77
84 bool first_derivative_impl(const InputVector & x, Matrix & out) const
85 {
86 out << 1.0, 0.0, x(1),
87 0.0, 1.0, x(0);
88 return out.allFinite();
89 }
90
97 bool second_derivative_impl(const InputVector & /*x*/, Tensor & out) const
98 {
99 out.resize(this->output_dimension());
100 out[0].setZero();
101 out[1].setZero();
102 out[2] << 0.0, 1.0,
103 1.0, 0.0;
104 return out[0].allFinite() && out[1].allFinite() && out[2].allFinite();
105 }
106
107 }; // class Brown
108
109 } // namespace TestSet
110
111} // namespace Optimist
112
113#endif // OPTIMIST_TESTSET_BROWN_HH
#define OPTIMIST_BASIC_CONSTANTS(Real)
Definition Optimist.hh:71
std::vector< InputType > m_guesses
Definition Function.hh:66
std::vector< InputType > m_solutions
Definition Function.hh:65
constexpr Integer output_dimension() const
Definition Function.hh:123
Class container for the vector-valued function.
Definition Function.hh:190
typename FunctionBase< Real, N, M, Brown< Real >, false >::OutputType OutputVector
Definition Function.hh:200
typename FunctionBase< Real, N, M, Brown< Real >, false >::InputType InputVector
Definition Function.hh:199
typename FunctionBase< Real, N, M, Brown< Real >, false >::FirstDerivativeType Matrix
Definition Function.hh:203
typename FunctionBase< Real, N, M, Brown< Real >, false >::SecondDerivativeType Tensor
Definition Function.hh:204
Real m_a
Definition Brown.hh:39
bool evaluate_impl(const InputVector &x, OutputVector &out) const
Definition Brown.hh:70
std::string name_impl() const
Definition Brown.hh:62
Brown()
Definition Brown.hh:52
bool first_derivative_impl(const InputVector &x, Matrix &out) const
Definition Brown.hh:84
bool second_derivative_impl(const InputVector &, Tensor &out) const
Definition Brown.hh:97
Namespace for the Optimist library.
Definition Optimist.hh:88