numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
dfp_optimizer.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
32
33namespace num_collect::opt {
34
36constexpr auto dfp_optimizer_tag =
37 logging::log_tag_view("num_collect::opt::dfp_optimizer");
38
50template <
52 concepts::line_searcher LineSearcher =
55 Eigen::MatrixX<typename ObjectiveFunction::value_type>>
57 : public descent_method_base<
58 dfp_optimizer<ObjectiveFunction, LineSearcher, Hessian>,
59 LineSearcher> {
60public:
63
66
68 using typename base_type::variable_type;
69
71 using variable_scalar_type = typename variable_type::Scalar;
72
74 using hessian_type = Hessian;
75
84
92 using typename base_type::value_type;
93
99 void init(const variable_type& init_variable) {
100 base_type::init(init_variable);
101 const auto dimensions = init_variable.size();
102 approx_hessian_ = hessian_type::Identity(dimensions, dimensions);
104 }
105
126
132 const {
133 iteration_logger.template append<index_type>(
134 "Iter.", &base_type::iterations);
135 iteration_logger.template append<index_type>(
136 "Eval.", &base_type::evaluations);
137 iteration_logger.template append<value_type>(
138 "Value", &base_type::opt_value);
139 iteration_logger.template append<value_type>(
140 "Grad.", &base_type::gradient_norm);
141 }
142
143private:
146
149
152
155
158
161
164};
165
166} // namespace num_collect::opt
Definition of backtracking_line_searcher class.
Class of tags of logs without memory management.
Class to perform backtracking line search.
Base class of implementations of descent methods for optimization.
typename objective_function_type::value_type value_type
Type of function values.
auto gradient() const -> const variable_type &
Get gradient for current optimal variable.
auto opt_variable() const -> const variable_type &
Get current optimal variable.
auto iterations() const noexcept -> index_type
Get the number of iterations.
typename objective_function_type::variable_type variable_type
Type of variables.
void init(const variable_type &init_variable)
Initialize.
auto evaluations() const noexcept -> index_type
Get the number of function evaluations.
typename line_searcher_type::objective_function_type objective_function_type
Type of the objective function.
auto gradient_norm() const -> value_type
Calculate norm of gradient.
auto opt_value() const -> const value_type &
Get current optimal value.
auto line_searcher() -> line_searcher_type &
Access object to perform line search.
Class of quasi-Newton method with Davidon-Fletcher-Powell (DFP) formula.
variable_type diff_var_
Difference of variable.
void init(const variable_type &init_variable)
Initialize.
auto gradient() const -> const variable_type &
Get gradient for current optimal variable.
auto opt_variable() const -> const variable_type &
Get current optimal variable.
typename variable_type::Scalar variable_scalar_type
Type of scalars in variables.
bool has_first_iteration_done_
Whether the first iteration has been done.
typename objective_function_type::variable_type variable_type
Type of variables.
hessian_type approx_hessian_
Approximate Hessian.
void configure_iteration_logger(logging::iterations::iteration_logger< this_type > &iteration_logger) const
Configure an iteration logger.
Hessian hessian_type
Type of Hessian.
auto calc_direction() -> variable_type
Calculate search direction.
typename line_searcher_type::objective_function_type objective_function_type
Type of the objective function.
variable_type diff_grad_
Difference of gradient.
variable_type prev_var_
Previous variable.
variable_type prev_grad_
Previous gradient.
dfp_optimizer(const objective_function_type &obj_fun=objective_function_type())
Constructor.
variable_type hessian_grad_
approx_hessian_ * diff_grad_
Concept of Eigen's dense matrices with real scalars.
Concept of objects to perform line search in optimization.
Concept of multi-variate first-order differentiable objective functions in optimization.
Definition of descent_method_base class.
Definition of index_type type.
Definition of iteration_logger class.
Definition of line_searcher concept.
Definition of log_tag_view class.
Definition of multi_variate_differentiable_objective_function concept.
Namespace of optimization algorithms.
constexpr auto dfp_optimizer_tag
Tag of dfp_optimizer.
Definition of real_scalar_dense_matrix concept.