23 template <
typename SamplerType>
32 template <
typename SamplerType>
43 virtual void execute()
override;
87 virtual void getAcquisition(std::vector<Real> & acq_new, std::vector<unsigned int> & indices);
159 template <
typename SamplerType>
165 params.
addClassDescription(
"A generic reporter to support parallel active learning: re-trains GP " 166 "and picks the next best batch.");
168 "Value of the model output from the SubApp.");
172 "Modified value of the model output from this reporter class.");
174 params.
addRequiredParam<UserObjectName>(
"al_gp",
"Active learning GP trainer.");
175 params.
addRequiredParam<UserObjectName>(
"gp_evaluator",
"Evaluator for the trained GP.");
179 "The sorted sample indices in order of importance to evaluate the subApp.");
181 "acquisition_function",
182 "acquisition_function",
183 "The values of the acquistion function in the current iteration.");
185 "convergence_value",
"convergence_value",
"Value to measure convergence of active learning.");
187 "inputs",
"inputs",
"Modified value of the model inputs from this reporter class.");
188 params.
addRequiredParam<UserObjectName>(
"acquisition",
"Name of the acquisition function.");
190 "penalize_acquisition",
192 "Set true to prevent clustering of the best batch inputs when operating in parallel.");
196 template <
typename SamplerType>
202 _al_sampler(getSampler<SamplerType>(
"sampler")),
203 _n_dim(_al_sampler.getNumberOfCols()),
204 _props(_al_sampler.getNumParallelProposals()),
205 _inputs_test(_al_sampler.getSampleTries()),
207 _output_comm(declareValue<
std::vector<
Real>>(
"outputs_required")),
208 _sorted_indices(declareValue<
std::vector<unsigned
int>>(
"sorted_indices")),
211 _acquisition_obj(getParallelAcquisitionFunctionByName(getParam<UserObjectName>(
"acquisition"))),
212 _acquisition_value(declareValue<
std::vector<
Real>>(
"acquisition_function")),
213 _convergence_value(declareValue<
Real>(
"convergence_value")),
214 _inputs_required(declareValue<
std::vector<
std::vector<
Real>>>(
"inputs")),
215 _penalize_acquisition(getParam<bool>(
"penalize_acquisition")),
216 _check_step(
std::numeric_limits<
int>::
max())
229 template <
typename SamplerType>
234 for (
unsigned int i = 0; i < data_out.size(); ++i)
236 for (
unsigned int j = 0;
j < _n_dim; ++
j)
237 _inputs_required[i][
j] = data_in(i,
j);
238 _gp_inputs.push_back(_inputs_required[i]);
239 _gp_outputs.push_back(data_out[i]);
243 template <
typename SamplerType>
247 for (
unsigned int i = 0; i < eval_outputs.size(); ++i)
248 eval_outputs[i] = _gp_eval.evaluate(_gp_inputs[i]);
251 template <
typename SamplerType>
255 _generic = _gp_outputs;
258 template <
typename SamplerType>
262 _inputs_test_modified = _inputs_test;
265 template <
typename SamplerType>
268 std::vector<unsigned int> & indices)
270 std::vector<Real> acq;
271 acq.resize(_inputs_test.size());
272 includeAdditionalInputs();
273 _acquisition_obj.computeAcquisition(
274 acq, _gp_outputs_test, _gp_std_test, _inputs_test_modified, _gp_inputs, _generic);
276 if (_penalize_acquisition)
277 _acquisition_obj.penalizeAcquisition(
278 acq_new, indices, acq, _length_scales, _inputs_test_modified);
281 template <
typename SamplerType>
285 Real convergence_value = 0.0;
286 for (
unsigned int ii = 0; ii < _output_comm.size(); ++ii)
287 convergence_value += Utility::pow<2>(_output_comm[ii] - _eval_outputs_current[ii]);
288 convergence_value = std::sqrt(convergence_value) / _output_comm.size();
289 return convergence_value;
292 template <
typename SamplerType>
296 for (
unsigned int i = 0; i < _gp_outputs_test.size(); ++i)
297 _gp_outputs_test[i] = _gp_eval.evaluate(_inputs_test[i], _gp_std_test[i]);
300 template <
typename SamplerType>
304 if (_al_sampler.getNumberOfLocalRows() == 0 || _check_step == _t_step)
306 _check_step = _t_step;
310 DenseMatrix<Real> data_in(_al_sampler.getNumberOfRows(), _al_sampler.getNumberOfCols());
311 for (
dof_id_type ss = _al_sampler.getLocalRowBegin(); ss < _al_sampler.getLocalRowEnd(); ++ss)
313 const auto data = _al_sampler.getNextLocalRow();
314 for (
unsigned int j = 0;
j < _al_sampler.getNumberOfCols(); ++
j)
315 data_in(ss,
j) = data[
j];
317 _communicator.sum(data_in.get_values());
318 _output_comm = _output_value;
319 _communicator.allgather(_output_comm);
324 setupGPData(_output_comm, data_in);
329 computeGPOutput(_eval_outputs_current);
330 _convergence_value = computeConvergenceValue();
334 _al_gp.reTrain(_gp_inputs, _gp_outputs);
335 _length_scales = _al_gp.getLengthScales();
345 std::vector<Real> acq_new;
346 std::vector<unsigned int> indices;
347 indices.resize(_inputs_test.size());
348 getAcquisition(acq_new, indices);
351 std::copy_n(indices.begin(), _props, _sorted_indices.begin());
352 std::copy_n(acq_new.begin(), _props, _acquisition_value.begin());
355 std::iota(_sorted_indices.begin(), _sorted_indices.end(), 0);
358 _check_step = _t_step;
A generic reporter to support parallel active learning: re-trains GP and picks the next best batch...
std::vector< std::vector< Real > > _inputs_test_modified
Storage for all the modified proposed samples to test the GP model.
std::vector< std::vector< Real > > _gp_inputs
Storage for the GP re-training inputs.
const std::vector< Real > & _output_value
Model output value from SubApp.
GenericActiveLearnerTempl< GenericActiveLearningSampler > GenericActiveLearner
virtual void computeGPOutput(std::vector< Real > &eval_outputs)
Computes the outputs of the trained GP model.
std::vector< Real > _eval_outputs_current
The GP outputs from the current iteration before re-training (to evaluate convergence) ...
const InputParameters & parameters() const
std::vector< Real > & _acquisition_value
The acquistion function values in the current iteration.
const SurrogateModel & _gp_eval
The GP evaluator object that permits re-evaluations.
static InputParameters validParams()
virtual void initialize() override
std::vector< Real > _length_scales
Storage for the length scales after the GP training.
static InputParameters validParams()
dof_id_type _props
Storage for the number of parallel proposals.
All ParallelAcquisition functions should inherit from this class.
unsigned int _n_dim
The input dimension for GP, equal to Sampler columns.
auto max(const L &left, const R &right)
std::vector< unsigned int > & _sorted_indices
The selected sample indices to evaluate the subApp.
virtual void execute() override
virtual void finalize() override
const std::vector< std::vector< Real > > & _inputs_test
Storage for all the proposed samples to test the GP model.
virtual void evaluateGPTest()
Evaluate the GP on all the test samples sent by the Sampler.
const bool & _penalize_acquisition
Penalize acquisition to prevent clustering when operating in parallel.
static InputParameters validParams()
Real & _convergence_value
For monitoring convergence of active learning.
std::vector< Real > & _output_comm
Modified value of model output by this reporter class.
virtual void includeAdditionalInputs()
Include additional inputs before evaluating the acquisition function.
const ReporterMode REPORTER_MODE_DISTRIBUTED
ParallelAcquisitionFunctionBase & _acquisition_obj
Storage for the parallel acquisition object to be utilized.
virtual void setupGeneric()
Setup the generic variable for acquisition computation (depends on the objective: optimization...
GenericActiveLearnerTempl(const InputParameters ¶meters)
virtual Real computeConvergenceValue()
Computes the convergence value during active learning.
virtual void setupGPData(const std::vector< Real > &data_out, const DenseMatrix< Real > &data_in)
Sets up the training data for the GP model.
virtual void getAcquisition(std::vector< Real > &acq_new, std::vector< unsigned int > &indices)
Output the acquisition function values and ordering of the indices.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Interface for objects that need to use samplers.
const ActiveLearningGaussianProcess & _al_gp
The active learning GP trainer that permits re-training.
std::vector< Real > _gp_outputs
Storage for the GP re-training outputs.
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
std::vector< Real > _gp_std_test
Outputs of GP model standard deviation for the test samples.
SamplerType & _al_sampler
The base sampler.
std::vector< std::vector< Real > > & _inputs_required
Transmit the required inputs to the json file.
std::vector< Real > _generic
A generic parameter to be passed to the acquisition function.
int _check_step
Ensure that the MCMC algorithm proceeds in a sequential fashion.
void ErrorVector unsigned int
std::vector< Real > _gp_outputs_test
Outputs of GP model for the test samples.