UQTk: Uncertainty Quantification Toolkit 3.1.5
lreg.h
Go to the documentation of this file.
1/* =====================================================================================
2
3 The UQ Toolkit (UQTk) version 3.1.5
4 Copyright (2024) NTESS
5 https://www.sandia.gov/UQToolkit/
6 https://github.com/sandialabs/UQTk
7
8 Copyright 2024 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
9 Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government
10 retains certain rights in this software.
11
12 This file is part of The UQ Toolkit (UQTk)
13
14 UQTk is open source software: you can redistribute it and/or modify
15 it under the terms of BSD 3-Clause License
16
17 UQTk 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 BSD 3 Clause License for more details.
21
22 You should have received a copy of the BSD 3 Clause License
23 along with UQTk. If not, see https://choosealicense.com/licenses/bsd-3-clause/.
24
25 Questions? Contact the UQTk Developers at https://github.com/sandialabs/UQTk/discussions
26 Sandia National Laboratories, Livermore, CA, USA
27===================================================================================== */
32
33#ifndef LREG_H_SEEN
34#define LREG_H_SEEN
35
36#include "Array1D.h"
37#include "Array2D.h"
38
41class Lreg {
42public:
43
45 Lreg() {residFlag_=false; diagPFlag_=false; sigma2_.Resize(1,0.e0); return;};
47 ~Lreg() {};
48 //void testing();
49
51 virtual void SetMindex(Array2D<int>& mindex){};
53 virtual void GetMindex(Array2D<int>& mindex){};
55 virtual void SetCenters(Array2D<double>& centers){};
57 virtual void SetWidths(Array1D<double>& widths){};
59 virtual void SetParamsRBF(){};
61 virtual void EvalBases(Array2D<double>& xx,Array2D<double>& bb){};// dummy
63 virtual void StripBases(Array1D<int>& used){};
64
66 void InitRegr();
68 void SetupData(Array2D<double>& xdata, Array1D<double>& ydata);
70 void SetupData(Array2D<double>& xdata, Array2D<double>& ydata);
72 void SetRegMode(string regmode){regMode_=regmode; return;}
74 void SetRegWeights(Array1D<double>& weights);
76 void BCS_BuildRegr(Array1D<int>& selected, double eta);
78 void LSQ_BuildRegr();
81
83 int GetNpt() const {return npt_;}
85 int GetNdim() const {return ndim_;}
87 int GetNbas() const {return nbas_;}
89 double GetSigma2() const {return sigma2_(0);}
91 void GetCoefCov(Array2D<double>& coef_cov) {coef_cov=coef_cov_; return;}
93 void GetCoef(Array1D<double>& coef) {coef=coef_; return;}
95 void Proj(Array1D<double>& array,Array1D<double>& proj_array);
99 double LSQ_computeBestLambda();
101 void getResid();
103 void getDiagP();
107 double computeRVE(Array2D<double>& xval,Array1D<double>& yval,Array1D<double>& yval_regr);
108
109
110 protected:
111
116
118 int npt_;
120 int nbas_;
122 int ndim_;
124 Array1D<double> sigma2_; // Defined as an array of length one for ease of passing it through Pybind
125 // double sigma2_;
136
138
142
143private:
144
146 double LSQ_computeLOO();
148 double LSQ_computeGCV();
152 string regMode_;
153
154};
155
158class RBFreg: public Lreg {
159public:
161 RBFreg(Array2D<double>& centers, Array1D<double>& widths);
164
166 void SetCenters(Array2D<double>& centers);
168 void SetWidths(Array1D<double>& widths);
169
173 void StripBases(Array1D<int>& used);
174
175private:
180
181};
182
185class PCreg: public Lreg {
186public:
188 PCreg(string strpar,int order,int dim);
189 PCreg(string strpar,Array2D<int>& mindex);
191 ~PCreg() {};
192
196 void StripBases(Array1D<int>& used);
198 void SetMindex(Array2D<int>& mindex){mindex_=mindex;}
200 void GetMindex(Array2D<int>& mindex){mindex=mindex_;return;}
201
202private:
206 string pctype_;
207
208};
209
212class PLreg: public Lreg {
213public:
215 PLreg(int order, int dim);
216 PLreg(Array2D<int>& mindex);
218 ~PLreg() {};
219
223 void StripBases(Array1D<int>& used);
225 void SetMindex(Array2D<int>& mindex){mindex_=mindex;}
227 void GetMindex(Array2D<int>& mindex){mindex=mindex_;return;}
228
229
230private:
233
234};
235
236#endif /* LREG_H_SEEN */
1D Array class for any type T
2D Array class for any type T
void Resize(const int &nx)
Resizes the array.
Definition Array1D.h:545
Stores data of any type T in a 1D array.
Definition Array1D.h:61
Stores data of any type T in a 2D array.
Definition Array2D.h:60
Class for linear parameteric regression.
Definition lreg.h:41
int GetNbas() const
Get the number of bases.
Definition lreg.h:87
Array1D< double > LSQ_computeBestLambdas()
Compute the best values for regulariation parameter vector lambda, for LSQ.
Definition lreg.cpp:384
Array1D< double > ydata_
ydata array
Definition lreg.h:115
Array1D< double > diagP_
Diagonal of projection matrix.
Definition lreg.h:133
void BCS_BuildRegr(Array1D< int > &selected, double eta)
Build BCS regression.
Definition lreg.cpp:206
int nbas_
Number of bases.
Definition lreg.h:120
Array1D< double > sigma2_
Variance.
Definition lreg.h:124
bool dataSetFlag_
Flag to indicate whether data has been set or not.
Definition lreg.h:150
~Lreg()
Destrcutor.
Definition lreg.h:47
void SetRegWeights(Array1D< double > &weights)
Set weights.
Definition lreg.cpp:197
double LSQ_computeGCV()
COmpute generalized-cross-validation error for LSQ.
Definition lreg.cpp:504
virtual void SetParamsRBF()
Set parameters (for RBF)
Definition lreg.h:59
bool residFlag_
Flag to indicate whether residual is computed.
Definition lreg.h:131
void GetCoef(Array1D< double > &coef)
Get coefficients.
Definition lreg.h:93
Array2D< double > xdata_
xdata array
Definition lreg.h:113
Array2D< double > A_inv_
Definition lreg.h:139
int GetNpt() const
Get the number of points.
Definition lreg.h:83
Array1D< double > Hty_
Definition lreg.h:140
void GetCoefCov(Array2D< double > &coef_cov)
Get coefficient covariance.
Definition lreg.h:91
int GetNdim() const
Get dimensionality.
Definition lreg.h:85
void getResid()
Compute the residual vector, if not already computed.
Definition lreg.cpp:423
Array1D< double > computeErrorMetrics(string method)
Compote error according to a selected metrics.
Definition lreg.cpp:454
Array2D< double > coef_cov_
Definition lreg.h:139
virtual void StripBases(Array1D< int > &used)
Strip bases.
Definition lreg.h:63
string regMode_
Regression mode (m, ms, msc for mean-only, mean+variance, mean+covariance)
Definition lreg.h:152
virtual void GetMindex(Array2D< int > &mindex)
Get multiindex.
Definition lreg.h:53
virtual void SetMindex(Array2D< int > &mindex)
Set multiindex.
Definition lreg.h:51
Array2D< double > bdata_
Auxiliary matrix or vector; see UQTk Manual.
Definition lreg.h:139
double computeRVE(Array2D< double > &xval, Array1D< double > &yval, Array1D< double > &yval_regr)
Compute validation error.
Definition lreg.cpp:470
double GetSigma2() const
Get the variance of the data.
Definition lreg.h:89
Array1D< double > resid_
Residuals.
Definition lreg.h:129
virtual void EvalBases(Array2D< double > &xx, Array2D< double > &bb)
Evaluate bases.
Definition lreg.h:61
int ndim_
Dimensionality.
Definition lreg.h:122
void InitRegr()
Initialize.
Definition lreg.cpp:133
Array1D< double > coef_
Definition lreg.h:140
void Proj(Array1D< double > &array, Array1D< double > &proj_array)
Project.
Definition lreg.cpp:368
void SetRegMode(string regmode)
Set the regression mode.
Definition lreg.h:72
Array2D< double > A_
Definition lreg.h:139
Array1D< double > coef_erb_
Definition lreg.h:140
void EvalRegr(Array2D< double > &xcheck, Array1D< double > &ycheck, Array1D< double > &yvar, Array2D< double > &ycov)
Evaluate the regression expansion.
Definition lreg.cpp:301
Array1D< double > weights_
Weights.
Definition lreg.h:127
void LSQ_BuildRegr()
Build LSQ regression.
Definition lreg.cpp:238
virtual void SetWidths(Array1D< double > &widths)
Set widths (for RBF)
Definition lreg.h:57
void SetupData(Array2D< double > &xdata, Array1D< double > &ydata)
Setup data (1d ydata)
Definition lreg.cpp:151
double LSQ_computeLOO()
Compute Leave-one-out error for LSQ.
Definition lreg.cpp:492
void getDiagP()
Compute the diagonal of projection matrix, if not already computed.
Definition lreg.cpp:436
double LSQ_computeBestLambda()
Compute the best value for regulariation parameter lambda, for LSQ.
Definition lreg.cpp:404
int npt_
Number of samples.
Definition lreg.h:118
bool diagPFlag_
Flag to indicate whether diagonal of projetion matrix is computed.
Definition lreg.h:135
virtual void SetCenters(Array2D< double > &centers)
Set centers (for RBF)
Definition lreg.h:55
Lreg()
Constructor.
Definition lreg.h:45
Derived class for PC regression.
Definition lreg.h:185
~PCreg()
Destructor.
Definition lreg.h:191
PCreg(string strpar, int order, int dim)
Constructors:
Definition lreg.cpp:76
Array2D< int > mindex_
Multiindex.
Definition lreg.h:204
void EvalBases(Array2D< double > &xx, Array2D< double > &bb)
Evaluate the bases.
Definition lreg.cpp:540
string pctype_
PC type.
Definition lreg.h:206
void SetMindex(Array2D< int > &mindex)
Set multiindex.
Definition lreg.h:198
void StripBases(Array1D< int > &used)
Strip the bases.
Definition lreg.cpp:596
void GetMindex(Array2D< int > &mindex)
Get multiindex.
Definition lreg.h:200
Derived class for polynomial regression.
Definition lreg.h:212
void StripBases(Array1D< int > &used)
Strip the bases.
Definition lreg.cpp:610
void SetMindex(Array2D< int > &mindex)
Set multiindex.
Definition lreg.h:225
void GetMindex(Array2D< int > &mindex)
Get multiindex.
Definition lreg.h:227
PLreg(int order, int dim)
Constructors:
Definition lreg.cpp:104
void EvalBases(Array2D< double > &xx, Array2D< double > &bb)
Evaluate the bases.
Definition lreg.cpp:553
Array2D< int > mindex_
Multiindex.
Definition lreg.h:232
~PLreg()
Destructor.
Definition lreg.h:218
Derived class for RBF regression.
Definition lreg.h:158
void SetWidths(Array1D< double > &widths)
Set widths.
Definition lreg.cpp:532
RBFreg(Array2D< double > &centers, Array1D< double > &widths)
Constructor:
Definition lreg.cpp:64
void EvalBases(Array2D< double > &xx, Array2D< double > &bb)
Evaluate the bases.
Definition lreg.cpp:574
~RBFreg()
Destructor.
Definition lreg.h:163
Array2D< double > centers_
RBF centers.
Definition lreg.h:177
void StripBases(Array1D< int > &used)
Strip the bases.
Definition lreg.cpp:624
void SetCenters(Array2D< double > &centers)
Set centers.
Definition lreg.cpp:523
Array1D< double > widths_
RBF bases' widhts.
Definition lreg.h:179