https://mooseframework.inl.gov
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | Private Member Functions | List of all members
NearestPointSurrogate Class Reference

#include <NearestPointSurrogate.h>

Inheritance diagram for NearestPointSurrogate:
[legend]

Public Types

typedef DataFileName DataFileParameterType
 

Public Member Functions

 NearestPointSurrogate (const InputParameters &parameters)
 
virtual Real evaluate (const std::vector< Real > &x) const override
 Evaluate surrogate model given a row of parameters. More...
 
virtual void evaluate (const std::vector< Real > &x, std::vector< Real > &y) const override
 Various evaluate methods that can be overriden. More...
 
virtual Real evaluate (const std::vector< Real > &x) const
 Evaluate surrogate model given a row of parameters. More...
 
virtual void evaluate (const std::vector< Real > &x, std::vector< Real > &y) const
 Various evaluate methods that can be overriden. More...
 
virtual Real evaluate (const std::vector< Real > &x, Real &std) const
 Evaluate methods that also return predicted standard deviation (see GaussianProcess.h) More...
 
virtual void evaluate (const std::vector< Real > &x, std::vector< Real > &y, std::vector< Real > &) const
 
virtual bool enabled () const
 
std::shared_ptr< MooseObjectgetSharedPtr ()
 
std::shared_ptr< const MooseObjectgetSharedPtr () const
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
virtual const std::string & name () const
 
std::string typeAndName () const
 
std::string errorPrefix (const std::string &error_type) const
 
void callMooseError (std::string msg, const bool with_prefix) const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
const InputParametersparameters () const
 
MooseObjectName uniqueName () const
 
const T & getParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const T * queryParam (const std::string &name) const
 
const T & getRenamedParam (const std::string &old_name, const std::string &new_name) const
 
getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &nm) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramInfo (const std::string &param, Args... args) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void mooseError (Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &relative_path) const
 
std::string getDataFilePath (const std::string &relative_path) const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 
T & getSampler (const std::string &name)
 
SamplergetSampler (const std::string &name)
 
T & getSamplerByName (const SamplerName &name)
 
SamplergetSamplerByName (const SamplerName &name)
 
template<>
SurrogateModelgetSurrogateModel (const std::string &name) const
 
template<>
SurrogateTrainerBasegetSurrogateTrainer (const std::string &name) const
 
template<>
SurrogateModelgetSurrogateModelByName (const UserObjectName &name) const
 
template<>
SurrogateTrainerBasegetSurrogateTrainerByName (const UserObjectName &name) const
 
const std::string & modelMetaDataName () const
 Accessor for the name of the model meta data. More...
 
const FileName & getModelDataFileName () const
 Get the associated filename. More...
 
bool hasModelData () const
 Check if we need to load model data (if the filename parameter is used) More...
 
virtual Real evaluate (const std::vector< Real > &x, Real &std) const
 Evaluate methods that also return predicted standard deviation (see GaussianProcess.h) More...
 
virtual void evaluate (const std::vector< Real > &x, std::vector< Real > &y, std::vector< Real > &) const
 
template<typename T = SurrogateModel>
T & getSurrogateModel (const std::string &name) const
 Get a SurrogateModel/Trainer with a given name. More...
 
template<typename T = SurrogateTrainerBase>
T & getSurrogateTrainer (const std::string &name) const
 
template<typename T = SurrogateModel>
T & getSurrogateModelByName (const UserObjectName &name) const
 Get a sampler with a given name. More...
 
template<typename T = SurrogateTrainerBase>
T & getSurrogateTrainerByName (const UserObjectName &name) const
 
template<typename T , typename... Args>
T & declareModelData (const std::string &data_name, Args &&... args)
 Declare model data for loading from file as well as restart. More...
 
template<typename T , typename... Args>
const T & getModelData (const std::string &data_name, Args &&... args) const
 Retrieve model data from the interface. More...
 

Static Public Member Functions

static InputParameters validParams ()
 
static MooseEnum defaultPredictorTypes ()
 
static MooseEnum defaultResponseTypes ()
 

Public Attributes

const ConsoleStream _console
 

Protected Attributes

const std::vector< std::vector< Real > > & _sample_points
 Array containing sample points. More...
 
const std::vector< std::vector< Real > > & _sample_results
 Array containing results. More...
 
const bool & _enabled
 
MooseApp_app
 
const std::string _type
 
const std::string _name
 
const InputParameters_pars
 
Factory_factory
 
ActionFactory_action_factory
 
const Parallel::Communicator & _communicator
 

Private Member Functions

unsigned int findNearestPoint (const std::vector< Real > &x) const
 

Detailed Description

Definition at line 14 of file NearestPointSurrogate.h.

Constructor & Destructor Documentation

