numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
shekel_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
35public:
37 using variable_type = Eigen::Vector4d;
38
40 using value_type = double;
41
47 explicit shekel_function(int m) : m_(m) {
48 // NOLINTNEXTLINE
49 beta_ << 0.1, 0.2, 0.2, 0.4, 0.4, 0.6, 0.3, 0.7, 0.5, 0.5;
50 // NOLINTNEXTLINE
51 c_ << 4.0, 1.0, 8.0, 6.0, 3.0, 2.0, 5.0, 8.0, 6.0, 7.0,
52 // NOLINTNEXTLINE
53 4.0, 1.0, 8.0, 6.0, 7.0, 9.0, 3.0, 1.0, 2.0, 3.6,
54 // NOLINTNEXTLINE
55 4.0, 1.0, 8.0, 6.0, 3.0, 2.0, 5.0, 8.0, 6.0, 7.0,
56 // NOLINTNEXTLINE
57 4.0, 1.0, 8.0, 6.0, 7.0, 9.0, 3.0, 1.0, 2.0, 3.6;
58 }
59
65 void evaluate_on(const Eigen::Vector4d& x) {
66 value_ = 0.0;
67 for (int i = 0; i < m_; ++i) {
68 value_ -= 1.0 / ((x - c_.col(i)).squaredNorm() + beta_(i));
69 }
70 }
71
77 [[nodiscard]] auto value() const -> const double& { return value_; }
78
79private:
81 int m_;
82
84 Eigen::Matrix<double, 10, 1> beta_{}; // NOLINT
85
87 Eigen::Matrix<double, 4, 10> c_{}; // NOLINT
88
90 double value_{};
91};
92
93} // namespace num_prob_collect::opt
Class of Shekel function in 4 dimensions.
Eigen::Matrix< double, 4, 10 > c_
Centers in the function.
void evaluate_on(const Eigen::Vector4d &x)
Evaluate function value on variable.
double value_type
Type of function values.
auto value() const -> const double &
Get function value.
Eigen::Matrix< double, 10, 1 > beta_
Offset in the function.
Eigen::Vector4d variable_type
Type of variables.
Namespace of optimization problems.
Definition namespaces.h:25