Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
Booth.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_VECTOR_FUNCTION_BOOTH_HH
14#define OPTIMIST_VECTOR_FUNCTION_BOOTH_HH
15
16#include "Optimist/TestSet.hh"
18
19namespace Optimist
20{
21
22 namespace TestSet
23 {
24
36 template <typename Real>
37 class Booth : public VectorFunction<Real, 2, 2, Booth<Real>>
38 {
39 public:
41
42 using Vector = typename VectorFunction<Real, 2, 2, Booth<Real>>::InputVector;
43 using Matrix = typename VectorFunction<Real, 2, 2, Booth<Real>>::Matrix;
44 using Tensor = typename VectorFunction<Real, 2, 2, Booth<Real>>::Tensor;
45
50 {
51 this->m_solutions.emplace_back(1.0, 3.0);
52 for (Real x{-10.0}; x < 10.0 + EPSILON; x += 5.0) {
53 for (Real y{-10.0}; y < 10.0 + EPSILON; y += 5.0) {
54 this->m_guesses.emplace_back(x, y);
55 }
56 }
57 }
58
63 std::string name_impl() const {return "Booth";}
64
70 void evaluate_impl(const Vector & x, Vector & out) const
71 {
72 out << x(0) + 2.0*x(1) - 7.0, 2.0*x(0) + x(1) - 5.0;
73 }
74
79 void first_derivative_impl(const Vector & /*x*/, Matrix & out) const
80 {
81 out << 1.0, 2.0, 2.0, 1.0;
82 }
83
89 void second_derivative_impl(const Vector & /*x*/, Tensor & out) const
90 {
91 out.resize(this->output_dimension());
92 std::for_each(out.begin(), out.end(), [] (Matrix& m) {m.setZero();});
93 }
94
95 }; // class Booth
96
97 } // namespace TestSet
98
99} // namespace Optimist
100
101#endif // OPTIMIST_VECTOR_FUNCTION_BOOTH_HH
#define OPTIMIST_BASIC_CONSTANTS(Real)
Definition Optimist.hh:70
std::vector< InputType > m_solutions
Definition Function.hh:52
std::vector< InputType > m_guesses
Definition Function.hh:53
constexpr Integer output_dimension() const
Definition Function.hh:107
void first_derivative_impl(const Vector &, Matrix &out) const
Definition Booth.hh:79
void second_derivative_impl(const Vector &, Tensor &out) const
Definition Booth.hh:89
Booth()
Definition Booth.hh:49
void evaluate_impl(const Vector &x, Vector &out) const
Definition Booth.hh:70
std::string name_impl() const
Definition Booth.hh:63
typename VectorFunction< Real, 2, 2, Booth< Real > >::InputVector Vector
Definition Booth.hh:42
typename VectorFunction< Real, 2, 2, Booth< Real > >::Matrix Matrix
Definition Booth.hh:43
typename VectorFunction< Real, 2, 2, Booth< Real > >::Tensor Tensor
Definition Booth.hh:44
VectorFunction()
Definition VectorFunction.hh:55
typename Function< Real, N, M, Booth< Real > >::InputType InputVector
Definition VectorFunction.hh:45
Namespace for the Optimist library.
Definition Optimist.hh:87