www.mooseframework.org
NormalDistribution.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "NormalDistribution.h"
11 #include "math.h"
12 #include "libmesh/utility.h"
13 
14 registerMooseObject("StochasticToolsApp", NormalDistribution);
15 
16 template <>
17 InputParameters
19 {
20  InputParameters params = validParams<Distribution>();
21  params.addClassDescription("Normal distribution");
22  params.addRequiredParam<Real>("mean", "Mean (or expectation) of the distribution.");
23  params.addRequiredRangeCheckedParam<Real>(
24  "standard_deviation", "standard_deviation > 0", "Standard deviation of the distribution ");
25  return params;
26 }
27 
28 NormalDistribution::NormalDistribution(const InputParameters & parameters)
29  : Distribution(parameters),
30  _mean(getParam<Real>("mean")),
31  _standard_deviation(getParam<Real>("standard_deviation"))
32 {
33 }
34 Real
35 NormalDistribution::pdf(const Real & x, const Real & mean, const Real & std_dev) const
36 {
37  return 1.0 / (std_dev * std::sqrt(2.0 * M_PI)) *
38  std::exp(-0.5 * Utility::pow<2>((x - mean) / std_dev));
39 }
40 
41 Real
42 NormalDistribution::cdf(const Real & x, const Real & mean, const Real & std_dev) const
43 {
44  return 0.5 * (1.0 + std::erf((x - mean) / (std_dev * std::sqrt(2.0))));
45 }
46 
47 Real
48 NormalDistribution::quantile(const Real & p, const Real & mean, const Real & std_dev) const
49 {
50  Real x = (p < 0.5 ? p : 1.0 - p);
51  Real y = std::sqrt(-2.0 * std::log(x));
52  Real sgn = (p - 0.5 < 0.0 ? -1.0 : 1.0);
53  Real Zp = sgn * (y + (_a[0] + _a[1] * y + _a[2] * Utility::pow<2>(y) +
54  _a[3] * Utility::pow<3>(y) + _a[4] * Utility::pow<4>(y)) /
55  (_b[0] + _b[1] * y + _b[2] * Utility::pow<2>(y) +
56  _b[3] * Utility::pow<3>(y) + _b[4] * Utility::pow<4>(y)));
57  return Zp * std_dev + mean;
58 }
59 
60 Real
61 NormalDistribution::pdf(const Real & x) const
62 {
63  return pdf(x, _mean, _standard_deviation);
64 }
65 
66 Real
67 NormalDistribution::cdf(const Real & x) const
68 {
69  return cdf(x, _mean, _standard_deviation);
70 }
71 
72 Real
73 NormalDistribution::quantile(const Real & p) const
74 {
76 }
InputParameters validParams< NormalDistribution >()
const Real & _standard_deviation
The standard deviation of the distribution (sigma)
virtual Real quantile(const Real &p) const override
const std::vector< Real > _a
const Real & _mean
The mean (or expectation) of the distribution (mu)
const std::vector< Real > _b
NormalDistribution(const InputParameters &parameters)
A class used to generate a normal distribution.
virtual Real cdf(const Real &x) const override
registerMooseObject("StochasticToolsApp", NormalDistribution)
virtual Real pdf(const Real &x) const override