www.mooseframework.org
MonteCarloSampler.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
8 #include "MonteCarloSampler.h"
9 
10 template <>
11 InputParameters
13 {
14  InputParameters params = validParams<Sampler>();
15  params.addClassDescription("Monte Carlo Sampler.");
16  params.addRequiredParam<unsigned int>(
17  "n_samples", "Number of Monte Carlo samples to perform for each distribution.");
18  return params;
19 }
20 
21 MonteCarloSampler::MonteCarloSampler(const InputParameters & parameters)
22  : Sampler(parameters), _num_samples(getParam<unsigned int>("n_samples"))
23 {
24 }
25 
26 std::vector<DenseMatrix<Real>>
28 {
29  std::vector<DenseMatrix<Real>> output(1);
30  output[0].resize(_num_samples, _distributions.size());
31  for (std::size_t i = 0; i < _num_samples; ++i)
32  for (auto j = beginIndex(_distributions); j < _distributions.size(); ++j)
33  output[0](i, j) = _distributions[j]->quantile(rand());
34  return output;
35 }
InputParameters validParams< MonteCarloSampler >()
const std::size_t _num_samples
Number of monte carlo samples to create for each distribution.
virtual std::vector< DenseMatrix< Real > > sample() override
MonteCarloSampler(const InputParameters &parameters)