LCOV - code coverage report
Current view: top level - src/distributions - StudentT.C (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: #31405 (292dce) with base fef103 Lines: 26 27 96.3 %
Date: 2025-09-04 07:57:52 Functions: 8 8 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 "StudentT.h"
      11             : #include "Beta.h"
      12             : 
      13             : registerMooseObject("StochasticToolsApp", StudentT);
      14             : 
      15             : InputParameters
      16          34 : StudentT::validParams()
      17             : {
      18          34 :   InputParameters params = Distribution::validParams();
      19          34 :   params.addClassDescription("Student t-distribution");
      20          68 :   params.addRequiredRangeCheckedParam<unsigned int>("dof", "dof > 0", "Degrees of freedom.");
      21          34 :   return params;
      22           0 : }
      23             : 
      24          17 : StudentT::StudentT(const InputParameters & parameters)
      25          34 :   : Distribution(parameters), _dof(getParam<unsigned int>("dof"))
      26             : {
      27          17 : }
      28             : 
      29             : Real
      30          34 : StudentT::pdf(const Real & x, const unsigned int & dof)
      31             : {
      32          34 :   Real v = dof;
      33          34 :   return std::pow((v / (v + x * x)), (1.0 + v) / 2.0) /
      34          34 :          (std::sqrt(v) * Beta::betaFunction(v / 2.0, 0.5));
      35             : }
      36             : 
      37             : Real
      38          34 : StudentT::cdf(const Real & x, const unsigned int & dof)
      39             : {
      40          34 :   Real v = dof;
      41          34 :   Real z = Beta::incompleteBeta(v / 2.0, 0.5, v / (v + x * x)) / 2.0;
      42          34 :   return x > 0 ? 1.0 - z : z;
      43             : }
      44             : 
      45             : Real
      46          34 : StudentT::quantile(const Real & p, const unsigned int & dof)
      47             : {
      48          34 :   Real v = dof;
      49          34 :   Real x = Beta::incompleteBetaInv(v / 2.0, 0.5, 2.0 * (p <= 0.5 ? p : 1.0 - p));
      50          34 :   return (p <= 0.5 ? -1.0 : 1.0) * std::sqrt(v * (1 - x) / x);
      51             : }
      52             : 
      53             : Real
      54          34 : StudentT::pdf(const Real & x) const
      55             : {
      56          34 :   return pdf(x, _dof);
      57             : }
      58             : 
      59             : Real
      60          34 : StudentT::cdf(const Real & x) const
      61             : {
      62          34 :   return cdf(x, _dof);
      63             : }
      64             : 
      65             : Real
      66          34 : StudentT::quantile(const Real & p) const
      67             : {
      68          34 :   return quantile(p, _dof);
      69             : }

Generated by: LCOV version 1.14