https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
11#include "Normal.h"
12#include "TruncatedNormal.h"
13
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
39void
41{
42 std::vector<Real> old_sample = (_t_step + 1 > 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 random(), old_sample[i], _std_prop[i], (*_lower_bound)[i], (*_upper_bound)[i]);
49 else
50 _new_samples[j][i] = Normal::quantile(random(), old_sample[i], _std_prop[i]);
51 }
52}
registerMooseObject("StochasticToolsApp", IndependentGaussianMH)
A class for performing M-H MCMC sampling with independent Gaussian propoposals.
virtual void proposeSamples() override
Fill in the _new_samples vector of vectors (happens within sampleSetUp)
static InputParameters validParams()
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.
virtual int decisionStep() const override
Return the step after which decision making can begin.
IndependentGaussianMH(const InputParameters &parameters)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void paramError(const std::string &param, Args... args) const
virtual Real quantile(const Real &p) const override
Definition Normal.C:80
A base class used to perform Parallel Markov Chain Monte Carlo (MCMC) sampling.
Definition PMCMCBase.h:20
const std::vector< Real > * _lower_bound
Lower bounds for making the next proposal.
Definition PMCMCBase.h:121
std::vector< const Distribution * > _priors
Storage for prior distribution objects to be utilized.
Definition PMCMCBase.h:115
static InputParameters validParams()
Definition PMCMCBase.C:18
Real random()
Sample a random number between 0 and 1.
Definition PMCMCBase.C:142
const std::vector< Real > & _initial_values
Initial values of the input params to get the MCMC scheme started.
Definition PMCMCBase.h:130
std::vector< std::vector< Real > > _new_samples
Vectors of new proposed samples.
Definition PMCMCBase.h:133
const unsigned int _num_parallel_proposals
Number of parallel proposals to be made and subApps to be executed.
Definition PMCMCBase.h:112
const std::vector< Real > * _upper_bound
Upper bounds for making the next proposal.
Definition PMCMCBase.h:124
virtual Real quantile(const Real &p) const override