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(_num_tries, std::vector<Real>(_priors.size())),
36 _var_test(_num_tries)
37{
38}
39
40const std::vector<std::vector<Real>> &
45
46const std::vector<Real> &
51
52void
54{
55 auto fill_vector = [&](std::vector<Real> & vector)
56 {
57 for (unsigned int i = 0; i < _priors.size(); ++i)
58 vector[i] = _priors[i]->quantile(random());
59 };
60
61 /* If step is 1, randomly generate the samples.
62 Else, generate the samples informed by the GP from the reporter "sorted_indices" */
63 for (dof_id_type i = 0; i < _num_parallel_proposals; ++i)
64 {
65 if (_t_step < 1)
66 {
67 fill_vector(_new_samples[i]);
68 if (_var_prior)
70 }
71 else
72 {
74 if (_var_prior)
76 }
77 }
78
79 /* Finally, generate several new samples randomly for the GP to try and pass it to the
80 reporter */
81 for (dof_id_type i = 0; i < _num_tries; ++i)
82 {
83 fill_vector(_inputs_test[i]);
84 if (_var_prior)
86 }
87}
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)
std::vector< std::vector< Real > > _inputs_test
Storage for all the proposed samples.
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)
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: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