Loading...
Searching...
No Matches
ITHACAregularization.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ██╗████████╗██╗ ██╗ █████╗ ██████╗ █████╗ ███████╗██╗ ██╗
3 ██║╚══██╔══╝██║ ██║██╔══██╗██╔════╝██╔══██╗ ██╔════╝██║ ██║
4 ██║ ██║ ███████║███████║██║ ███████║█████╗█████╗ ██║ ██║
5 ██║ ██║ ██╔══██║██╔══██║██║ ██╔══██║╚════╝██╔══╝ ╚██╗ ██╔╝
6 ██║ ██║ ██║ ██║██║ ██║╚██████╗██║ ██║ ██║ ╚████╔╝
7 ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═══╝
8 * In real Time Highly Advanced Computational Applications for Finite Volumes
9 * Copyright (C) 2017 by the ITHACA-FV authors
10-------------------------------------------------------------------------------
11License
12 This file is part of ITHACA-FV
13 ITHACA-FV is free software: you can redistribute it and/or modify
14 it under the terms of the GNU Lesser General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17 ITHACA-FV is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU Lesser General Public License for more details.
21 You should have received a copy of the GNU Lesser General Public License
22 along with ITHACA-FV. If not, see <http://www.gnu.org/licenses/>.
23\*---------------------------------------------------------------------------*/
24
28
30
31
32// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34{
35
36Eigen::VectorXd TSVD(Eigen::MatrixXd A,
37 Eigen::MatrixXd b, int filter)
38{
39 M_Assert(b.cols() == 1, "The b input in TSVD must have only one column");
40 Eigen::JacobiSVD<Eigen::MatrixXd> svd(A,
41 Eigen::ComputeThinU | Eigen::ComputeThinV);
42 Eigen::MatrixXd U = svd.matrixU();
43 Eigen::MatrixXd V = svd.matrixV();
44 Eigen::VectorXd x = Eigen::VectorXd::Zero(b.size());
45
46 for (label i = 0; i < filter; i++)
47 {
48 x += (U.col(i).dot(b.col(0)) / svd.singularValues()(i)) * (V.col(i));
49 }
50
51 return x;
52}
53
54Eigen::VectorXd TSVD(Eigen::MatrixXd A,
55 Eigen::MatrixXd b, double noiseVariance, word parameterMethod)
56{
57 int filter;
58
59 if (parameterMethod == "DP")
60 {
61 Info << "\nRegularization parameter selected by Discrepancy principle" << endl;
62 Eigen::JacobiSVD<Eigen::MatrixXd> svd(A,
63 Eigen::ComputeThinU | Eigen::ComputeThinV);
64 Eigen::MatrixXd U = svd.matrixU();
65 Eigen::VectorXd bVect = b.col(0);
66 double min;
67
68 for (int col = 0; col < U.cols() - 1; col++)
69 {
70 double f = 0;
71
72 for (int i = col + 1; i < U.cols(); i++)
73 {
74 Eigen::VectorXd tempU = U.col(i);
75 f += tempU.col(i).dot(bVect) * tempU.col(i).dot(bVect);
76 }
77
78 f += 2 * noiseVariance * col;
79
80 if (col == 0)
81 {
82 min = f;
83 filter = col + 1;
84 }
85 else if (min > f)
86 {
87 min = f;
88 filter = col + 1;
89 }
90
91 Info << "debug : f = " << f << endl;
92 Info << "debug : min = " << min << endl;
93 Info << "debug : k = " << filter << endl;
94 }
95 }
96 else if (parameterMethod == "UPRE")
97 {
98 Info << "\nRegularization parameter selected by Discrepancy principle" << endl;
99 }
100 else
101 {
102 Info << "Regularization parameter selection methods available are:" << endl
103 << "DP, UPRE" << endl;
104 exit(1);
105 }
106
107 return ITHACAregularization::TSVD(A, b, filter);
108}
109
110Eigen::VectorXd Tikhonov(Eigen::MatrixXd A,
111 Eigen::MatrixXd b, double regularizationParameter)
112{
113 M_Assert(b.cols() == 1, "The b input in TSVD must have only one column");
114 Eigen::MatrixXd Anew = A.transpose() * A + regularizationParameter *
115 Eigen::MatrixXd::Identity(A.rows(), A.cols());
116 Eigen::MatrixXd bNew = A.transpose() * b;
117 Eigen::VectorXd x = A.inverse() * b;
118 Info << "x = \n" << x.transpose() << endl;
119 x = Anew.inverse() * bNew;
120 Info << "xNew = \n" << x.transpose() << endl;
121 return x;
122}
123}
Header file of the ITHACAregularization class, it contains the implementation of several methods for ...
Namespace for regularization of ill-conditione linear system.
Eigen::VectorXd Tikhonov(Eigen::MatrixXd A, Eigen::MatrixXd b, double regularizationParameter)
Truncated Singular Value regularization.
Eigen::VectorXd TSVD(Eigen::MatrixXd A, Eigen::MatrixXd b, int filter)
Truncated Singular Value regularization.