https://mooseframework.inl.gov
NearestPointTrainer.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 
10 #include "NearestPointTrainer.h"
11 #include "Sampler.h"
12 
13 registerMooseObject("StochasticToolsApp", NearestPointTrainer);
14 
17 {
19  params.addClassDescription("Loops over and saves sample values for [NearestPointSurrogate.md].");
20 
21  return params;
22 }
23 
25  : SurrogateTrainer(parameters),
26  _sample_points(declareModelData<std::vector<std::vector<Real>>>("_sample_points")),
27  _sample_results(declareModelData<std::vector<std::vector<Real>>>("_sample_results")),
28  _predictor_row(getPredictorData())
29 {
30  _sample_points.resize(_n_dims);
31  _sample_results.resize(1);
32 }
33 
34 void
36 {
37  for (auto & it : _sample_points)
38  {
39  it.clear();
40  it.reserve(getLocalSampleSize());
41  }
42 
43  for (auto & it : _sample_results)
44  {
45  it.clear();
46  it.reserve(getLocalSampleSize());
47  }
48 }
49 
50 void
52 {
53  if (_rvecval && (_sample_results.size() != _rvecval->size()))
54  _sample_results.resize(_rvecval->size());
55 
56  // Get predictors from reporter values
57  for (auto d : make_range(_n_dims))
58  _sample_points[d].push_back(_predictor_row[d]);
59 
60  // Get responses
61  if (_rval)
62  _sample_results[0].push_back(*_rval);
63  else if (_rvecval)
64  for (auto r : make_range(_rvecval->size()))
65  _sample_results[r].push_back((*_rvecval)[r]);
66 }
67 
68 void
70 {
71  for (auto & it : _sample_points)
73 
74  for (auto & it : _sample_results)
76 }
std::vector< std::vector< Real > > & _sample_results
Container for results (y values).
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
const Real * _rval
Response value.
unsigned int _n_dims
Dimension of predictor data - either _sampler.getNumberOfCols() or _pvals.size() + _pcols...
registerMooseObject("StochasticToolsApp", NearestPointTrainer)
static InputParameters validParams()
const std::vector< Real > * _rvecval
Vector response value.
const Parallel::Communicator & _communicator
NearestPointTrainer(const InputParameters &parameters)
const std::vector< Real > & _predictor_row
Data from the current predictor row.
unsigned int getLocalSampleSize() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
This is the main trainer base class.
IntRange< T > make_range(T beg, T end)
std::vector< std::vector< Real > > & _sample_points
Map containing sample points and the results.
void addClassDescription(const std::string &doc_string)
static InputParameters validParams()
virtual void preTrain() override
virtual void postTrain() override
virtual void train() override