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 32 : StudentT::validParams() 17 : { 18 32 : InputParameters params = Distribution::validParams(); 19 32 : params.addClassDescription("Student t-distribution"); 20 64 : params.addRequiredRangeCheckedParam<unsigned int>("dof", "dof > 0", "Degrees of freedom."); 21 32 : return params; 22 0 : } 23 : 24 16 : StudentT::StudentT(const InputParameters & parameters) 25 32 : : Distribution(parameters), _dof(getParam<unsigned int>("dof")) 26 : { 27 16 : } 28 : 29 : Real 30 32 : StudentT::pdf(const Real & x, const unsigned int & dof) 31 : { 32 32 : Real v = dof; 33 32 : return std::pow((v / (v + x * x)), (1.0 + v) / 2.0) / 34 32 : (std::sqrt(v) * Beta::betaFunction(v / 2.0, 0.5)); 35 : } 36 : 37 : Real 38 32 : StudentT::cdf(const Real & x, const unsigned int & dof) 39 : { 40 32 : Real v = dof; 41 32 : Real z = Beta::incompleteBeta(v / 2.0, 0.5, v / (v + x * x)) / 2.0; 42 32 : return x > 0 ? 1.0 - z : z; 43 : } 44 : 45 : Real 46 32 : StudentT::quantile(const Real & p, const unsigned int & dof) 47 : { 48 32 : Real v = dof; 49 32 : Real x = Beta::incompleteBetaInv(v / 2.0, 0.5, 2.0 * (p <= 0.5 ? p : 1.0 - p)); 50 32 : return (p <= 0.5 ? -1.0 : 1.0) * std::sqrt(v * (1 - x) / x); 51 : } 52 : 53 : Real 54 32 : StudentT::pdf(const Real & x) const 55 : { 56 32 : return pdf(x, _dof); 57 : } 58 : 59 : Real 60 32 : StudentT::cdf(const Real & x) const 61 : { 62 32 : return cdf(x, _dof); 63 : } 64 : 65 : Real 66 32 : StudentT::quantile(const Real & p) const 67 : { 68 32 : return quantile(p, _dof); 69 : }