13#ifndef OPTIMIST_TESTSET_ROSENBROCK_COST_HH
14#define OPTIMIST_TESTSET_ROSENBROCK_COST_HH
38 template <
typename Vector, Integer N>
55 if constexpr (N == 2) {
58 this->
add_guess(Dense::Constant(N, -0.5));
65 return "RosenbrockCost<" + std::to_string(N) +
">";
70 for (
Integer i{0}; i < N - 1; ++i) {
71 const Scalar a{x(i + 1) - x(i) * x(i)}, b{1 - x(i)};
72 f += 100 * a * a + b * b;
79 for (
Integer i{0}; i < N - 1; ++i) {
80 const Scalar a{x(i + 1) - x(i) * x(i)};
81 g(i) += -400 * x(i) * a - 2 * (1 - x(i));
88 for (
Integer i{0}; i < N - 1; ++i) {
89 H(i, i) += 1200 * x(i) * x(i) - 400 * x(i + 1) + 2;
90 H(i, i + 1) += -400 * x(i);
91 H(i + 1, i) += -400 * x(i);
92 H(i + 1, i + 1) += 200;
98 template <
typename Vector>
101 template <
typename Vector>
Helper base class for scalar cost functions written once in terms of dense vectors.
Definition DenseFunction.hh:43
void add_solution(const Dense &x)
Definition DenseFunction.hh:94
Utils::DenseMatrix< Vector > DenseMatrix
Definition DenseFunction.hh:48
void add_guess(const Dense &x)
Definition DenseFunction.hh:101
Utils::DenseVector< Vector > Dense
Definition DenseFunction.hh:47
static Dense make(std::initializer_list< Scalar > values)
Definition DenseFunction.hh:108
typename Vector::Scalar Scalar
Definition DenseFunction.hh:46
Rosenbrock's cost function in dimensions (chained form).
Definition RosenbrockCost.hh:41
Scalar value(const Dense &x) const
Definition RosenbrockCost.hh:68
constexpr std::string name_impl() const
Definition RosenbrockCost.hh:64
void gradient(const Dense &x, Dense &g) const
Definition RosenbrockCost.hh:77
DenseCostFunction< Vector, N, RosenbrockCost< Vector, N > > Base
Definition RosenbrockCost.hh:43
void hessian(const Dense &x, DenseMatrix &H) const
Definition RosenbrockCost.hh:86
RosenbrockCost()
Definition RosenbrockCost.hh:51
RosenbrockCost< Vector, 4 > RosenbrockCost4
Definition RosenbrockCost.hh:102
RosenbrockCost< Vector, 2 > RosenbrockCost2
Definition RosenbrockCost.hh:99
Namespace for the Optimist library.
Definition Optimist.hh:90
OPTIMIST_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Optimist.hh:98