LCOV - code coverage report
Current view: top level - src/likelihoods - TruncatedGaussian.C (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: f45d79 Lines: 19 21 90.5 %
Date: 2025-07-25 05:00:46 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "TruncatedGaussian.h"
      11             : #include "TruncatedNormal.h"
      12             : 
      13             : registerMooseObject("StochasticToolsApp", TruncatedGaussian);
      14             : 
      15             : InputParameters
      16          44 : TruncatedGaussian::validParams()
      17             : {
      18          44 :   InputParameters params = Gaussian::validParams();
      19          44 :   params.addClassDescription(
      20             :       "TruncatedGaussian likelihood function evaluating the model goodness against experiments.");
      21          88 :   params.addRequiredParam<Real>("lower_bound", "Lower bound for the quantity of interest.");
      22          88 :   params.addRequiredParam<Real>("upper_bound", "Upper bound for the quantity of interest.");
      23          44 :   return params;
      24           0 : }
      25             : 
      26          24 : TruncatedGaussian::TruncatedGaussian(const InputParameters & parameters)
      27             :   : Gaussian(parameters),
      28          24 :     _lower_bound(getParam<Real>("lower_bound")),
      29          72 :     _upper_bound(getParam<Real>("upper_bound"))
      30             : {
      31          24 :   if (!(_lower_bound < _upper_bound))
      32           4 :     mooseError("The specified lower bound should be less than the upper bound.");
      33          20 : }
      34             : 
      35             : Real
      36          20 : TruncatedGaussian::function(const std::vector<Real> & exp,
      37             :                             const std::vector<Real> & model,
      38             :                             const Real & noise,
      39             :                             const Real & lower_bound,
      40             :                             const Real & upper_bound,
      41             :                             const bool & log_likelihood)
      42             : {
      43             :   Real result = 0.0;
      44          80 :   for (unsigned i = 0; i < exp.size(); ++i)
      45          60 :     result += std::log(TruncatedNormal::pdf(exp[i], model[i], noise, lower_bound, upper_bound));
      46          20 :   if (!log_likelihood)
      47           0 :     result = std::exp(result);
      48          20 :   return result;
      49             : }
      50             : 
      51             : Real
      52          20 : TruncatedGaussian::function(const std::vector<Real> & x) const
      53             : {
      54          20 :   return function(_exp_values, x, _noise, _lower_bound, _upper_bound, _log_likelihood);
      55             : }

Generated by: LCOV version 1.14