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 and Enrico Bertolazzi. *
3 * *
4 * The Optimist project is distributed under the BSD 2-Clause License. *
5 * *
6 * Davide Stocco Enrico Bertolazzi *
7 * University of Trento University of Trento *
8 * davide.stocco@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/Function.hh"
17
18namespace Optimist {
19
20 namespace TestSet {
21
38 template <typename Input, typename Output>
39 requires TypeTrait<Input>::IsEigen && TypeTrait<Output>::IsEigen &&
40 (!TypeTrait<Input>::IsFixed ||
41 TypeTrait<Input>::Dimension == 2) &&
42 (!TypeTrait<Output>::IsFixed ||
43 TypeTrait<Output>::Dimension == 3)
44 class Brown : public Function<Input, Output, Brown<Input, Output>> {
45 private:
46 using Scalar = typename Input::Scalar;
48 FirstDerivative;
50 SecondDerivative;
51
53 1.0e-6};
54
55 public:
57
58
62 this->m_solutions.emplace_back(this->m_a, 2.0 * this->m_a);
63 this->m_guesses.emplace_back(1.0, 1.0);
64 }
65
70 constexpr std::string name_impl() const {
71 return "Brown";
72 }
73
80 bool evaluate_impl(const Input &x, Output &out) const {
81 out << x(0) - this->m_a, x(1) - 2.0 * this->m_a, x(0) * x(1) - 2.0;
82 return out.allFinite();
83 }
84
91 bool first_derivative_impl(const Input &x, FirstDerivative &out) const {
92 out << 1.0, 0.0, x(1), 0.0, 1.0, x(0);
93 return out.allFinite();
94 }
95
102 bool second_derivative_impl(const Input & /*x*/,
103 SecondDerivative &out) const {
104 out.resize(this->output_dimension());
105 out[0].setZero();
106 out[1].setZero();
107 out[2] << 0.0, 1.0, 1.0, 0.0;
108 return out[0].allFinite() && out[1].allFinite() && out[2].allFinite();
109 }
110
111 }; // class Brown
112
113 } // namespace TestSet
114
115} // namespace Optimist
116
117#endif // OPTIMIST_TESTSET_BROWN_HH
#define OPTIMIST_BASIC_CONSTANTS(Scalar)
Definition Optimist.hh:70
std::conditional_t< InputTrait::IsEigen||OutputTrait::IsEigen, std::conditional_t< InputTrait::IsSparse||OutputTrait::IsSparse, std::vector< Eigen::SparseMatrix< Scalar > >, std::vector< Eigen::Matrix< Scalar, OutputTrait::Dimension, InputTrait::Dimension > > >, Scalar > SecondDerivative
Definition Function.hh:64
std::vector< Input > m_guesses
Definition Function.hh:79
std::vector< Input > m_solutions
Definition Function.hh:77
std::conditional_t< InputTrait::IsEigen||OutputTrait::IsEigen, std::conditional_t< InputTrait::IsSparse||OutputTrait::IsSparse, Eigen::SparseMatrix< Scalar >, Eigen::Matrix< Scalar, OutputTrait::Dimension, InputTrait::Dimension > >, Scalar > FirstDerivative
Definition Function.hh:56
constexpr Integer output_dimension() const
Definition Function.hh:141
bool second_derivative_impl(const Input &, SecondDerivative &out) const
Definition Brown.hh:102
Brown()
Definition Brown.hh:61
bool evaluate_impl(const Input &x, Output &out) const
Definition Brown.hh:80
bool first_derivative_impl(const Input &x, FirstDerivative &out) const
Definition Brown.hh:91
constexpr std::string name_impl() const
Definition Brown.hh:70
typename Input::Scalar Scalar
Definition Brown.hh:46
Scalar m_a
Definition Brown.hh:52
Namespace for the Optimist library.
Definition Optimist.hh:90