numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
powell4_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
37public:
39 using variable_type = Eigen::Vector4d;
40
42 using value_type = double;
43
49 void evaluate_on(const Eigen::Vector4d& x) {
50 value_ = std::pow(x(0) + 10.0 * x(1), 2) // NOLINT
51 + 5.0 * std::pow(x(2) - x(3), 2) // NOLINT
52 + std::pow(x(1) - 2.0 * x(2), 4) // NOLINT
53 + 10.0 * std::pow(x(0) - x(3), 4); // NOLINT
54
55 grad_(0) = 2.0 * (x(0) + 10.0 * x(1)) // NOLINT
56 + 40.0 * std::pow(x(0) - x(3), 3); // NOLINT
57 grad_(1) = 20.0 * (x(0) + 10.0 * x(1)) // NOLINT
58 + 4.0 * std::pow(x(1) - 2.0 * x(2), 3); // NOLINT
59 grad_(2) = 10.0 * (x(2) - x(3)) // NOLINT
60 - 8.0 * std::pow(x(1) - 2.0 * x(2), 3); // NOLINT
61 grad_(3) = -10.0 * (x(2) - x(3)) // NOLINT
62 - 40.0 * std::pow(x(0) - x(3), 3); // NOLINT
63 }
64
70 [[nodiscard]] auto value() const -> const double& { return value_; }
71
77 [[nodiscard]] auto gradient() const -> const Eigen::Vector4d& {
78 return grad_;
79 }
80
81private:
83 double value_{};
84
86 Eigen::Vector4d grad_{};
87};
88
89} // namespace num_prob_collect::opt
Class of Powell function in 4 dimensions.
void evaluate_on(const Eigen::Vector4d &x)
Evaluate function value on variable.
double value_type
Type of function values.
auto gradient() const -> const Eigen::Vector4d &
Get gradient.
auto value() const -> const double &
Get function value.
Eigen::Vector4d variable_type
Type of variables.
Namespace of Eigen library.
Definition variable.h:416
Namespace of optimization problems.
Definition namespaces.h:25