https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
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
34void
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
50void
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
68void
70{
71 for (auto & it : _sample_points)
73
74 for (auto & it : _sample_results)
76}
registerMooseObject("StochasticToolsApp", NearestPointTrainer)
void addClassDescription(const std::string &doc_string)
virtual void postTrain() override
virtual void preTrain() override
virtual void train() override
static InputParameters validParams()
NearestPointTrainer(const InputParameters &parameters)
std::vector< std::vector< Real > > & _sample_points
Map containing sample points and the results.
const std::vector< Real > & _predictor_row
Data from the current predictor row.
std::vector< std::vector< Real > > & _sample_results
Container for results (y values).
This is the main trainer base class.
unsigned int getLocalSampleSize() const
const std::vector< Real > * _rvecval
Vector response value.
const Real * _rval
Response value.
static InputParameters validParams()
unsigned int _n_dims
Dimension of predictor data - either _sampler.getNumberOfCols() or _pvals.size() + _pcols....
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
const Parallel::Communicator & _communicator