◆ NearestPointSurrogate()

NearestPointSurrogate::NearestPointSurrogate ( const InputParameters parameters)

Definition at line 23 of file NearestPointSurrogate.C.

25  _sample_points(getModelData<std::vector<std::vector<Real>>>("_sample_points")),
26  _sample_results(getModelData<std::vector<std::vector<Real>>>("_sample_results"))
27 {
28 }
const T & getModelData(const std::string &data_name, Args &&... args) const
Retrieve model data from the interface.
const std::vector< std::vector< Real > > & _sample_points
Array containing sample points.
const std::vector< std::vector< Real > > & _sample_results
Array containing results.
const InputParameters & parameters() const
SurrogateModel(const InputParameters &parameters)

Member Function Documentation

◆ declareModelData()

template<typename T , typename... Args>
T & RestartableModelInterface::declareModelData ( const std::string &  data_name,
Args &&...  args 
)
inherited

Declare model data for loading from file as well as restart.

Definition at line 78 of file RestartableModelInterface.h.

79 {
80  return _model_restartable.declareRestartableData<T>(data_name, std::forward<Args>(args)...);
81 }
T & declareRestartableData(const std::string &data_name, Args &&... args)
Declare a piece of data as "restartable" and initialize it.
PublicRestartable _model_restartable
Member for interfacing with the framework&#39;s restartable system.

◆ defaultPredictorTypes()

static MooseEnum SurrogateModel::defaultPredictorTypes ( )
inlinestaticinherited

Definition at line 27 of file SurrogateModel.h.

27 { return MooseEnum("real"); }

◆ defaultResponseTypes()

static MooseEnum SurrogateModel::defaultResponseTypes ( )
inlinestaticinherited

Definition at line 28 of file SurrogateModel.h.

Referenced by EvaluateSurrogate::validParams().

28 { return MooseEnum("real vector_real"); }

◆ evaluate() [1/8]

virtual void SurrogateModel::evaluate
inline

Definition at line 59 of file SurrogateModel.h.

60  {
61  evaluateError(x, y, true);
62  }
void evaluateError(P x, R y, bool with_std=false) const
const std::vector< double > y
const std::vector< double > x

◆ evaluate() [2/8]

virtual Real SurrogateModel::evaluate
inline

Evaluate surrogate model given a row of parameters.

Definition at line 33 of file SurrogateModel.h.

34  {
35  evaluateError(x, Real());
36  return 0.0;
37  };
void evaluateError(P x, R y, bool with_std=false) const
const std::vector< double > x
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ evaluate() [3/8]

virtual void SurrogateModel::evaluate
inline

Various evaluate methods that can be overriden.

Definition at line 43 of file SurrogateModel.h.

44  {
45  evaluateError(x, y);
46  }
void evaluateError(P x, R y, bool with_std=false) const
const std::vector< double > y
const std::vector< double > x

◆ evaluate() [4/8]

virtual Real SurrogateModel::evaluate
inline

Evaluate methods that also return predicted standard deviation (see GaussianProcess.h)

Definition at line 53 of file SurrogateModel.h.

54  {
55  evaluateError(x, std, true);
56  return 0.0;
57  }
void evaluateError(P x, R y, bool with_std=false) const
const std::vector< double > x

◆ evaluate() [5/8]

Real NearestPointSurrogate::evaluate ( const std::vector< Real > &  x) const
overridevirtual

Evaluate surrogate model given a row of parameters.

Reimplemented from SurrogateModel.

Definition at line 31 of file NearestPointSurrogate.C.

32 {
33  // Check whether input point has same dimensionality as training data
34  mooseAssert(_sample_points.size() == x.size(),
35  "Input point does not match dimensionality of training data.");
36 
38 }
unsigned int findNearestPoint(const std::vector< Real > &x) const
const std::vector< double > x
const std::vector< std::vector< Real > > & _sample_points
Array containing sample points.
const std::vector< std::vector< Real > > & _sample_results
Array containing results.

◆ evaluate() [6/8]

void NearestPointSurrogate::evaluate ( const std::vector< Real > &  x,
std::vector< Real > &  y 
) const
overridevirtual

Various evaluate methods that can be overriden.

Reimplemented from SurrogateModel.

Definition at line 41 of file NearestPointSurrogate.C.

42 {
43  mooseAssert(_sample_points.size() == x.size(),
44  "Input point does not match dimensionality of training data.");
45 
46  y.assign(_sample_results.size(), 0.0);
47 
48  unsigned int idx = findNearestPoint(x);
49 
50  for (const auto & r : index_range(y))
51  y[r] = _sample_results[r][idx];
52 }
unsigned int findNearestPoint(const std::vector< Real > &x) const
const std::vector< double > y
const std::vector< double > x
const std::vector< std::vector< Real > > & _sample_points
Array containing sample points.
const std::vector< std::vector< Real > > & _sample_results
Array containing results.
auto index_range(const T &sizable)
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)

