numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
newton_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/Cholesky>
23
31
32namespace num_collect::opt {
33
35constexpr auto newton_optimizer_tag =
36 logging::log_tag_view("num_collect::opt::newton_optimizer");
37
46 ObjectiveFunction,
47 concepts::line_searcher LineSearcher =
49 typename HessianSolver =
50 Eigen::LLT<typename ObjectiveFunction::hessian_type>>
52 : public descent_method_base<
53 newton_optimizer<ObjectiveFunction, LineSearcher, HessianSolver>,
54 LineSearcher> {
55public:
57 using this_type =
59
62
64 using typename base_type::variable_type;
65
67 using hessian_type = typename objective_function_type::hessian_type;
68
70 using hessian_solver_type = HessianSolver;
71
80
87 using typename base_type::value_type;
88
94 [[nodiscard]] auto hessian() const -> const hessian_type& {
95 return line_searcher().obj_fun().hessian();
96 }
97
101 [[nodiscard]] auto calc_direction() -> variable_type {
103 }
104
110 const {
111 iteration_logger.template append<index_type>(
112 "Iter.", &base_type::iterations);
113 iteration_logger.template append<index_type>(
114 "Eval.", &base_type::evaluations);
115 iteration_logger.template append<value_type>(
116 "Value", &base_type::opt_value);
117 iteration_logger.template append<value_type>(
118 "Grad.", &base_type::gradient_norm);
119 }
120
121private:
128 [[nodiscard]] auto calc_direction_impl(const hessian_type& hessian)
129 -> variable_type {
130 solver_.compute(hessian);
131 return -solver_.solve(gradient());
132 }
133
136};
137
138} // 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 iterations() const noexcept -> index_type
Get the number of iterations.
typename objective_function_type::variable_type variable_type
Type of variables.
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 newton method for optimization.
hessian_solver_type solver_
Solver of linear equation of Hessian.
auto gradient() const -> const variable_type &
Get gradient for current optimal variable.
auto calc_direction() -> variable_type
Calculate search direction.
typename objective_function_type::variable_type variable_type
Type of variables.
auto hessian() const -> const hessian_type &
Get Hessian for current optimal variable.
typename line_searcher_type::objective_function_type objective_function_type
Type of the objective function.
HessianSolver hessian_solver_type
Type of solvers of linear equation of Hessian.
void configure_iteration_logger(logging::iterations::iteration_logger< this_type > &iteration_logger) const
Configure an iteration logger.
auto calc_direction_impl(const hessian_type &hessian) -> variable_type
Calculate search direction.
typename objective_function_type::hessian_type hessian_type
Type of Hessian.
newton_optimizer(const objective_function_type &obj_fun=objective_function_type())
Constructor.
auto line_searcher() -> line_searcher_type &
Access object to perform line search.
Concept of objects to perform line search in optimization.
Concept of multi-variate second-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_twice_differentiable_objective_function concept.
Namespace of optimization algorithms.
constexpr auto newton_optimizer_tag
Tag of newton_optimizer.