https://mooseframework.inl.gov
TestLikelihood.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 "TestLikelihood.h"
11 #include "Sampler.h"
12 
13 registerMooseObject("StochasticToolsTestApp", TestLikelihood);
14 
17 {
20  params.addClassDescription("Reporter to test a likelihood object.");
21  params.addParam<ReporterValueName>(
22  "function", "function", "Value of the density or mass function.");
23  params.addRequiredParam<std::vector<UserObjectName>>("likelihoods", "Names of likelihoods.");
24  params.addRequiredParam<ReporterName>("model_pred", "Reporter with the model predictions.");
25  params.addParam<ReporterValueName>(
26  "model_pred_required",
27  "model_pred_required",
28  "Modified value of the model output from this reporter class.");
29  params.addRequiredParam<SamplerName>("sampler", "The sampler object.");
30  return params;
31 }
32 
34  : GeneralReporter(parameters),
35  LikelihoodInterface(parameters),
36  _function(declareValue<std::vector<Real>>("function")),
37  _model_pred(getReporterValue<std::vector<Real>>("model_pred", REPORTER_MODE_DISTRIBUTED)),
38  _model_pred_required(declareValue<std::vector<Real>>("model_pred_required")),
39  _sampler(getSampler("sampler")),
40  _local_comm(_sampler.getLocalComm())
41 {
42  for (const UserObjectName & name : getParam<std::vector<UserObjectName>>("likelihoods"))
44 
45  _function.resize(_likelihoods.size());
46 }
47 
48 void
50 {
53  for (unsigned i = 0; i < _function.size(); ++i)
54  _function[i] = _likelihoods[i]->function(_model_pred_required);
55 }
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
static InputParameters validParams()
virtual void execute() override
virtual const std::string & name() const
void addRequiredParam(const std::string &name, const std::string &doc_string)
static InputParameters validParams()
std::vector< const LikelihoodFunctionBase * > _likelihoods
Storage for the likelihood objects to be utilized.
registerMooseObject("StochasticToolsTestApp", TestLikelihood)
const T & getParam(const std::string &name) const
std::vector< Real > & _function
Value of the density or mass function.
const ReporterMode REPORTER_MODE_DISTRIBUTED
static InputParameters validParams()
TestLikelihood will help test new likelihood objects.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< Real > & _model_pred_required
Transfer the right outputs to the file.
const std::vector< Real > & _model_pred
model prediction values
LikelihoodFunctionBase * getLikelihoodFunctionByName(const UserObjectName &name) const
Lookup a LikelihoodFunction object by name and return pointer.
void addClassDescription(const std::string &doc_string)
libMesh::Parallel::Communicator & _local_comm
Communicator that was split based on samples that have rows.
TestLikelihood(const InputParameters &parameters)