numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
explicit_regularized_solver_base.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
27
29
36template <typename Derived, base::concepts::dense_matrix Data>
38 : public regularized_solver_base<Derived, Data> {
39public:
42 using regularized_solver_base<Derived, Data>::data_size;
43
50 void solve(const scalar_type& param, data_type& solution) const {
51 return derived().solve(param, solution);
52 }
53
60 [[nodiscard]] auto residual_norm(const scalar_type& param) const
61 -> scalar_type {
62 return derived().residual_norm(param);
63 }
64
71 [[nodiscard]] auto regularization_term(const scalar_type& param) const
72 -> scalar_type {
73 return derived().regularization_term(param);
74 }
75
84 const scalar_type& param) const -> scalar_type {
85 return derived().first_derivative_of_residual_norm(param);
86 }
87
95 const scalar_type& param) const -> scalar_type {
96 return derived().first_derivative_of_regularization_term(param);
97 }
98
107 const scalar_type& param) const -> scalar_type {
108 return derived().second_derivative_of_residual_norm(param);
109 }
110
118 const scalar_type& param) const -> scalar_type {
119 return derived().second_derivative_of_regularization_term(param);
120 }
121
128 [[nodiscard]] auto sum_of_filter_factor(const scalar_type& param) const
129 -> scalar_type {
130 return derived().sum_of_filter_factor(param);
131 }
132
139 [[nodiscard]] auto l_curve_curvature(const scalar_type& param) const {
140 const scalar_type res = residual_norm(param);
141 const scalar_type reg = regularization_term(param);
145 const scalar_type reg2 =
147
148 const scalar_type log_res1 = res1 / res;
149 const scalar_type log_reg1 = reg1 / reg;
150 const scalar_type log_res2 = (res2 * res - res1 * res1) / (res * res);
151 const scalar_type log_reg2 = (reg2 * reg - reg1 * reg1) / (reg * reg);
152
153 using std::pow;
154 return (log_res1 * log_reg2 - log_res2 * log_reg1) /
155 pow(log_res1 * log_res1 + log_reg1 * log_reg1,
156 static_cast<scalar_type>(1.5)); // NOLINT
157 }
158
165 [[nodiscard]] auto gcv(const scalar_type& param) const -> scalar_type {
166 const scalar_type den =
167 static_cast<scalar_type>(data_size()) - sum_of_filter_factor(param);
168 return residual_norm(param) / (den * den);
169 }
170
171protected:
179
180 using regularized_solver_base<Derived, Data>::derived;
181};
182
183} // namespace num_collect::regularization
Class of tags of logs without memory management.
Base class of solvers using explicit formulas for regularization.
auto residual_norm(const scalar_type &param) const -> scalar_type
Calculate the squared norm of the residual.
auto first_derivative_of_regularization_term(const scalar_type &param) const -> scalar_type
Calculate the first-order derivative of the Regularization term.
auto regularization_term(const scalar_type &param) const -> scalar_type
Calculate the regularization term.
auto sum_of_filter_factor(const scalar_type &param) const -> scalar_type
Calculate the sum of filter factors.
auto second_derivative_of_residual_norm(const scalar_type &param) const -> scalar_type
Calculate the second-order derivative of the squared norm of the residual.
auto gcv(const scalar_type &param) const -> scalar_type
Calculate GCV function.
void solve(const scalar_type &param, data_type &solution) const
Solve for a regularization parameter.
auto second_derivative_of_regularization_term(const scalar_type &param) const -> scalar_type
Calculate the send-order derivative of the Regularization term.
auto l_curve_curvature(const scalar_type &param) const
Calculate the curvature of L-curve.
auto first_derivative_of_residual_norm(const scalar_type &param) const -> scalar_type
Calculate the first-order derivative of the squared norm of the residual.
auto derived() noexcept -> Derived &
Access derived object.
auto data_size() const -> index_type
Get the size of data.
typename Eigen::NumTraits< typename data_type::Scalar >::Real scalar_type
Type of scalars.
Definition of dense_matrix concept.
Definition of log_tag_view class.
Namespace of regularization algorithms.
Definition of regularized_solver_base class.