queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
InfiniteDimensionalGaussian.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2017 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include <memory>
26 #include <vector>
27 #include <cmath>
28 
29 #include <queso/InfiniteDimensionalMeasureBase.h>
30 #include <queso/InfiniteDimensionalGaussian.h>
31 #include <queso/Environment.h>
32 #include <queso/FunctionBase.h>
33 #include <queso/OperatorBase.h>
34 #include <queso/RngBase.h>
35 
36 namespace QUESO {
37 
39  const FullEnvironment& env,
40  const FunctionBase & mean,
41  const OperatorBase & precision,
42  double alpha,
43  double beta)
45  mean(mean),
46  precision(precision),
47  env(env),
48  alpha(alpha),
49  beta(beta)
50 {
51  this->coeffs.resize(this->precision.get_num_converged(), 0.0);
52 }
53 
55 {
56 }
57 
59 {
60  unsigned int i;
61 
62  for (i = 0; i < this->precision.get_num_converged(); i++) {
63  (this->coeffs)[i] = env.rngObject()->gaussianSample(this->beta);
64  }
65 
66  SharedPtr<FunctionBase>::Type f(this->precision.inverse_kl_transform(this->coeffs, this->alpha));
67 
68  // Add on the mean
69  f->add(1.0, mean);
70 
71  return f;
72 }
73 
75 {
76  // This is code repetition, but I'm not quite sure this belongs
77  // in the operator class, because it's useful in the measure
78  return (this->coeffs)[i] / std::pow(this->precision.get_eigenvalue(i), this->alpha / 2.0);
79 }
80 
81 } // End namespace QUESO
std::shared_ptr< T > Type
Definition: SharedPtr.h:69
virtual double gaussianSample(double stdDev) const =0
Samples a value from a Gaussian distribution with standard deviation given by stdDev.
virtual unsigned int get_num_converged() const =0
Return the number of converged eigenpairs.
Abstract base class for operator objects. Operators are assumed to be symmetric and positive-definite...
Definition: OperatorBase.h:45
InfiniteDimensionalGaussian(const FullEnvironment &env, const FunctionBase &mean, const OperatorBase &precision, double alpha, double beta)
Construct a Gaussian with mean mean, precision operator precision. alpha controls regularity of draws...
This class sets up the full environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:508
const RngBase * rngObject() const
Access to the RNG object.
Definition: Environment.C:471
Abstract base class for infinite dimensional measures.
virtual double get_eigenvalue(unsigned int i) const =0
Return eigenvalue i.
virtual double get_kl_coefficient(unsigned int i) const
Return coefficient i of the KL expansion of the current draw. Must be called after draw() ...
virtual SharedPtr< FunctionBase >::Type draw()
Draw from the measure, and then return a shared pointer to the draw.
Abstract base class for function objects.
Definition: FunctionBase.h:47
virtual SharedPtr< FunctionBase >::Type inverse_kl_transform(std::vector< double > &xi, double alpha) const =0
Given coefficients xi, computes the Karhunen-Loeve transform.

Generated on Tue Jun 5 2018 19:48:55 for queso-0.57.1 by  doxygen 1.8.5