https://mooseframework.inl.gov
Loading...
Searching...
No Matches
BayesianActiveLearningSampler.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://www.mooseframework.org
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 "Uniform.h"
13
15
18{
20 params.addClassDescription("Fast Bayesian inference with the parallel active learning (partly "
21 "inspired from El Gammal et al. 2023).");
23 "sorted_indices", "The sorted sample indices in order of importance to evaluate the subApp.");
24 params.addRequiredRangeCheckedParam<unsigned int>(
25 "num_tries",
26 "num_tries>0",
27 "Number of samples to propose in each iteration (not all are sent for subApp evals).");
28 return params;
29}
30
32 : PMCMCBase(parameters),
33 _sorted_indices(getReporterValue<std::vector<unsigned int>>("sorted_indices")),
34 _num_tries(getParam<unsigned int>("num_tries")),
35 _inputs_test(declareRecoverableData<std::vector<std::vector<Real>>>("inputs_test")),
36 _var_test(_num_tries)
37{
38 _inputs_test.resize(_num_tries, std::vector<Real>(_priors.size()));
39}
40
41const std::vector<std::vector<Real>> &
46
47const std::vector<Real> &
52
53void
55{
56 auto fill_vector = [&](std::vector<Real> & vector)
57 {
58 for (unsigned int i = 0; i < _priors.size(); ++i)
59 vector[i] = _priors[i]->quantile(random());
60 };
61
62 /* If step is 1, randomly generate the samples.
63 Else, generate the samples informed by the GP from the reporter "sorted_indices" */
64 for (dof_id_type i = 0; i < _num_parallel_proposals; ++i)
65 {
66 if (_t_step < 1)
67 {
68 fill_vector(_new_samples[i]);
69 if (_var_prior)
71 }
72 else
73 {
75 if (_var_prior)
77 }
78 }
79
80 /* Finally, generate several new samples randomly for the GP to try and pass it to the
81 reporter */
82 for (dof_id_type i = 0; i < _num_tries; ++i)
83 {
84 fill_vector(_inputs_test[i]);
85 if (_var_prior)
87 }
88}
registerMooseObject("StochasticToolsApp", BayesianActiveLearningSampler)
void ErrorVector unsigned int
Fast Bayesian inference with the parallel active learning (partly inspired from El Gammal et al.
const std::vector< unsigned int > & _sorted_indices
The selected sample indices to evaluate the subApp.
const std::vector< std::vector< Real > > & getSampleTries() const
Return the random samples for the GP to try in the reporter class.
const unsigned int & _num_tries
Number of samples to propose in each iteration (not all are sent for subApp evals)
const std::vector< Real > & getVarSampleTries() const
Return the random variance samples for the GP to try in the reporter class.
BayesianActiveLearningSampler(const InputParameters &parameters)
std::vector< Real > _var_test
Storage for all the proposed variances.
virtual void proposeSamples() override
Fill in the _new_samples vector of vectors (happens within sampleSetUp)
std::vector< std::vector< Real > > & _inputs_test
Storage for all the proposed samples.
virtual Real quantile(const Real &y) const=0
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
A base class used to perform Parallel Markov Chain Monte Carlo (MCMC) sampling.
Definition PMCMCBase.h:20
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:153
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
const unsigned int _num_parallel_proposals
Number of parallel proposals to be made and subApps to be executed.
Definition PMCMCBase.h:112
std::vector< Real > & _new_var_samples
Vector of new proposed variance samples.
Definition PMCMCBase.h:136