◆ evaluate() [7/8]

virtual Real SurrogateModel::evaluate ( const std::vector< Real > &  x,
Real std 
) const
inlinevirtualinherited

Evaluate methods that also return predicted standard deviation (see GaussianProcess.h)

Reimplemented in GaussianProcessSurrogate.

Definition at line 53 of file SurrogateModel.h.

54  {
55  evaluateError(x, std, true);
56  return 0.0;
57  }
void evaluateError(P x, R y, bool with_std=false) const
const std::vector< double > x

◆ evaluate() [8/8]

virtual void SurrogateModel::evaluate ( const std::vector< Real > &  x,
std::vector< Real > &  y,
std::vector< Real > &   
) const
inlinevirtualinherited

Reimplemented in GaussianProcessSurrogate.

Definition at line 59 of file SurrogateModel.h.

60  {
61  evaluateError(x, y, true);
62  }
void evaluateError(P x, R y, bool with_std=false) const
const std::vector< double > y
const std::vector< double > x

◆ findNearestPoint()

unsigned int NearestPointSurrogate::findNearestPoint ( const std::vector< Real > &  x) const
private

Definition at line 55 of file NearestPointSurrogate.C.

Referenced by evaluate().

56 {
57  unsigned int idx = 0;
58 
59  // Container of current minimum distance during training sample loop
60  Real dist_min = std::numeric_limits<Real>::max();
61 
62  for (dof_id_type p = 0; p < _sample_points[0].size(); ++p)
63  {
64  // Sum over the distance of each point dimension
65  Real dist = 0;
66  for (unsigned int i = 0; i < x.size(); ++i)
67  {
68  Real diff = (x[i] - _sample_points[i][p]);
69  dist += diff * diff;
70  }
71 
72  // Check if this training point distance is smaller than the current minimum
73  if (dist < dist_min)
74  {
75  idx = p;
76  dist_min = dist;
77  }
78  }
79  return idx;
80 }
const std::vector< double > x
const std::vector< std::vector< Real > > & _sample_points
Array containing sample points.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
uint8_t dof_id_type

◆ getModelData()

template<typename T , typename... Args>
const T & RestartableModelInterface::getModelData ( const std::string &  data_name,
Args &&...  args 
) const
inherited

Retrieve model data from the interface.

Definition at line 85 of file RestartableModelInterface.h.

86 {
87  return _model_restartable.getRestartableData<T>(data_name, std::forward<Args>(args)...);
88 }
const T & getRestartableData(const std::string &data_name) const
Declare a piece of data as "restartable" and initialize it Similar to declareRestartableData but retu...
PublicRestartable _model_restartable
Member for interfacing with the framework&#39;s restartable system.

◆ getModelDataFileName()

const FileName & RestartableModelInterface::getModelDataFileName ( ) const
inherited

Get the associated filename.

Definition at line 33 of file RestartableModelInterface.C.

34 {
35  return _model_object.getParam<FileName>("filename");
36 }
const T & getParam(const std::string &name) const
const MooseObject & _model_object
Reference to the MooseObject that uses this interface.

◆ getSurrogateModel() [1/2]

template<>
SurrogateModel& SurrogateModelInterface::getSurrogateModel ( const std::string &  name) const
inherited

Definition at line 46 of file SurrogateModelInterface.C.

