https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
13registerMooseObject("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
29Real
30StudentT::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
37Real
38StudentT::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
45Real
46StudentT::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
53Real
54StudentT::pdf(const Real & x) const
55{
56 return pdf(x, _dof);
57}
58
59Real
60StudentT::cdf(const Real & x) const
61{
62 return cdf(x, _dof);
63}
64
65Real
66StudentT::quantile(const Real & p) const
67{
68 return quantile(p, _dof);
69}
const std::vector< double > x
const Real p
const double v
registerMooseObject("StochasticToolsApp", StudentT)
void ErrorVector unsigned int
static Real incompleteBetaInv(const Real &a, const Real &b, const Real &p)
Inverse of lower incomplete beta function.
Definition Beta.C:124
static Real incompleteBeta(const Real &a, const Real &b, const Real &x)
Lower incomplete beta function.
Definition Beta.C:82
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
static InputParameters validParams()
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
A class used to generate a Student's t distribution.
Definition StudentT.h:18
virtual Real quantile(const Real &p) const override
Definition StudentT.C:66
virtual Real pdf(const Real &x) const override
Definition StudentT.C:54
virtual Real cdf(const Real &x) const override
Definition StudentT.C:60
static InputParameters validParams()
Definition StudentT.C:16
StudentT(const InputParameters &parameters)
Definition StudentT.C:24
const unsigned int & _dof
Degrees of freedom.
Definition StudentT.h:34