https://mooseframework.inl.gov
StudentT.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 "StudentT.h"
11 #include "Beta.h"
12 
13 registerMooseObject("StochasticToolsApp", StudentT);
14 
17 {
19  params.addClassDescription("Student t-distribution");
20  params.addRequiredRangeCheckedParam<unsigned int>("dof", "dof > 0", "Degrees of freedom.");
21  return params;
22 }
23 
25  : Distribution(parameters), _dof(getParam<unsigned int>("dof"))
26 {
27 }
28 
29 Real
30 StudentT::pdf(const Real & x, const unsigned int & dof)
31 {
32  Real v = dof;
33  return std::pow((v / (v + x * x)), (1.0 + v) / 2.0) /
34  (std::sqrt(v) * Beta::betaFunction(v / 2.0, 0.5));
35 }
36 
37 Real
38 StudentT::cdf(const Real & x, const unsigned int & dof)
39 {
40  Real v = dof;
41  Real z = Beta::incompleteBeta(v / 2.0, 0.5, v / (v + x * x)) / 2.0;
42  return x > 0 ? 1.0 - z : z;
43 }
44 
45 Real
46 StudentT::quantile(const Real & p, const unsigned int & dof)
47 {
48  Real v = dof;
49  Real x = Beta::incompleteBetaInv(v / 2.0, 0.5, 2.0 * (p <= 0.5 ? p : 1.0 - p));
50  return (p <= 0.5 ? -1.0 : 1.0) * std::sqrt(v * (1 - x) / x);
51 }
52 
53 Real
54 StudentT::pdf(const Real & x) const
55 {
56  return pdf(x, _dof);
57 }
58 
59 Real
60 StudentT::cdf(const Real & x) const
61 {
62  return cdf(x, _dof);
63 }
64 
65 Real
66 StudentT::quantile(const Real & p) const
67 {
68  return quantile(p, _dof);
69 }
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
virtual Real cdf(const Real &x) const override
Definition: StudentT.C:60
virtual Real pdf(const Real &x) const override
Definition: StudentT.C:54
static Real incompleteBetaInv(const Real &a, const Real &b, const Real &p)
Inverse of lower incomplete beta function.
Definition: Beta.C:124
const unsigned int & _dof
Degrees of freedom.
Definition: StudentT.h:34
virtual Real quantile(const Real &p) const override
Definition: StudentT.C:66
const std::vector< double > x
registerMooseObject("StochasticToolsApp", StudentT)
static Real betaFunction(const Real &a, const Real &b)
Beta function: B(a,b) = Gamma(a)Gamma(b)/Gamma(a+b)
Definition: Beta.C:76
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::string v
Definition: NS.h:84
static InputParameters validParams()
StudentT(const InputParameters &parameters)
Definition: StudentT.C:24
static Real incompleteBeta(const Real &a, const Real &b, const Real &x)
Lower incomplete beta function.
Definition: Beta.C:82
void addClassDescription(const std::string &doc_string)
static InputParameters validParams()
Definition: StudentT.C:16
MooseUnits pow(const MooseUnits &, int)
void ErrorVector unsigned int
A class used to generate a Student&#39;s t distribution.
Definition: StudentT.h:17