47 {
48  return getSurrogateModelByName<SurrogateModel>(_smi_params.get<UserObjectName>(name));
49 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateModel() [2/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateModel ( const std::string &  name) const
inherited

Get a SurrogateModel/Trainer with a given name.

Parameters
nameThe name of the parameter key of the sampler to retrieve
Returns
The sampler with name associated with the parameter 'name'

Definition at line 81 of file SurrogateModelInterface.h.

Referenced by SurrogateTrainer::initialize().

82 {
83  return getSurrogateModelByName<T>(_smi_params.get<UserObjectName>(name));
84 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateModelByName() [1/2]

template<>
SurrogateModel& SurrogateModelInterface::getSurrogateModelByName ( const UserObjectName &  name) const
inherited

Definition at line 31 of file SurrogateModelInterface.C.

32 {
33  std::vector<SurrogateModel *> models;
35  .query()
36  .condition<AttribName>(name)
37  .condition<AttribSystem>("SurrogateModel")
38  .queryInto(models);
39  if (models.empty())
40  mooseError("Unable to find a SurrogateModel object with the name '" + name + "'");
41  return *(models[0]);
42 }
void mooseError(Args &&... args)
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
TheWarehouse & theWarehouse() const
const std::string name
Definition: Setup.h:20
Query query()

◆ getSurrogateModelByName() [2/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateModelByName ( const UserObjectName &  name) const
inherited

Get a sampler with a given name.

Parameters
nameThe name of the sampler to retrieve
Returns
The sampler with name 'name'

Definition at line 88 of file SurrogateModelInterface.h.

Referenced by CrossValidationScores::CrossValidationScores(), EvaluateSurrogate::EvaluateSurrogate(), and InverseMapping::initialSetup().

89 {
90  std::vector<T *> models;
92  .query()
93  .condition<AttribName>(name)
94  .condition<AttribSystem>("SurrogateModel")
95  .queryInto(models);
96  if (models.empty())
97  mooseError("Unable to find a SurrogateModel object of type " + std::string(typeid(T).name()) +
98  " with the name '" + name + "'");
99  return *(models[0]);
100 }
void mooseError(Args &&... args)
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
TheWarehouse & theWarehouse() const
const std::string name
Definition: Setup.h:20
Query query()

◆ getSurrogateTrainer() [1/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateTrainer ( const std::string &  name) const
inherited

Definition at line 104 of file SurrogateModelInterface.h.

105 {
106  return getSurrogateTrainerByName<T>(_smi_params.get<UserObjectName>(name));
107 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateTrainer() [2/2]

template<>
SurrogateTrainerBase& SurrogateModelInterface::getSurrogateTrainer ( const std::string &  name) const
inherited

Definition at line 60 of file SurrogateModelInterface.C.

61 {
62  return getSurrogateTrainerByName<SurrogateTrainerBase>(_smi_params.get<UserObjectName>(name));
63 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateTrainerByName() [1/2]

template<>
SurrogateTrainerBase& SurrogateModelInterface::getSurrogateTrainerByName ( const UserObjectName &  name) const
inherited

Definition at line 53 of file SurrogateModelInterface.C.

54 {
56 }
T & getUserObject(const std::string &name, unsigned int tid=0) const
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
const std::string name
Definition: Setup.h:20
This is the base trainer class whose main functionality is the API for declaring model data...

◆ getSurrogateTrainerByName() [2/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateTrainerByName ( const UserObjectName &  name) const
inherited

Definition at line 111 of file SurrogateModelInterface.h.

Referenced by SurrogateTrainerOutput::output().

112 {
113  SurrogateTrainerBase * base_ptr =
115  T * obj_ptr = dynamic_cast<T *>(base_ptr);
116  if (!obj_ptr)
117  mooseError("Failed to find a SurrogateTrainer object of type " + std::string(typeid(T).name()) +
118  " with the name '",
119  name,
120  "' for the desired type.");
121  return *obj_ptr;
122 }
T & getUserObject(const std::string &name, unsigned int tid=0) const
void mooseError(Args &&... args)
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
const std::string name
Definition: Setup.h:20
const THREAD_ID _smi_tid
Thread ID.
This is the base trainer class whose main functionality is the API for declaring model data...

◆ hasModelData()

bool RestartableModelInterface::hasModelData ( ) const
inherited

Check if we need to load model data (if the filename parameter is used)

Definition at line 39 of file RestartableModelInterface.C.

40 {
41  return _model_object.isParamValid("filename");
42 }
bool isParamValid(const std::string &name) const
const MooseObject & _model_object
Reference to the MooseObject that uses this interface.

◆ modelMetaDataName()

const std::string& RestartableModelInterface::modelMetaDataName ( ) const
inlineinherited

Accessor for the name of the model meta data.

Definition at line 47 of file RestartableModelInterface.h.

Referenced by SurrogateTrainerOutput::output(), and MappingOutput::output().

47 { return _model_meta_data_name; }
const std::string _model_meta_data_name
The model meta data name.

◆ validParams()

InputParameters NearestPointSurrogate::validParams ( )
static

Definition at line 15 of file NearestPointSurrogate.C.

16 {
18  params.addClassDescription("Surrogate that evaluates the value from the nearest point from data "
19  "in [NearestPointTrainer.md]");
20  return params;
21 }
static InputParameters validParams()
void addClassDescription(const std::string &doc_string)

Member Data Documentation

◆ _sample_points

const std::vector<std::vector<Real> >& NearestPointSurrogate::_sample_points
protected

Array containing sample points.

Definition at line 25 of file NearestPointSurrogate.h.

Referenced by evaluate(), and findNearestPoint().

◆ _sample_results

const std::vector<std::vector<Real> >& NearestPointSurrogate::_sample_results
protected

Array containing results.

Definition at line 28 of file NearestPointSurrogate.h.

Referenced by evaluate().


The documentation for this class was generated from the following files: