numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
explicit_gcv.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_->gcv(param);
67 }
68
69private:
72};
73
81 template <typename> typename Optimizer = opt::heuristic_global_optimizer>
83 : public explicit_param_searcher_base<explicit_gcv<Solver, Optimizer>,
84 Solver> {
85public:
87 using base_type =
89
90 using typename base_type::data_type;
91 using typename base_type::scalar_type;
92 using typename base_type::solver_type;
93
98
104 explicit explicit_gcv(const solver_type& solver)
105 : solver_(&solver),
107 opt::make_function_object_wrapper<scalar_type(scalar_type)>(
109
111 void search() {
112 using std::log10;
113 using std::pow;
114 const auto [min_param, max_param] = solver_->param_search_region();
115 const scalar_type log_min_param = log10(min_param);
116 const scalar_type log_max_param = log10(max_param);
117 optimizer_.init(log_min_param, log_max_param);
118 optimizer_.solve();
119 opt_param_ = pow(static_cast<scalar_type>(10), // NOLINT
120 optimizer_.opt_variable());
121 }
122
124 [[nodiscard]] auto opt_param() const -> scalar_type { return opt_param_; }
125
127 void solve(data_type& solution) const {
128 solver_->solve(opt_param_, solution);
129 }
130
131private:
134
137
140};
141
142} // namespace num_collect::regularization
Wrapper class of a function object to use as an objective function.
Class to perform global optimization using heuristics.
typename solver_type::scalar_type scalar_type
Type of scalars.
explicit_gcv_objective_function(const solver_type &solver)
Constructor.
auto operator()(const scalar_type &log_param) const -> scalar_type
Calculate GCV function.
Class to search optimal regularization parameter using GCV.
typename solver_type::data_type data_type
Type of data.
Optimizer< opt::function_object_wrapper< scalar_type(scalar_type), explicit_gcv_objective_function< solver_type > > > optimizer_type
Type of optimizers.
void solve(data_type &solution) const
Solver with the optimal regularization parameter.
auto opt_param() const -> scalar_type
Get the optimal regularization parameter.
void search()
Search the optimal regularization parameter.
typename solver_type::scalar_type scalar_type
Type of scalars.
explicit_gcv(const solver_type &solver)
Constructor.
scalar_type opt_param_
Optimal regularization parameter.
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.