numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
multi_quadratic_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
30public:
32 using variable_type = Eigen::VectorXd;
34 using value_type = double;
36 using hessian_type = Eigen::MatrixXd;
37
43 void evaluate_on(const Eigen::VectorXd& variable) {
44 value_ = coeff_ * variable.squaredNorm();
45 constexpr double two = 2.0;
46 grad_ = two * coeff_ * variable;
47 hessian_ = (two * coeff_) *
48 Eigen::MatrixXd::Identity(variable.size(), variable.size());
49 }
50
56 [[nodiscard]] auto value() const -> const double& { return value_; }
57
63 [[nodiscard]] auto gradient() const -> const Eigen::VectorXd& {
64 return grad_;
65 }
66
72 [[nodiscard]] auto hessian() const -> const Eigen::MatrixXd& {
73 return hessian_;
74 }
75
76private:
78 double coeff_{3.0}; // NOLINT
79
81 double value_{0.0};
82
84 Eigen::VectorXd grad_{};
85
87 Eigen::MatrixXd hessian_{};
88};
89
90} // namespace num_prob_collect::opt
Quadratic function for test of optimization.
auto gradient() const -> const Eigen::VectorXd &
Get gradient.
auto value() const -> const double &
Get function value.
void evaluate_on(const Eigen::VectorXd &variable)
Evaluate function value on variable.
auto hessian() const -> const Eigen::MatrixXd &
Get Hessian.
Namespace of Eigen library.
Definition variable.h:416
Namespace of optimization problems.
Definition namespaces.h:25