https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Private Member Functions | Private Attributes | List of all members
Beta Class Reference

A class used to generate a Beta distribution. More...

#include <Beta.h>

Inheritance diagram for Beta:
[legend]

Public Types

typedef DataFileName DataFileParameterType
 

Public Member Functions

 Beta (const InputParameters &parameters)
 
virtual Real pdf (const Real &x) const override
 
virtual Real cdf (const Real &x) const override
 
virtual Real quantile (const Real &p) const override
 
virtual Real median () const
 
virtual bool enabled () const
 
std::shared_ptr< MooseObjectgetSharedPtr ()
 
std::shared_ptr< const MooseObjectgetSharedPtr () const
 
bool isKokkosObject () const
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
const std::string & name () const
 
std::string typeAndName () const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
MooseObjectName uniqueName () const
 
const InputParametersparameters () const
 
const hit::Node * getHitNode () const
 
bool hasBase () const
 
const std::string & getBase () const
 
const TgetParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const TqueryParam (const std::string &name) const
 
const TgetRenamedParam (const std::string &old_name, const std::string &new_name) const
 
T getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &name) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramInfo (const std::string &param, Args... args) const
 
std::string messagePrefix (const bool hit_prefix=true) const
 
std::string errorPrefix (const std::string &) const
 
void mooseError (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecatedNoTrace (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
void callMooseError (std::string msg, const bool with_prefix, const hit::Node *node=nullptr, const bool show_trace=true) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &relative_path) const
 
std::string getDataFilePath (const std::string &relative_path) const
 
PerfGraphperfGraph ()
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static InputParameters validParams ()
 
static Real pdf (const Real &x, const Real &alpha, const Real &beta)
 
static Real cdf (const Real &x, const Real &alpha, const Real &beta)
 
static Real quantile (const Real &p, const Real &alpha, const Real &beta)
 
static Real betaFunction (const Real &a, const Real &b)
 Beta function: B(a,b) = Gamma(a)Gamma(b)/Gamma(a+b)
 
static Real incompleteBeta (const Real &a, const Real &b, const Real &x)
 Lower incomplete beta function.
 
static Real incompleteBetaInv (const Real &a, const Real &b, const Real &p)
 Inverse of lower incomplete beta function.
 
static void callMooseError (MooseApp *const app, const InputParameters &params, std::string msg, const bool with_prefix, const hit::Node *node, const bool show_trace=true)
 

Public Attributes

 usingCombinedWarningSolutionWarnings
 
const ConsoleStream _console
 

Static Public Attributes

static const std::string type_param
 
static const std::string name_param
 
static const std::string unique_name_param
 
static const std::string app_param
 
static const std::string moose_base_param
 
static const std::string kokkos_object_param
 

Protected Member Functions

void flagInvalidSolutionInternal (const InvalidSolutionID invalid_solution_id) const
 
InvalidSolutionID registerInvalidSolutionInternal (const std::string &message, const bool warning) const
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level) const
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level, const std::string &live_message, const bool print_dots=true) const
 
std::string timedSectionName (const std::string &section_name) const
 

Protected Attributes

const Real & _alpha
 Shape parameter 1.
 
const Real & _beta
 Shape parameter 2.
 
const bool & _enabled
 
MooseApp_app
 
Factory_factory
 
ActionFactory_action_factory
 
const std::string & _type
 
const std::string & _name
 
const InputParameters_pars
 
MooseApp_pg_moose_app
 
const std::string _prefix
 
const Parallel::Communicator & _communicator
 

Static Private Member Functions

static const hit::Node * getHitNode (const InputParameters &params)
 
static std::string messagePrefix (const InputParameters &params, const bool hit_prefix)
 

Private Attributes

const ParallelParamObject_parent
 
const MooseBase_si_moose_base
 
const FEProblemBase_si_problem
 

Detailed Description

A class used to generate a Beta distribution.

Definition at line 17 of file Beta.h.

Constructor & Destructor Documentation

◆ Beta()

Beta::Beta ( const InputParameters parameters)

Definition at line 26 of file Beta.C.

27 : Distribution(parameters), _alpha(getParam<Real>("alpha")), _beta(getParam<Real>("beta"))
28{
29}
const Real & _alpha
Shape parameter 1.
Definition Beta.h:48
const Real & _beta
Shape parameter 2.
Definition Beta.h:50
const InputParameters & parameters() const

Member Function Documentation

◆ betaFunction()

Real Beta::betaFunction ( const Real &  a,
const Real &  b 
)
static

Beta function: B(a,b) = Gamma(a)Gamma(b)/Gamma(a+b)

Definition at line 76 of file Beta.C.

77{
78 return std::tgamma(a) * std::tgamma(b) / std::tgamma(a + b);
79}

Referenced by incompleteBeta(), incompleteBetaInv(), pdf(), and StudentT::pdf().

◆ cdf() [1/2]

Real Beta::cdf ( const Real &  x) const
overridevirtual

Implements Distribution.

Definition at line 64 of file Beta.C.

65{
66 return cdf(x, _alpha, _beta);
67}
const std::vector< double > x
virtual Real cdf(const Real &x) const override
Definition Beta.C:64

Referenced by cdf().

◆ cdf() [2/2]

Real Beta::cdf ( const Real &  x,
const Real &  alpha,
const Real &  beta 
)
static

Definition at line 41 of file Beta.C.

42{
43 if (x <= 0.0)
44 return 0.0;
45 else if (x >= 1.0)
46 return 1.0;
47 else
48 return incompleteBeta(alpha, beta, x);
49}
static Real incompleteBeta(const Real &a, const Real &b, const Real &x)
Lower incomplete beta function.
Definition Beta.C:82

◆ incompleteBeta()

Real Beta::incompleteBeta ( const Real &  a,
const Real &  b,
const Real &  x 
)
static

Lower incomplete beta function.

Non-boost implementation from: Section 6.4 of https://www.cec.uchile.cl/cinetica/pcordero/MC_libros/NumericalRecipesinC.pdf

Definition at line 82 of file Beta.C.

83{
84 if (x > ((a + 1.0) / (a + b + 2.0)))
85 return 1.0 - incompleteBeta(b, a, 1.0 - x);
86
87 const Real tol = 1e-14;
88 const unsigned int max_iter = 1e3;
89 const Real coef = std::pow(x, a) * std::pow(1.0 - x, b) / a / betaFunction(a, b);
90 Real fn = 1.0;
91 Real cn = 1.0;
92 Real dn = 0.0;
93 Real num;
94 Real m = 0.0;
95 for (unsigned int i = 0; i < max_iter; ++i)
96 {
97 if (i == 0)
98 num = 1.0;
99 else if (i % 2 == 0)
100 {
101 m = i / 2.0;
102 num = m * (b - m) * x / (a + 2.0 * m) / (a + 2.0 * m - 1.0);
103 }
104 else
105 {
106 m = (i - 1) / 2.0;
107 num = -(a + m) * (a + b + m) * x / (a + 2.0 * m) / (a + 2.0 * m + 1.0);
108 }
109
110 dn = 1.0 / (1.0 + num * dn);
111 cn = 1.0 + num / cn;
112 const Real cd = cn * dn;
113 fn *= cd;
114
115 if (std::abs(1.0 - cd) < tol)
116 return coef * (fn - 1.0);
117 }
118
119 mooseAssert(false, "Could not compute incomplete beta function.");
120 return coef * (fn - 1.0);
121}
const double tol
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

Referenced by cdf(), FDistribution::cdf(), StudentT::cdf(), incompleteBeta(), and incompleteBetaInv().

◆ incompleteBetaInv()

Real Beta::incompleteBetaInv ( const Real &  a,
const Real &  b,
const Real &  p 
)
static

Inverse of lower incomplete beta function.

Non-boost implementation uses Newton-Raphson to find root of incompleteBeta(a, b, x) - p

