numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
explicit_l_curve.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 <cmath>
23
28
30
38template <concepts::explicit_regularized_solver Solver>
40public:
42 using solver_type = Solver;
43
45 using scalar_type = typename solver_type::scalar_type;
46
53 : solver_(&solver) {}
54
61 [[nodiscard]] auto operator()(const scalar_type& log_param) const
62 -> scalar_type {
63 using std::pow;
64 const scalar_type param = pow(static_cast<scalar_type>(10), // NOLINT
65 log_param);
66 return -solver_->l_curve_curvature(param);
67 }
68
69private:
72};
73
81 template <typename> typename Optimizer = opt::heuristic_global_optimizer>
83 : public explicit_param_searcher_base<explicit_l_curve<Solver, Optimizer>,
84 Solver> {
85public:
87 using base_type =
89 Solver>;
90
91 using typename base_type::data_type;
92 using typename base_type::scalar_type;
93 using typename base_type::solver_type;
94
99
105 explicit explicit_l_curve(const solver_type& solver)
106 : solver_(&solver),
108 opt::make_function_object_wrapper<scalar_type(scalar_type)>(
110
112 void search() {
113 using std::log10;
114 using std::pow;
115 const auto [min_param, max_param] = solver_->param_search_region();
116 const scalar_type log_min_param = log10(min_param);
117 const scalar_type log_max_param = log10(max_param);
118 optimizer_.init(log_min_param, log_max_param);
119 optimizer_.solve();
120 opt_param_ = pow(static_cast<scalar_type>(10), // NOLINT
121 optimizer_.opt_variable());
122 }
123
125 [[nodiscard]] auto opt_param() const -> scalar_type { return opt_param_; }
126
128 void solve(data_type& solution) const {
129 solver_->solve(opt_param_, solution);
130 }
131
132private:
135
138
141};
142
143} // namespace num_collect::regularization
Wrapper class of a function object to use as an objective function.
Class to perform global optimization using heuristics.
auto operator()(const scalar_type &log_param) const -> scalar_type
Calculate the curvature of L-curve.
explicit_l_curve_objective_function(const solver_type &solver)
Constructor.
typename solver_type::scalar_type scalar_type
Type of scalars.
Class to search optimal regularization parameter using l-curve.
typename solver_type::data_type data_type
Type of data.
Optimizer< opt::function_object_wrapper< scalar_type(scalar_type), explicit_l_curve_objective_function< solver_type > > > optimizer_type
Type of optimizers.
scalar_type opt_param_
Optimal regularization parameter.
void solve(data_type &solution) const
Solver with the optimal regularization parameter.
auto opt_param() const -> scalar_type
Get the optimal regularization parameter.
explicit_l_curve(const solver_type &solver)
Constructor.
void search()
Search the optimal regularization parameter.
typename solver_type::scalar_type scalar_type
Type of scalars.
Base class for searching the optimal regularization parameters using explicit formulas for regulariza...
typename solver_type::scalar_type scalar_type
Type of scalars.
Concept of solvers using explicit formulas for regularization.
Definition of explicit_param_searcher_base class.
Definition of explicit_regularized_solver concept.
Definition of function_object_wrapper class.
Definition of heuristic_global_optimizer class.
Namespace of regularization algorithms.