numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
rosenbrock_function.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <Eigen/Core>
23
24namespace num_prob_collect::opt {
25
36public:
38 using variable_type = Eigen::Vector3d;
39
41 using value_type = double;
42
48 void evaluate_on(const Eigen::Vector3d& x) {
49 value_ = 100.0 * std::pow(x(1) - x(0) * x(0), 2) // NOLINT
50 + std::pow(x(0) - 1.0, 2) // NOLINT
51 + 100.0 * std::pow(x(2) - x(1) * x(1), 2) // NOLINT
52 + std::pow(x(1) - 1.0, 2); // NOLINT
53
54 grad_(0) = -400.0 * (x(1) - x(0) * x(0)) * x(0) // NOLINT
55 + 2.0 * (x(0) - 1.0); // NOLINT
56 grad_(1) = 200.0 * (x(1) - x(0) * x(0)) // NOLINT
57 - 400.0 * (x(2) - x(1) * x(1)) * x(1) // NOLINT
58 + 2.0 * (x(1) - 1.0); // NOLINT
59 grad_(2) = 200.0 * (x(2) - x(1) * x(1)); // NOLINT
60 }
61
67 [[nodiscard]] auto value() const -> const double& { return value_; }
68
74 [[nodiscard]] auto gradient() const -> const Eigen::Vector3d& {
75 return grad_;
76 }
77
78private:
80 double value_{};
81
83 Eigen::Vector3d grad_{};
84};
85
86} // namespace num_prob_collect::opt
Class of Rosenbrock function in 3 dimensions.
auto gradient() const -> const Eigen::Vector3d &
Get gradient.
Eigen::Vector3d variable_type
Type of variables.
double value_type
Type of function values.
auto value() const -> const double &
Get function value.
void evaluate_on(const Eigen::Vector3d &x)
Evaluate function value on variable.
Namespace of Eigen library.
Definition variable.h:416
Namespace of optimization problems.
Definition namespaces.h:25