Definition at line 124 of file Beta.C.

125{
126 if (a < b)
127 return 1.0 - incompleteBetaInv(b, a, 1.0 - p);
128
129 // Try with Newton method
130 Real x = 0.5;
131 const Real tol = 1e-14;
132 const unsigned int max_iter = 1e3;
133 const Real scale = betaFunction(a, b);
134 Real f;
135 Real df;
136 for (unsigned int i = 0; i < max_iter; ++i)
137 {
138 f = incompleteBeta(a, b, x) - p;
139 if (std::abs(f) < tol)
140 return x;
141 df = std::pow(x, a - 1.0) * std::pow(1.0 - x, b - 1.0) / scale;
142 x -= f / df;
143 // There's a divergence so try out bisection
144 if (x < 0 || x > 1.0)
145 break;
146 }
147
148 // Try with bisection method
149 Real x1 = 0; // f(0) = -p
150 Real x2 = 1; // f(1) = 1 - p
151 for (unsigned int i = 0; i < max_iter; ++i)
152 {
153 x = (x2 + x1) / 2.0;
154 f = incompleteBeta(a, b, x) - p;
155 if (std::abs(f) < tol)
156 return x;
157 else if (f < 0)
158 x1 = x;
159 else
160 x2 = x;
161 }
162
163 mooseAssert(false, "Could not find inverse of incomplete gamma function.");
164 return x;
165}
Real f(Real x)
Test function for Brents method.
const Real p
Real scale
static Real incompleteBetaInv(const Real &a, const Real &b, const Real &p)
Inverse of lower incomplete beta function.
Definition Beta.C:124

Referenced by incompleteBetaInv(), quantile(), FDistribution::quantile(), and StudentT::quantile().

◆ pdf() [1/2]

Real Beta::pdf ( const Real &  x) const
overridevirtual

Implements Distribution.

Definition at line 58 of file Beta.C.

59{
60 return pdf(x, _alpha, _beta);
61}
virtual Real pdf(const Real &x) const override
Definition Beta.C:58

Referenced by pdf(), and FDistribution::pdf().

◆ pdf() [2/2]

Real Beta::pdf ( const Real &  x,
const Real &  alpha,
const Real &  beta 
)
static

Definition at line 32 of file Beta.C.

33{
34 if (x <= 0.0 || x > 1.0)
35 return 0.0;
36 else
37 return std::pow(x, alpha - 1.0) * std::pow(1.0 - x, beta - 1.0) / betaFunction(alpha, beta);
38}

◆ quantile() [1/2]

Real Beta::quantile ( const Real &  p) const
overridevirtual

Implements Distribution.

Definition at line 70 of file Beta.C.

71{
72 return quantile(p, _alpha, _beta);
73}
virtual Real quantile(const Real &p) const override
Definition Beta.C:70

Referenced by quantile().

◆ quantile() [2/2]

Real Beta::quantile ( const Real &  p,
const Real &  alpha,
const Real &  beta 
)
static

Definition at line 52 of file Beta.C.

53{
54 return incompleteBetaInv(alpha, beta, p);
55}

◆ validParams()

InputParameters Beta::validParams ( )
static

Definition at line 17 of file Beta.C.

18{
20 params.addClassDescription("Beta distribution");
21 params.addRequiredRangeCheckedParam<Real>("alpha", "alpha > 0", "Shape parameter 1.");
22 params.addRequiredRangeCheckedParam<Real>("beta", "beta > 0", "Shape parameter 2.");
23 return params;
24}
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)

Member Data Documentation

◆ _alpha

const Real& Beta::_alpha
protected

Shape parameter 1.

Definition at line 48 of file Beta.h.

Referenced by cdf(), pdf(), and quantile().

◆ _beta

const Real& Beta::_beta
protected

Shape parameter 2.

Definition at line 50 of file Beta.h.

Referenced by cdf(), pdf(), and quantile().


The documentation for this class was generated from the following files: