UQTk: Uncertainty Quantification Toolkit  3.1.1
post.h
Go to the documentation of this file.
1 /* =====================================================================================
2 
3  The UQ Toolkit (UQTk) version 3.1.1
4  Copyright (2021) NTESS
5  https://www.sandia.gov/UQToolkit/
6  https://github.com/sandialabs/UQTk
7 
8  Copyright 2021 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 <uqtk-developers@software.sandia.gov>
26  Sandia National Laboratories, Livermore, CA, USA
27 ===================================================================================== */
31 
32 #ifndef POST_H_SEEN
33 #define POST_H_SEEN
34 
35 #include "Array1D.h"
36 #include "Array2D.h"
37 #include "mrv.h"
38 
39 #include <iostream>
40 #include <string.h>
41 #include <stdio.h>
42 #include <sstream>
43 
44 using namespace std; // needed for python string conversion
45 
47 
48 class Post {
49 public:
50 
52  Post();
54  ~Post() {}
55 
57  void setData(Array2D<double>& xdata,Array2D<double>& ydata);
59  void setDataNoise(Array1D<double>& sigma);
61  void inferDataNoise();
63  void inferLogDataNoise();
65  Array1D<double> dataSigma(double m_last);
67  void setModel(Array1D< Array2D<double> (*)(Array2D<double>&, Array2D<double>&, Array2D<double>&, void *) > forwardFuncs, Array2D<double>& fixindnom, void* funcInfo);
69  void setModelRVinput(int pdim, int order, Array1D<int>& rndInd,string pdfType,string pcType);
71  int getChainDim();
73  void setPrior(string priorType, double priora, double priorb);
75  double evalLogPrior(Array1D<double>& m);
77  Array2D<double> getParamPCcf(Array1D<double>& m);
79  Array2D<double> samParam(Array1D<double>& m, int ns);
81  void momParam(Array1D<double>& m, Array1D<double>& parMean, Array1D<double>& parVar, bool covFlag, Array2D<double>& parCov);
83  Array2D<double> samForwardFcn(Array2D<double> (*forwardFunc)(Array2D<double>&, Array2D<double>&, Array2D<double>&, void*),Array1D<double>& m, Array2D<double>& xgrid, int ns);
85  void momForwardFcn(Array2D<double> (*forwardFunc)(Array2D<double>&, Array2D<double>&, Array2D<double>&, void*),Array1D<double>& m, Array2D<double>& xgrid, Array1D<double>& fcnMean, Array1D<double>& fcnVar, bool covflag, Array2D<double>& fcnCov);
87  void momForwardFcn(Array1D<double>& m, Array2D<double>& xgrid, Array1D<double>& fcnMean, Array1D<double>& fcnVar, bool covflag, Array2D<double>& fcnCov);
89  virtual double evalLogLik(Array1D<double>& m){return 0;};
90 
91 
92 protected:
100  int nData_;
102  int nEach_;
104  int xDim_;
106  int pDim_;
108  int chDim_;
116  //Array2D<double> (*forwardFcn_)(Array2D<double>&, Array2D<double>&, Array2D<double>&, void*);
119  void* funcinfo_;
123  int ncat_;
124 
134  string pdfType_;
136  string rvpcType_;
138  string priorType_;
140  double priora_;
142  double priorb_;
143 
144  private:
145 
148 
149 };
150 
151 /*******************************************************************/
152 /*******************************************************************/
153 /*******************************************************************/
154 
157 class Lik_Full: public Post {
158 public:
160  Lik_Full(double bdw,int nsam){this->bdw_=bdw; this->nsam_=nsam; return;}
163 
165  double evalLogLik(Array1D<double>& m);
166 
167  private:
169  double bdw_;
171  int nsam_;
172 };
173 
174 /*******************************************************************/
175 /*******************************************************************/
176 /*******************************************************************/
177 
180 class Lik_Marg: public Post {
181 public:
183  Lik_Marg(double bdw,int nsam){this->bdw_=bdw; this->nsam_=nsam; return;}
186 
188  double evalLogLik(Array1D<double>& m);
189 
190  private:
192  double bdw_;
194  int nsam_;
195 
196 };
197 
198 /*******************************************************************/
199 /*******************************************************************/
200 /*******************************************************************/
201 
204 class Lik_MVN: public Post {
205 public:
207  Lik_MVN(double nugget){this->nugget_=nugget; return;}
209  ~Lik_MVN(){};
210 
212  double evalLogLik(Array1D<double>& m);
213 
214  private:
216  double nugget_;
217 
218 };
219 
220 /*******************************************************************/
221 
224 class Lik_GausMarg: public Post {
225 public:
227  Lik_GausMarg(){return;}
230 
232  double evalLogLik(Array1D<double>& m);
233 
234 };
235 
236 /*******************************************************************/
237 
240 class Lik_GausMargD: public Post {
241 public:
243  Lik_GausMargD(){return;}
246 
249 
250 };
251 
252 /*******************************************************************/
253 
256 class Lik_ABC: public Post {
257 public:
259  Lik_ABC(double eps){this->abceps_=eps; return;}
261  ~Lik_ABC(){};
262 
264  double evalLogLik(Array1D<double>& m);
265 
266 private:
268  double abceps_;
269 
270 };
271 
272 /*******************************************************************/
273 
276 class Lik_ABCm: public Post {
277 public:
279  Lik_ABCm(double eps){this->abceps_=eps; return;}
282 
284  double evalLogLik(Array1D<double>& m);
285 
286 private:
288  double abceps_;
289 
290 };
291 
292 /*******************************************************************/
293 
296 class Lik_Koh: public Post {
297 public:
299  Lik_Koh(double corLength){ this->extraInferredParams_=1;this->corLength_=corLength; return;}
301  ~Lik_Koh(){};
302 
304  double evalLogLik(Array1D<double>& m);
305 private:
306  double corLength_;
307 
308 };
309 
310 /*******************************************************************/
311 
314 class Lik_Classical: public Post {
315 public:
317  Lik_Classical(){ return;}
320 
322  double evalLogLik(Array1D<double>& m);
323 
324 
325 };
326 
327 /*******************************************************************/
330 class Lik_Eov: public Post {
331 public:
333  Lik_Eov(){ return;}
335  ~Lik_Eov(){};
336 
338  double evalLogLik(Array1D<double>& m);
339 
340 
341 };
342 
343 /*******************************************************************/
344 
345 #endif /* POST_H_SEEN */
1D Array class for any type T
2D Array class for any type T
Definition: Array1D.h:472
Definition: Array1D.h:262
Stores data of any type T in a 1D array.
Definition: Array1D.h:61
Derived class for ABC likelihood.
Definition: post.h:256
Lik_ABC(double eps)
Constructor given ABC epsilon.
Definition: post.h:259
~Lik_ABC()
Destructor.
Definition: post.h:261
double abceps_
ABC epsilon.
Definition: post.h:268
Derived class for ABC-mean likelihood.
Definition: post.h:276
~Lik_ABCm()
Destructor.
Definition: post.h:281
Lik_ABCm(double eps)
Constructor given ABC epsilon.
Definition: post.h:279
double abceps_
ABC epsilon.
Definition: post.h:288
Derived class for classical likelihood.
Definition: post.h:314
Lik_Classical()
Constructor.
Definition: post.h:317
~Lik_Classical()
Destructor.
Definition: post.h:319
Derived class for error-in-variable likelihood.
Definition: post.h:330
Lik_Eov()
Constructor.
Definition: post.h:333
~Lik_Eov()
Destructor.
Definition: post.h:335
Derived class for full likelihood.
Definition: post.h:157
~Lik_Full()
Destructor.
Definition: post.h:162
double bdw_
KDE bandwidth.
Definition: post.h:169
int nsam_
KDE sample size.
Definition: post.h:171
Lik_Full(double bdw, int nsam)
Constructor given KDE bandwidth and sample size.
Definition: post.h:160
Derived class for gaussian-marginal likelihood with discrete parameter.
Definition: post.h:240
~Lik_GausMargD()
Destructor.
Definition: post.h:245
Lik_GausMargD()
Constructor.
Definition: post.h:243
double evalLogLik(Array1D< double > &m)
Evaluate log-likelihood.
Derived class for gaussian-marginal likelihood.
Definition: post.h:224
Lik_GausMarg()
Constructor.
Definition: post.h:227
~Lik_GausMarg()
Destructor.
Definition: post.h:229
Derived class for Kennedy-O'Hagan likelihood.
Definition: post.h:296
Lik_Koh(double corLength)
Constructor given correlation length.
Definition: post.h:299
double corLength_
Definition: post.h:306
~Lik_Koh()
Destructor.
Definition: post.h:301
Derived class for mvn likelihood.
Definition: post.h:204
double nugget_
Nugget size.
Definition: post.h:216
~Lik_MVN()
Destructor.
Definition: post.h:209
Lik_MVN(double nugget)
Constructor given fiagonal nugget.
Definition: post.h:207
Derived class for marginal likelihood.
Definition: post.h:180
int nsam_
KDE sample size.
Definition: post.h:194
double bdw_
KDE bandwidth.
Definition: post.h:192
Lik_Marg(double bdw, int nsam)
Constructor given KDE bandwidth and sample size.
Definition: post.h:183
~Lik_Marg()
Destructor.
Definition: post.h:185
multivariate RV parameterized by PC expansions
Definition: mrv.h:48
posterior evaluation with various likelihood and prior options
Definition: post.h:48
Array1D< double > yDatam_
ydata averaged per measurement (in case more than one y is given for each x)
Definition: post.h:98
Array2D< double > xData_
xdata
Definition: post.h:89
void * funcinfo_
Auxiliary information for function evaluation.
Definition: post.h:119
Array1D< double > dataNoiseSig_
Data noise stdev.
Definition: post.h:114
bool dataNoiseLogFlag_
Flag to check if data noise logarithm is used.
Definition: post.h:112
double priora_
Prior parameter #1.
Definition: post.h:140
int nData_
Number of data points.
Definition: post.h:100
int verbosity_
Verbosity level.
Definition: post.h:147
Array1D< double > lower_
Lower and upper bounds on parameters.
Definition: post.h:132
~Post()
Destructor.
Definition: post.h:54
int pDim_
Dimensionality of parameter space (p-space)
Definition: post.h:106
int chDim_
Dimensionality of posterior input.
Definition: post.h:108
Array1D< int > rndInd_
Indices of randomized inputs.
Definition: post.h:128
Array2D< double > fixIndNom_
Indices and nominal values for fixed inputs.
Definition: post.h:130
int nEach_
Number of samples at each input.
Definition: post.h:102
Array2D< double > yData_
ydata
Definition: post.h:96
bool inferDataNoise_
Flag for data noise inference.
Definition: post.h:110
int extraInferredParams_
Number of extra inferred parameters, such as data noise or Koh variance.
Definition: post.h:121
int xDim_
Dimensionality of x-space.
Definition: post.h:104
double priorb_
Prior parameter #2.
Definition: post.h:142
int ncat_
Number of categories.
Definition: post.h:123
string priorType_
Prior type.
Definition: post.h:138
Mrv * Mrv_
Pointer to a multivariate PC RV object.
Definition: post.h:126
virtual double evalLogLik(Array1D< double > &m)
Dummy evaluation of log-likelihood.
Definition: post.h:89
string pdfType_
Input parameter PDF type.
Definition: post.h:134
string rvpcType_
PC type parameter for the r.v.
Definition: post.h:136
Header for multivariate random variable class.