numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
blur_sine.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
24#include <Eigen/Core>
25
27
29
33class blur_sine {
34public:
36 using coeff_type = Eigen::MatrixXd;
37
39 using data_type = Eigen::VectorXd;
40
48 num_collect::index_type solution_size) {
49 coeff_.resize(data_size, solution_size);
50 for (num_collect::index_type j = 0; j < solution_size; ++j) {
51 for (num_collect::index_type i = 0; i < data_size; ++i) {
52 static constexpr double factor = 100.0;
53 const double sol_rate =
54 static_cast<double>(j) / static_cast<double>(solution_size);
55 const double data_rate =
56 static_cast<double>(i) / static_cast<double>(data_size);
57 const double diff = sol_rate - data_rate;
58 coeff_(i, j) = std::exp(-factor * diff * diff);
59 }
60 }
61
62 solution_.resize(solution_size);
63 for (num_collect::index_type i = 0; i < solution_size; ++i) {
64 static constexpr double factor = 10.0;
65 const double sol_rate =
66 static_cast<double>(i) / static_cast<double>(solution_size);
67 solution_(i) = std::sin(factor * sol_rate);
68 }
69
71 }
72
78 [[nodiscard]] auto coeff() const -> const Eigen::MatrixXd& {
79 return coeff_;
80 }
81
87 [[nodiscard]] auto solution() const -> const Eigen::VectorXd& {
88 return solution_;
89 }
90
96 [[nodiscard]] auto data() const -> const Eigen::VectorXd& { return data_; }
97
98private:
100 Eigen::MatrixXd coeff_;
101
103 Eigen::VectorXd solution_;
104
106 Eigen::VectorXd data_;
107};
108
109} // namespace num_prob_collect::regularization
Class of problem of blurred sine function.
Definition blur_sine.h:33
Eigen::MatrixXd coeff_
Coefficient matrix.
Definition blur_sine.h:100
auto coeff() const -> const Eigen::MatrixXd &
Get the coefficient matrix.
Definition blur_sine.h:78
auto solution() const -> const Eigen::VectorXd &
Get the solution.
Definition blur_sine.h:87
Eigen::VectorXd data_type
Type of data vector.
Definition blur_sine.h:39
auto data() const -> const Eigen::VectorXd &
Get the data.
Definition blur_sine.h:96
Eigen::MatrixXd coeff_type
Type of coefficient matrices.
Definition blur_sine.h:36
blur_sine(num_collect::index_type data_size, num_collect::index_type solution_size)
Constructor.
Definition blur_sine.h:47
Definition of index_type type.
Namespace of Eigen library.
Definition variable.h:416
std::ptrdiff_t index_type
Type of indices in this library.
Definition index_type.h:33
Namespace of regularization.
Definition namespaces.h:34