https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Gaussian.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 "Gaussian.h"
11#include "Normal.h"
12#include "DelimitedFileReader.h"
13
14registerMooseObject("StochasticToolsApp", Gaussian);
15
18{
21 "Gaussian likelihood function evaluating the model goodness against experiments.");
22 params.addParam<bool>("log_likelihood", true, "Compute log-likelihood or likelihood.");
24 "noise", "Experimental noise plus model deviations against experiments.");
25 params.addParam<FileName>("file_name", "Name of the CSV file with experimental values.");
26 params.addParam<std::string>(
27 "file_column_name", "Name of column in CSV file to use, by default first column is used.");
28 params.addParam<std::vector<Real>>(
29 "exp_values", "User-specified experimental values when CSV file is not provided.");
30 return params;
31}
32
34 : LikelihoodFunctionBase(parameters),
36 _log_likelihood(getParam<bool>("log_likelihood")),
37 _noise(getReporterValue<Real>("noise"))
38{
39 if (isParamValid("exp_values") && isParamValid("file_name"))
40 paramError("exp_values", "exp_values and file_name both cannot be set at the same time.");
41 else if (isParamValid("file_name"))
42 {
43 MooseUtils::DelimitedFileReader reader(getParam<FileName>("file_name"));
44 reader.read();
45 if (isParamValid("file_column_name"))
46 _exp_values = reader.getData(getParam<std::string>("file_column_name"));
47 else
48 _exp_values = reader.getData(0);
49 }
50 else if (isParamValid("exp_values"))
51 _exp_values = getParam<std::vector<Real>>("exp_values");
52 else
53 mooseError("Either 'exp_values' or 'file_name' parameters must be specified to represent "
54 "experimental data.");
55}
56
57Real
58Gaussian::function(const std::vector<Real> & exp,
59 const std::vector<Real> & model,
60 const Real & noise,
61 const bool & log_likelihood)
62{
63 Real result = 0.0;
64 Real val1;
65 for (unsigned i = 0; i < exp.size(); ++i)
66 {
67 val1 = Normal::pdf(exp[i], model[i], noise);
68 val1 = std::log(val1);
69 result += val1;
70 }
71 if (!log_likelihood)
72 result = std::exp(result);
73 return result;
74}
75
76Real
77Gaussian::function(const std::vector<Real> & x) const
78{
80}
const std::vector< double > x
registerMooseObject("StochasticToolsApp", Gaussian)
const PertinentGeochemicalSystem model(database, {"H2O", "H+", "HCO3-", "O2(aq)", "Ca++", ">(s)FeOH", "radius_neg1", "radius_neg1.5"}, {"Calcite"}, {}, {"Calcite_asdf"}, {"CH4(aq)"}, {">(s)FeOCa+"}, "O2(aq)", "e-")
A class used to generate a Gaussian likelihood of observing model predictions.
Definition Gaussian.h:19
const Real & _noise
Noise value.
Definition Gaussian.h:44
std::vector< Real > _exp_values
Experimental data values.
Definition Gaussian.h:47
virtual Real function(const std::vector< Real > &x) const override
Return the probability density or mass function at vector x.
Definition Gaussian.C:77
const bool _log_likelihood
return log-likelihood or likelihood
Definition Gaussian.h:41
Gaussian(const InputParameters &parameters)
Definition Gaussian.C:33
static InputParameters validParams()
Definition Gaussian.C:17
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
All Likelihoods should inherit from this class.
static InputParameters validParams()
void paramError(const std::string &param, Args... args) const
void mooseError(Args &&... args) const
bool isParamValid(const std::string &name) const
const std::vector< std::vector< T > > & getData() const
virtual Real pdf(const Real &x) const override
Definition Normal.C:68