www.mooseframework.org
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SobolSampler Class Reference

A class used to perform Monte Carlo Sampling. More...

#include <SobolSampler.h>

Inheritance diagram for SobolSampler:
[legend]

Public Member Functions

 SobolSampler (const InputParameters &parameters)
 

Protected Member Functions

virtual std::vector< DenseMatrix< Real > > sample () override
 
virtual void sampleSetUp () override
 
virtual void sampleTearDown () override
 

Protected Attributes

const std::size_t _num_samples
 Number of Monte Carlo samples to create for each Sobol matrix. More...
 
DenseMatrix< Real > _a_matrix
 
DenseMatrix< Real > _b_matrix
 

Detailed Description

A class used to perform Monte Carlo Sampling.

Definition at line 22 of file SobolSampler.h.

Constructor & Destructor Documentation

◆ SobolSampler()

SobolSampler::SobolSampler ( const InputParameters &  parameters)

Definition at line 25 of file SobolSampler.C.

26  : Sampler(parameters),
27  _num_samples(getParam<unsigned int>("n_samples")),
28  _a_matrix(0, 0),
29  _b_matrix(0, 0)
30 {
31  setNumberOfRequiedRandomSeeds(2);
32 }
DenseMatrix< Real > _b_matrix
Definition: SobolSampler.h:38
DenseMatrix< Real > _a_matrix
Definition: SobolSampler.h:37
const std::size_t _num_samples
Number of Monte Carlo samples to create for each Sobol matrix.
Definition: SobolSampler.h:33

Member Function Documentation

◆ sample()

std::vector< DenseMatrix< Real > > SobolSampler::sample ( )
overrideprotectedvirtual

Definition at line 55 of file SobolSampler.C.

56 {
57  // Create the output vector
58  auto n = _distributions.size() + 2;
59  std::vector<DenseMatrix<Real>> output(n);
60 
61  // Include the A and B matrices
62  output[0] = _a_matrix;
63  output[1] = _b_matrix;
64 
65  // Create the AB matrices
66  for (auto idx = beginIndex(_distributions, 2); idx < n; ++idx)
67  {
68  output[idx] = _a_matrix;
69  for (std::size_t i = 0; i < _num_samples; ++i)
70  output[idx](i, idx - 2) = _b_matrix(i, idx - 2);
71  }
72 
73  return output;
74 }
DenseMatrix< Real > _b_matrix
Definition: SobolSampler.h:38
DenseMatrix< Real > _a_matrix
Definition: SobolSampler.h:37
const std::size_t _num_samples
Number of Monte Carlo samples to create for each Sobol matrix.
Definition: SobolSampler.h:33

◆ sampleSetUp()

void SobolSampler::sampleSetUp ( )
overrideprotectedvirtual

Definition at line 35 of file SobolSampler.C.

36 {
37  _a_matrix.resize(_num_samples, _distributions.size());
38  _b_matrix.resize(_num_samples, _distributions.size());
39  for (std::size_t i = 0; i < _num_samples; ++i)
40  for (auto j = beginIndex(_distributions); j < _distributions.size(); ++j)
41  {
42  _a_matrix(i, j) = _distributions[j]->quantile(this->rand(0));
43  _b_matrix(i, j) = _distributions[j]->quantile(this->rand(1));
44  }
45 }
DenseMatrix< Real > _b_matrix
Definition: SobolSampler.h:38
DenseMatrix< Real > _a_matrix
Definition: SobolSampler.h:37
const std::size_t _num_samples
Number of Monte Carlo samples to create for each Sobol matrix.
Definition: SobolSampler.h:33

◆ sampleTearDown()

void SobolSampler::sampleTearDown ( )
overrideprotectedvirtual

Definition at line 48 of file SobolSampler.C.

49 {
50  _a_matrix.resize(0, 0);
51  _b_matrix.resize(0, 0);
52 }
DenseMatrix< Real > _b_matrix
Definition: SobolSampler.h:38
DenseMatrix< Real > _a_matrix
Definition: SobolSampler.h:37

Member Data Documentation

◆ _a_matrix

DenseMatrix<Real> SobolSampler::_a_matrix
protected

Sobol Monte Carlo matrices, these are sized and cleared to avoid keeping large matrices around

Definition at line 37 of file SobolSampler.h.

Referenced by sample(), sampleSetUp(), and sampleTearDown().

◆ _b_matrix

DenseMatrix<Real> SobolSampler::_b_matrix
protected

Definition at line 38 of file SobolSampler.h.

Referenced by sample(), sampleSetUp(), and sampleTearDown().

◆ _num_samples

const std::size_t SobolSampler::_num_samples
protected

Number of Monte Carlo samples to create for each Sobol matrix.

Definition at line 33 of file SobolSampler.h.

Referenced by sample(), and sampleSetUp().


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