queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
MonteCarloQuadrature.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 <queso/MonteCarloQuadrature.h>
26 #include <queso/UniformVectorRV.h>
27 #include <queso/GslVector.h>
28 #include <queso/GslMatrix.h>
29 
30 namespace QUESO
31 {
32  template <class V, class M>
34  unsigned int n_samples )
35  : MultiDQuadratureBase<V,M>(domain)
36  {
37  // We'll just uniformly sample over the domain to retrieve the quadrature
38  // points.
39  UniformVectorRV<V,M> uniform_rv("MonteCarloQuadrature_", //prefix
40  this->m_domain);
41 
42  const BaseVectorRealizer< V, M > & realizer = uniform_rv.realizer();
43 
44  this->m_positions.resize(n_samples,SharedPtr<GslVector>::Type());
45 
46  for( unsigned int i = 0; i < n_samples; i++ )
47  {
48  // Create new vector from our vector space
49  // We are taking ownership of this pointer.
50  typename QUESO::SharedPtr<V>::Type domain_vec(domain.vectorSpace().newVector());
51 
52  // Draw the new point
53  realizer.realization(*domain_vec);
54 
55  // This is now the quadrature point position
56  this->m_positions[i] = domain_vec;
57  }
58 
59  // The weights are just the scaling factor for the MC sum
60  this->m_weights.resize(n_samples,domain.volume()/(double)(n_samples));
61  }
62 
63  // Instantiate
65 
66 } // end namespace QUESO
std::shared_ptr< T > Type
Definition: SharedPtr.h:69
A templated (base) class for handling sampling from vector RVs.
A class representing a uniform vector RV.
virtual void realization(V &nextValues) const =0
Performs a realization (sample) from a probability density function. See template specialization...
A templated class for handling subsets.
Definition: VectorSubset.h:46
double volume() const
Set volume; access to private attribute m_volume.
Definition: VectorSet.C:91
MonteCarloQuadrature(const VectorSubset< V, M > &domain, unsigned int n_samples)
std::vector< double > m_weights
Numerical integration using Monte Carlo.
Base class for multi-dimensional quadrature rules.
std::vector< typename QUESO::SharedPtr< V >::Type > m_positions
Locations of quadrature points.
const VectorSubset< V, M > & m_domain
Domain over which the quadrature will be performed.
const BaseVectorRealizer< V, M > & realizer() const
Finds a realization (sample) of the PDF of this vector RV; access to private attribute m_realizer...
Definition: VectorRV.C:106
const VectorSpace< V, M > & vectorSpace() const
Vector space to which this set belongs to. See template specialization.
Definition: VectorSubset.C:68

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