UQTk: Uncertainty Quantification Toolkit 3.1.5
post.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===================================================================================== */
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
44using namespace std; // needed for python string conversion
45
47
48class Post {
49public:
50
52 Post();
54 ~Post() {}
55
57 void setData(Array2D<double>& xdata,Array2D<double>& ydata);
59 void setData(Array2D<double>& xdata,Array1D<Array1D<double> >& ydata);
61 void setDataNoise(Array1D<double>& sigma);
63 void inferDataNoise();
65 void inferLogDataNoise();
67 Array1D<double> dataSigma(double m_last);
69 void setModel(Array1D< Array2D<double> (*)(Array2D<double>&, Array2D<double>&, Array2D<double>&, void *) > forwardFuncs, Array2D<double>& fixindnom, void* funcInfo);
71 void setModelRVinput(int pdim, int order, Array1D<int>& rndInd,string pdfType,string pcType);
73 int getChainDim();
75 void setPrior(string priorType, double priora, double priorb);
83 void momParam(Array1D<double>& m, Array1D<double>& parMean, Array1D<double>& parVar, bool covFlag, Array2D<double>& parCov);
87 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);
89 void momForwardFcn(Array1D<double>& m, Array2D<double>& xgrid, Array1D<double>& fcnMean, Array1D<double>& fcnVar, bool covflag, Array2D<double>& fcnCov);
91 virtual double evalLogLik(Array1D<double>& m){return 0;};
92
93
94protected:
106 int xDim_;
108 int pDim_;
118 //Array2D<double> (*forwardFcn_)(Array2D<double>&, Array2D<double>&, Array2D<double>&, void*);
125 int ncat_;
126
136 string pdfType_;
138 string rvpcType_;
142 double priora_;
144 double priorb_;
145
146 private:
147
150
151};
152
153/*******************************************************************/
154/*******************************************************************/
155/*******************************************************************/
156
159class Lik_Full: public Post {
160public:
162 Lik_Full(double bdw,int nsam){this->bdw_=bdw; this->nsam_=nsam; return;}
165
167 double evalLogLik(Array1D<double>& m);
168
169 private:
171 double bdw_;
173 int nsam_;
174};
175
176/*******************************************************************/
177/*******************************************************************/
178/*******************************************************************/
179
182class Lik_Marg: public Post {
183public:
185 Lik_Marg(double bdw,int nsam){this->bdw_=bdw; this->nsam_=nsam; return;}
188
190 double evalLogLik(Array1D<double>& m);
191
192 private:
194 double bdw_;
196 int nsam_;
197
198};
199
200/*******************************************************************/
201/*******************************************************************/
202/*******************************************************************/
203
206class Lik_MVN: public Post {
207public:
209 Lik_MVN(double nugget){this->nugget_=nugget; return;}
212
214 double evalLogLik(Array1D<double>& m);
215
216 private:
218 double nugget_;
219
220};
221
222/*******************************************************************/
223
226class Lik_GausMarg: public Post {
227public:
229 Lik_GausMarg(){return;}
232
234 double evalLogLik(Array1D<double>& m);
235
236};
237
238/*******************************************************************/
239
242class Lik_GausMargD: public Post {
243public:
245 Lik_GausMargD(){return;}
248
251
252};
253
254/*******************************************************************/
255
258class Lik_ABC: public Post {
259public:
261 Lik_ABC(double eps){this->abceps_=eps; return;}
264
266 double evalLogLik(Array1D<double>& m);
267
268private:
270 double abceps_;
271
272};
273
274/*******************************************************************/
275
278class Lik_ABCm: public Post {
279public:
281 Lik_ABCm(double eps){this->abceps_=eps; return;}
284
286 double evalLogLik(Array1D<double>& m);
287
288private:
290 double abceps_;
291
292};
293
294/*******************************************************************/
295
298class Lik_Koh: public Post {
299public:
301 Lik_Koh(double corLength){ this->extraInferredParams_=1;this->corLength_=corLength; return;}
304
306 double evalLogLik(Array1D<double>& m);
307private:
309
310};
311
312/*******************************************************************/
313
316class Lik_Classical: public Post {
317public:
319 Lik_Classical(){ return;}
322
324 double evalLogLik(Array1D<double>& m);
325
326
327};
328
329/*******************************************************************/
332class Lik_Eov: public Post {
333public:
335 Lik_Eov(){ return;}
338
340 double evalLogLik(Array1D<double>& m);
341
342
343};
344
345/*******************************************************************/
346
347#endif /* POST_H_SEEN */
1D Array class for any type T
2D Array class for any type T
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
Derived class for ABC likelihood.
Definition post.h:258
double evalLogLik(Array1D< double > &m)
Evaluate log-likelihood.
Definition post.cpp:623
Lik_ABC(double eps)
Constructor given ABC epsilon.
Definition post.h:261
~Lik_ABC()
Destructor.
Definition post.h:263
double abceps_
ABC epsilon.
Definition post.h:270
Derived class for ABC-mean likelihood.
Definition post.h:278
~Lik_ABCm()
Destructor.
Definition post.h:283
Lik_ABCm(double eps)
Constructor given ABC epsilon.
Definition post.h:281
double abceps_
ABC epsilon.
Definition post.h:290
double evalLogLik(Array1D< double > &m)
Evaluate log-likelihood.
Definition post.cpp:662
Derived class for classical likelihood.
Definition post.h:316
double evalLogLik(Array1D< double > &m)
Evaluate log-likelihood.
Definition post.cpp:741
Lik_Classical()
Constructor.
Definition post.h:319
~Lik_Classical()
Destructor.
Definition post.h:321
Derived class for error-in-variable likelihood.
Definition post.h:332
double evalLogLik(Array1D< double > &m)
Evaluate log-likelihood.
Definition post.cpp:774
Lik_Eov()
Constructor.
Definition post.h:335
~Lik_Eov()
Destructor.
Definition post.h:337
Derived class for full likelihood.
Definition post.h:159
~Lik_Full()
Destructor.
Definition post.h:164
double bdw_
KDE bandwidth.
Definition post.h:171
int nsam_
KDE sample size.
Definition post.h:173
double evalLogLik(Array1D< double > &m)
Evaluate log-likelihood.
Definition post.cpp:437
Lik_Full(double bdw, int nsam)
Constructor given KDE bandwidth and sample size.
Definition post.h:162
Derived class for gaussian-marginal likelihood with discrete parameter.
Definition post.h:242
~Lik_GausMargD()
Destructor.
Definition post.h:247
Lik_GausMargD()
Constructor.
Definition post.h:245
double evalLogLik(Array1D< double > &m)
Evaluate log-likelihood.
Derived class for gaussian-marginal likelihood.
Definition post.h:226
Lik_GausMarg()
Constructor.
Definition post.h:229
~Lik_GausMarg()
Destructor.
Definition post.h:231
double evalLogLik(Array1D< double > &m)
Evaluate log-likelihood.
Definition post.cpp:589
Derived class for Kennedy-O'Hagan likelihood.
Definition post.h:298
Lik_Koh(double corLength)
Constructor given correlation length.
Definition post.h:301
double evalLogLik(Array1D< double > &m)
Evaluate log-likelihood.
Definition post.cpp:694
double corLength_
Definition post.h:308
~Lik_Koh()
Destructor.
Definition post.h:303
Derived class for mvn likelihood.
Definition post.h:206
double evalLogLik(Array1D< double > &m)
Evaluate log-likelihood.
Definition post.cpp:556
double nugget_
Nugget size.
Definition post.h:218
~Lik_MVN()
Destructor.
Definition post.h:211
Lik_MVN(double nugget)
Constructor given fiagonal nugget.
Definition post.h:209
Derived class for marginal likelihood.
Definition post.h:182
int nsam_
KDE sample size.
Definition post.h:196
double bdw_
KDE bandwidth.
Definition post.h:194
Lik_Marg(double bdw, int nsam)
Constructor given KDE bandwidth and sample size.
Definition post.h:185
~Lik_Marg()
Destructor.
Definition post.h:187
double evalLogLik(Array1D< double > &m)
Evaluate log-likelihood.
Definition post.cpp:497
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
Definition post.h:100
Array2D< double > xData_
xdata
Definition post.h:96
Array1D< Array1D< double > > yData_
ydata
Definition post.h:98
Post()
Constructor.
Definition post.cpp:51
void * funcinfo_
Auxiliary information for function evaluation.
Definition post.h:121
Array1D< double > dataNoiseSig_
Data noise stdev.
Definition post.h:116
void setModel(Array1D< Array2D< double >(*)(Array2D< double > &, Array2D< double > &, Array2D< double > &, void *) > forwardFuncs, Array2D< double > &fixindnom, void *funcInfo)
Set a pointer to the forward model f(p,x)
Definition post.cpp:153
void inferLogDataNoise()
Indicate inference of log of data noise stdev.
Definition post.cpp:123
Array1D< double > upper_
Definition post.h:134
Array1D< double > dataSigma(double m_last)
Get data noise, whether inferred or fixed.
Definition post.cpp:133
bool dataNoiseLogFlag_
Flag to check if data noise logarithm is used.
Definition post.h:114
void setModelRVinput(int pdim, int order, Array1D< int > &rndInd, string pdfType, string pcType)
Set model input parameters' randomization scheme.
Definition post.cpp:163
Array1D< Array2D< double >(*)(Array2D< double > &, Array2D< double > &, Array2D< double > &, void *) > forwardFcns_
Pointer to the forward function f(p,x)
Definition post.h:119
double priora_
Prior parameter #1.
Definition post.h:142
Array1D< int > nEachs_
Number of samples at each input.
Definition post.h:104
void setDataNoise(Array1D< double > &sigma)
Set the magnitude of data noise.
Definition post.cpp:98
int nData_
Number of data points.
Definition post.h:102
int verbosity_
Verbosity level.
Definition post.h:149
Array1D< double > lower_
Lower and upper bounds on parameters.
Definition post.h:134
~Post()
Destructor.
Definition post.h:54
int pDim_
Dimensionality of parameter space (p-space)
Definition post.h:108
int chDim_
Dimensionality of posterior input.
Definition post.h:110
Array1D< int > rndInd_
Indices of randomized inputs.
Definition post.h:130
double evalLogPrior(Array1D< double > &m)
Evaluate log-prior.
Definition post.cpp:211
Array2D< double > samParam(Array1D< double > &m, int ns)
Sample model parameters given posterior input.
Definition post.cpp:338
Array2D< double > fixIndNom_
Indices and nominal values for fixed inputs.
Definition post.h:132
bool inferDataNoise_
Flag for data noise inference.
Definition post.h:112
int getChainDim()
Get the dimensionailty of the posterior function.
Definition post.cpp:195
void momParam(Array1D< double > &m, Array1D< double > &parMean, Array1D< double > &parVar, bool covFlag, Array2D< double > &parCov)
Get moments of parameters given posterior input.
Definition post.cpp:348
void setPrior(string priorType, double priora, double priorb)
Set the prior type and its parameters.
Definition post.cpp:201
int extraInferredParams_
Number of extra inferred parameters, such as data noise or Koh variance.
Definition post.h:123
void setData(Array2D< double > &xdata, Array2D< double > &ydata)
Set the x- and y-data.
Definition post.cpp:58
int xDim_
Dimensionality of x-space.
Definition post.h:106
Array2D< double > samForwardFcn(Array2D< double >(*forwardFunc)(Array2D< double > &, Array2D< double > &, Array2D< double > &, void *), Array1D< double > &m, Array2D< double > &xgrid, int ns)
Sample forward function at a given grid for given posterior input.
Definition post.cpp:360
double priorb_
Prior parameter #2.
Definition post.h:144
int ncat_
Number of categories.
Definition post.h:125
string priorType_
Prior type.
Definition post.h:140
Mrv * Mrv_
Pointer to a multivariate PC RV object.
Definition post.h:128
virtual double evalLogLik(Array1D< double > &m)
Dummy evaluation of log-likelihood.
Definition post.h:91
string pdfType_
Input parameter PDF type.
Definition post.h:136
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)
Get moments of forward function at a given grid for given posterior input.
Definition post.cpp:372
string rvpcType_
PC type parameter for the r.v.
Definition post.h:138
Array2D< double > getParamPCcf(Array1D< double > &m)
Extract parameter PC coefficients from a posterior input.
Definition post.cpp:326
void inferDataNoise()
Indicate inference of data noise stdev.
Definition post.cpp:111
Header for multivariate random variable class.