queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
QUESO::MonteCarloQuadrature< V, M > Class Template Reference

Numerical integration using Monte Carlo. More...

#include <MonteCarloQuadrature.h>

Inheritance diagram for QUESO::MonteCarloQuadrature< V, M >:
QUESO::MultiDQuadratureBase< V, M > QUESO::BaseQuadrature

Public Member Functions

 MonteCarloQuadrature (const VectorSubset< V, M > &domain, unsigned int n_samples)
 
virtual ~MonteCarloQuadrature ()
 
- Public Member Functions inherited from QUESO::MultiDQuadratureBase< V, M >
 MultiDQuadratureBase (const VectorSubset< V, M > &domain)
 
virtual ~MultiDQuadratureBase ()=0
 Pure virtual destructor, forcing this to be an abstract object. More...
 
const std::vector< typename
QUESO::SharedPtr< V >::Type > & 
positions () const
 
const VectorSubset< V, M > & getDomain () const
 
- Public Member Functions inherited from QUESO::BaseQuadrature
 BaseQuadrature ()
 
virtual ~BaseQuadrature ()=0
 Pure virtual destructor, forcing this to be an abstract object. More...
 
const std::vector< double > & weights () const
 Array of the weights used in the numerical integration. More...
 

Additional Inherited Members

- Protected Attributes inherited from QUESO::MultiDQuadratureBase< V, M >
std::vector< typename
QUESO::SharedPtr< V >::Type > 
m_positions
 Locations of quadrature points. More...
 
const VectorSubset< V, M > & m_domain
 Domain over which the quadrature will be performed. More...
 
- Protected Attributes inherited from QUESO::BaseQuadrature
std::vector< double > m_weights
 

Detailed Description

template<class V = GslVector, class M = GslMatrix>
class QUESO::MonteCarloQuadrature< V, M >

Numerical integration using Monte Carlo.

Monte Carlo integration approximates an integral by randomly sampling the function. Namely, if \( <f> = 1/|\Omega| \int_{\Omega} f(x) \; dx \) is the average, then

\[ \int_{\Omega} f(x) \; dx = |\Omega| <f> \approx |\Omega| \frac{1}{N} \sum_{i=1}^N f(x_i) \]

where \(N\) is the number of samples. This class, then, uniformly samples over the user-specified domain for the given number of samples. Then, to adhere to the quadrature interface, the positions are accessible in the positions vector and the factor \(|\Omega|/N \) is cached in the weights vector.

Definition at line 47 of file MonteCarloQuadrature.h.

Constructor & Destructor Documentation

template<class V , class M >
QUESO::MonteCarloQuadrature< V, M >::MonteCarloQuadrature ( const VectorSubset< V, M > &  domain,
unsigned int  n_samples 
)

Definition at line 33 of file MonteCarloQuadrature.C.

References QUESO::MultiDQuadratureBase< V, M >::m_domain, QUESO::MultiDQuadratureBase< V, M >::m_positions, QUESO::BaseQuadrature::m_weights, QUESO::BaseVectorRealizer< V, M >::realization(), QUESO::BaseVectorRV< V, M >::realizer(), QUESO::VectorSubset< V, M >::vectorSpace(), and QUESO::VectorSet< V, M >::volume().

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  }
std::shared_ptr< T > Type
Definition: SharedPtr.h:69
std::vector< double > m_weights
Definition of a shared pointer.
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.
template<class V = GslVector, class M = GslMatrix>
virtual QUESO::MonteCarloQuadrature< V, M >::~MonteCarloQuadrature ( )
inlinevirtual

Definition at line 54 of file MonteCarloQuadrature.h.

54 {}

The documentation for this class was generated from the following files:

Generated on Tue Jun 5 2018 19:49:20 for queso-0.57.1 by  doxygen 1.8.5