https://mooseframework.inl.gov
IndependentGaussianMH.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "IndependentGaussianMH.h"
11 #include "Normal.h"
12 #include "TruncatedNormal.h"
13 
14 registerMooseObject("StochasticToolsApp", IndependentGaussianMH);
15 
18 {
20  params.addClassDescription("Perform M-H MCMC sampling with independent Gaussian propoposals.");
21  params.addRequiredParam<ReporterName>("seed_inputs",
22  "Reporter with seed inputs values for the next proposals.");
23  params.addRequiredParam<std::vector<Real>>("std_prop",
24  "Standard deviations for making the next proposal.");
25  return params;
26 }
27 
29  : PMCMCBase(parameters),
30  _seed_inputs(getReporterValue<std::vector<Real>>("seed_inputs")),
31  _std_prop(getParam<std::vector<Real>>("std_prop"))
32 {
33  // Error check for sizes of proposal stds
34  if (_std_prop.size() != _priors.size())
35  paramError("std_prop",
36  "The number of proposal stds, initial values, and priors should be the same.");
37 }
38 
39 void
40 IndependentGaussianMH::proposeSamples(const unsigned int seed_value)
41 {
42  std::vector<Real> old_sample = (_t_step > decisionStep()) ? _seed_inputs : _initial_values;
43  for (unsigned int j = 0; j < _num_parallel_proposals; ++j)
44  for (unsigned int i = 0; i < _priors.size(); ++i)
45  {
46  if (_lower_bound)
48  old_sample[i],
49  _std_prop[i],
50  (*_lower_bound)[i],
51  (*_upper_bound)[i]);
52  else
53  _new_samples[j][i] = Normal::quantile(getRand(seed_value), old_sample[i], _std_prop[i]);
54  }
55 }
const unsigned int _num_parallel_proposals
Number of parallel proposals to be made and subApps to be executed.
Definition: PMCMCBase.h:106
const std::vector< Real > & _initial_values
Initial values of the input params to get the MCMC scheme started.
Definition: PMCMCBase.h:124
IndependentGaussianMH(const InputParameters &parameters)
const std::vector< Real > * _lower_bound
Lower bounds for making the next proposal.
Definition: PMCMCBase.h:115
registerMooseObject("StochasticToolsApp", IndependentGaussianMH)
std::vector< const Distribution * > _priors
Storage for prior distribution objects to be utilized.
Definition: PMCMCBase.h:109
static InputParameters validParams()
Real getRand(unsigned int index=0)
virtual int decisionStep() const override
Return the step after which decision making can begin.
void addRequiredParam(const std::string &name, const std::string &doc_string)
virtual void proposeSamples(const unsigned int seed_value) override
Fill in the _new_samples vector of vectors (happens within sampleSetUp)
const std::vector< Real > & _seed_inputs
Reporter value the seed input values for proposing the next set of samples.
const std::vector< Real > & _std_prop
Standard deviations for making the next proposal.
void paramError(const std::string &param, Args... args) const
const std::vector< Real > * _upper_bound
Upper bounds for making the next proposal.
Definition: PMCMCBase.h:118
virtual Real quantile(const Real &p) const override
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< std::vector< Real > > _new_samples
Vectors of new proposed samples.
Definition: PMCMCBase.h:127
void addClassDescription(const std::string &doc_string)
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
virtual Real quantile(const Real &p) const override
Definition: Normal.C:80
A class for performing M-H MCMC sampling with independent Gaussian propoposals.
static InputParameters validParams()
Definition: PMCMCBase.C:18
A base class used to perform Parallel Markov Chain Monte Carlo (MCMC) sampling.
Definition: PMCMCBase.h:19