https://mooseframework.inl.gov
Loading...
Searching...
No Matches
AffineInvariantStretchSampler.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
13
16{
18 params.addClassDescription("Perform Affine Invariant Ensemble MCMC with stretch sampler.");
20 "previous_state", "Reporter value with the previous state of all the walkers.");
22 "previous_state_var",
23 "Reporter value with the previous state of all the walkers for variance.");
24 params.addParam<Real>("step_size", 2.0, "Step size for each of the walkers.");
25 return params;
26}
27
29 : PMCMCBase(parameters),
30 _step_size(getParam<Real>("step_size")),
31 _previous_state(getReporterValue<std::vector<std::vector<Real>>>("previous_state")),
32 _previous_state_var(getReporterValue<std::vector<Real>>("previous_state_var"))
33{
35 paramError("num_parallel_proposals",
36 "At least three parallel proposals should be used for the Stretch Sampler.");
37
40 "It is recommended that the parallel proposals be greater than or equal to the "
41 "inferred parameters. This will allow the sampler to not get stuck on a hyper-plane.");
42
43 // Assign the correct size to the step size vector
45}
46
47void
49{
50 unsigned int j = 0;
51 bool indicator;
52 unsigned int index_req = 0;
53 while (j < _num_parallel_proposals)
54 {
55 indicator = 0;
56 _affine_step[j] = Utility::pow<2>((_step_size - 1.0) * random() + 1.0) / _step_size;
58 for (unsigned int i = 0; i < _priors.size(); ++i)
59 {
60 _new_samples[j][i] =
61 (_t_step + 1 > decisionStep())
62 ? (_previous_state[index_req][i] +
63 _affine_step[j] * (_previous_state[j][i] - _previous_state[index_req][i]))
64 : _priors[i]->quantile(random());
65 if (_lower_bound)
66 indicator =
67 (_new_samples[j][i] < (*_lower_bound)[i] || _new_samples[j][i] > (*_upper_bound)[i])
68 ? 1
69 : indicator;
70 }
71 if (_var_prior)
72 {
74 (_t_step + 1 > decisionStep())
75 ? (_previous_state_var[index_req] +
79 indicator = 1;
80 }
81 if (!indicator)
82 ++j;
83 }
84}
85
86const std::vector<Real> &
registerMooseObject("StochasticToolsApp", AffineInvariantStretchSampler)
A class for performing Affine Invariant Ensemble MCMC with stretch sampler.
const std::vector< std::vector< Real > > & _previous_state
Reporter value with the previous state of all the walkers.
const Real _step_size
The step size for the stretch sampler.
virtual int decisionStep() const override
Return the step after which decision making can begin.
AffineInvariantStretchSampler(const InputParameters &parameters)
const std::vector< Real > & _previous_state_var
Reporter value with the previous state of all the walkers for variance.
virtual void proposeSamples() override
Fill in the _new_samples vector of vectors (happens within sampleSetUp)
const std::vector< Real > & getAffineStepSize() const
Return the vector of step size for decision making.
std::vector< Real > _affine_step
Vector of affine step sizes.
virtual Real quantile(const Real &y) const=0
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void paramError(const std::string &param, Args... args) const
void mooseWarning(Args &&... args) const
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 Distribution * _var_prior
Storage for prior distribution object of the variance to be utilized.
Definition PMCMCBase.h:118
std::vector< std::vector< Real > > _new_samples
Vectors of new proposed samples.
Definition PMCMCBase.h:133
std::vector< Real > _new_var_samples
Vector of new proposed variance samples.
Definition PMCMCBase.h:136
const unsigned int _num_parallel_proposals
Number of parallel proposals to be made and subApps to be executed.
Definition PMCMCBase.h:112
const Real & _variance_bound
Upper bound for variance for making the next proposal.
Definition PMCMCBase.h:127
unsigned int randomIndex(const unsigned int &upper_bound, const unsigned int &exclude)
Sample a random index excluding a specified index.
Definition PMCMCBase.C:148