Loading...
Searching...
No Matches
LRSensitivity.C
Go to the documentation of this file.
1#include "LRSensitivity.H"
2
3
4using std::vector;
5using std::string;
6
7// Constructors
9
10LRSensitivity::LRSensitivity(label Npara, label Np)
11{
12 No_parameters = Npara;
13 Npoints = Np;
14 setAll();
15}
16
17
18void LRSensitivity::buildSamplingSet(std::vector<std::string>& pdflist,
19 Eigen::MatrixXd plist)
20{
21 for (label i = 0; i < No_parameters; i++)
22 {
23 MatX.col(i) = ITHACAsampling::samplingMC(pdflist[i], trainingRange(i, 0),
24 trainingRange(i, 1), plist(i, 0), plist(i, 1), Npoints);
25 }
26}
27
28
29void LRSensitivity::setAll()
30{
31 MatX.resize(Npoints, No_parameters);
32 MatX.setZero();
34 MatXn.setZero();
36 trainingRange.setZero();
37 y.resize(Npoints);
38 y.setZero();
39 yn.resize(Npoints);
40 yn.setZero();
41 ylin.resize(Npoints);
42 ylin.setZero();
43 EX.resize(No_parameters);
44 EX.setZero();
45 VX.resize(No_parameters);
46 VX.setZero();
47 betas.resize(No_parameters);
48 betas.setZero();
49}
50
52{
53 if (M().MObuilt == true)
54 {
55 y = M().modelOutput;
56 }
57 else
58 {
59 std::cout << "Model output not computed or assigned, program aborted" <<
60 std::endl;
61 exit(0);
62 }
63}
64
66{
67 Ey = 0;
68 Vy = 0;
69 Ey = y.sum() / Npoints;
70
71 for (label i = 0; i < Npoints; i++)
72 {
73 Vy += (y(i) - Ey) * (y(i) - Ey);
74 }
75
76 Vy = Vy / (Npoints - 1);
77 Ydone = true;
78}
79
81{
82 for (label i = 0; i < No_parameters; i++)
83 {
84 EX(i) = MatX.col(i).sum() / Npoints;
85 VX(i) = 0;
86
87 for (label j = 0; j < Npoints; j++)
88 {
89 VX(i) += (MatX(j, i) - EX(i)) * (MatX(j, i) - EX(i));
90 }
91
92 VX(i) = VX(i) / (Npoints - 1);
93 }
94
95 Xdone = true;
96}
97
98
100{
101 if (Ydone == true && Xdone == true)
102 {
103 //Normalize independent variables and output
104 for (label j = 0; j < Npoints; j++)
105 {
106 yn(j) = (y(j) - Ey) / std::sqrt(Vy);
107
108 for (label i = 0; i < No_parameters; i++)
109 {
110 MatXn(j, i) = (MatX(j, i) - EX(i)) / std::sqrt(VX(i));
111 }
112 }
113
114 Eigen::MatrixXd A = MatXn.transpose() * MatXn;
115 Eigen::VectorXd sol = MatXn.transpose() * yn;
116 betas = A.colPivHouseholderQr().solve(sol);
117 bdone = true;
118 }
119 else
120 {
121 std::cout <<
122 "Statistics about inputs or output are not computed yet, nothing to do ..." <<
123 std::endl;
124 }
125}
126
128{
129 if (bdone == true)
130 {
131 QI = 0;
132 double N = 0;
133 double D = 0;
134
135 for (label j = 0; j < Npoints; j++)
136 {
137 ylin(j) = Ey;
138
139 for (label i = 0; i < No_parameters; i++)
140 {
141 ylin(j) += betas(i) * MatXn(j, i) * std::sqrt(Vy);
142 }
143
144 N += (ylin(j) - Ey) * (ylin(j) - Ey);
145 D += (y(j) - Ey) * (y(j) - Ey);
146 }
147
148 QI = N / D;
149 }
150 else
151 {
152 std::cout <<
153 "Linear regression coefficients are not computed yet, nothing to do ..." <<
154 std::endl;
155 }
156}
157
158
159
static Eigen::VectorXd samplingMC(std::string pdftype, double &lowerE, double &upperE, double &distpara1, double &distpara2, label &Npoints)
void getYstat()
Method to compute Ey and Vy, it sets Ydone=true.
void getXstats()
Method to compute EX and VX, it sets Xdone=true.
double Vy
Variance of the output.
Eigen::VectorXd y
Vectors to store the output of the model.
Eigen::VectorXd yn
Vector to store the normalized output of the model.
Eigen::MatrixXd MatXn
Matrices storing the independent variables' normalized values.
double QI
double to quantify the goodness of linear regression from 0 (no linearity) to 1 (perfect linearity) a...
Eigen::MatrixXd MatX
Matrices storing the independent variables' values.
Eigen::VectorXd VX
Vector to store the variances of the parameters.
double Ey
Mean value of the output.
label No_parameters
Number of parameters used for the analysis.
void getBetas()
Method to compute SRCs, it sets bdone=true.
void load_output()
Method to load the output of FOM/ROM inside member LRsensitivity member y.
label Npoints
Number of points used for Monte Carlo sampling.
bool bdone
boolean variable to check if SRCs are computed
Eigen::VectorXd ylin
Vector to store the result of linear approximation.
Eigen::MatrixXd trainingRange
Matrix to store the range used in training/offline stage.
Eigen::VectorXd betas
Vector to store the standardized regression coefficient (SRC)
void assessQuality()
Method to compute the quality of linear regression approximation.
void buildSamplingSet(std::vector< std::string > &pdflist, Eigen::MatrixXd plist)
Method to build MatX, it internally calls ITHACAsampling::samplingMC pdflist is the list with the nam...
Eigen::VectorXd EX
Vector to store the meanvalues of the parameters.
autoPtr< FofM > M
Figure of merit object.
bool Ydone
boolean variable to check if Ey and Vy are computed
bool Xdone
boolean variable to check if EX and VX are computed
volScalarField & A
volScalarField & D
label i
Definition pEqn.H:46