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_TESTSET_BOOTH_HH
14#define OPTIMIST_TESTSET_BOOTH_HH
15
16#include "Optimist/TestSet.hh"
17
18namespace Optimist
19{
20
21 namespace TestSet
22 {
23
35 template <typename Real>
36 class Booth : public Function<Real, 2, 2, Booth<Real>>
37 {
38 public:
40
41 using Vector = typename Function<Real, 2, 2, Booth<Real>>::InputVector;
42 using Matrix = typename Function<Real, 2, 2, Booth<Real>>::Matrix;
43 using Tensor = typename Function<Real, 2, 2, Booth<Real>>::Tensor;
44
49 {
50 this->m_solutions.emplace_back(1.0, 3.0);
51 for (Real x{-10.0}; x < 10.0 + EPSILON; x += 5.0) {
52 for (Real y{-10.0}; y < 10.0 + EPSILON; y += 5.0) {
53 this->m_guesses.emplace_back(x, y);
54 }
55 }
56 }
57
62 std::string name_impl() const {return "Booth";}
63
69 void evaluate_impl(const Vector & x, Vector & out) const
70 {
71 out << x(0) + 2.0*x(1) - 7.0, 2.0*x(0) + x(1) - 5.0;
72 }
73
78 void first_derivative_impl(const Vector & /*x*/, Matrix & out) const
79 {
80 out << 1.0, 2.0, 2.0, 1.0;
81 }
82
88 void second_derivative_impl(const Vector & /*x*/, Tensor & out) const
89 {
90 out.resize(this->output_dimension());
91 std::for_each(out.begin(), out.end(), [] (Matrix& m) {m.setZero();});
92 }
93
94 }; // class Booth
95
96 } // namespace TestSet
97
98} // namespace Optimist
99
100#endif // OPTIMIST_TESTSET_BOOTH_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
constexpr Integer output_dimension() const
Definition Function.hh:117
typename FunctionBase< Real, N, M, Booth< Real >, false >::InputType InputVector
Definition Function.hh:193
void first_derivative_impl(const Vector &, Matrix &out) const
Definition Booth.hh:78
void second_derivative_impl(const Vector &, Tensor &out) const
Definition Booth.hh:88
Booth()
Definition Booth.hh:48
void evaluate_impl(const Vector &x, Vector &out) const
Definition Booth.hh:69
typename Function< Real, 2, 2, Booth< Real > >::InputVector Vector
Definition Booth.hh:41
std::string name_impl() const
Definition Booth.hh:62
typename Function< Real, 2, 2, Booth< Real > >::Tensor Tensor
Definition Booth.hh:43
typename Function< Real, 2, 2, Booth< Real > >::Matrix Matrix
Definition Booth.hh:42
Namespace for the Optimist library.
Definition Optimist.hh:87