https://mooseframework.inl.gov
Loading...
Searching...
No Matches
FDistribution.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 "FDistribution.h"
11#include "Beta.h"
12
13registerMooseObject("StochasticToolsApp", FDistribution);
14
17{
19 params.addClassDescription("F-distribution or Fisher-Snedecor distribution");
20 params.addRequiredRangeCheckedParam<unsigned int>("df1", "df1 > 0", "Degrees of freedom 1.");
21 params.addRequiredRangeCheckedParam<unsigned int>("df2", "df2 > 0", "Degrees of freedom 2.");
22 return params;
23}
24
26 : Distribution(parameters),
27 _df1(getParam<unsigned int>("df1")),
28 _df2(getParam<unsigned int>("df2"))
29{
30}
31
32Real
33FDistribution::pdf(const Real & x, const unsigned int & df1, const unsigned int & df2)
34{
35 // Handy definitions
36 Real d1 = static_cast<Real>(df1);
37 Real d2 = static_cast<Real>(df2);
38 Real d1x = d1 * x;
39 Real d2pd1x = d2 + d1x;
40
41 Real a;
42 Real b;
43 Real y;
44 Real z;
45 if (d1 * x > d2)
46 {
47 a = d2 / 2.0;
48 b = d1 / 2.0;
49 y = (d2 * d1) / (d2pd1x * d2pd1x);
50 z = d2 / d2pd1x;
51 }
52 else
53 {
54 a = d1 / 2.0;
55 b = d2 / 2.0;
56 y = (d2pd1x * d1 - d1x * d1) / (d2pd1x * d2pd1x);
57 z = d1x / d2pd1x;
58 }
59
60 return y * Beta::pdf(z, a, b);
61}
62
63Real
64FDistribution::cdf(const Real & x, const unsigned int & df1, const unsigned int & df2)
65{
66 // Handy definitions
67 Real d1 = static_cast<Real>(df1);
68 Real d2 = static_cast<Real>(df2);
69
70 return Beta::incompleteBeta(d1 / 2.0, d2 / 2.0, d1 * x / (d1 * x + d2));
71}
72
73Real
74FDistribution::quantile(const Real & p, const unsigned int & df1, const unsigned int & df2)
75{
76 // Handy definitions
77 Real d1 = static_cast<Real>(df1);
78 Real d2 = static_cast<Real>(df2);
79
80 Real z = Beta::incompleteBetaInv(d1 / 2.0, d2 / 2.0, p);
81 return d2 * z / d1 / (1.0 - z);
82}
83
84Real
85FDistribution::pdf(const Real & x) const
86{
87 return pdf(x, _df1, _df2);
88}
89
90Real
91FDistribution::cdf(const Real & x) const
92{
93 return cdf(x, _df1, _df2);
94}
95
96Real
97FDistribution::quantile(const Real & p) const
98{
99 return quantile(p, _df1, _df2);
100}
const std::vector< double > y
const std::vector< double > x
registerMooseObject("StochasticToolsApp", FDistribution)
const Real p
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
virtual Real pdf(const Real &x) const override
Definition Beta.C:58
static InputParameters validParams()
A class used to generate am F-distribution.
static InputParameters validParams()
virtual Real cdf(const Real &x) const override
const unsigned int & _df1
FDistribution(const InputParameters &parameters)
virtual Real pdf(const Real &x) const override
const unsigned int & _df2
virtual Real quantile(const Real &p) const override
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)