www.mooseframework.org
TruncatedNormalDistribution.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 
11 
13 
14 template <>
15 InputParameters
17 {
18  InputParameters params = validParams<NormalDistribution>();
19  params.addClassDescription("Truncated normal distribution");
20  params.addParam<Real>(
21  "lower_bound", -std::numeric_limits<Real>::max(), "Lower bound of the distribution ");
22  params.addParam<Real>(
23  "upper_bound", std::numeric_limits<Real>::max(), "Upper bound of the distribution ");
24  return params;
25 }
26 
28  : NormalDistribution(parameters),
29  _lower_bound(getParam<Real>("lower_bound")),
30  _upper_bound(getParam<Real>("upper_bound"))
31 {
33  mooseError("lower_bound in truncated normal distribution must be less than upper_bound.");
34 }
35 
36 Real
38  const Real & mean,
39  const Real & std_dev,
40  const Real & lower_bound,
41  const Real & upper_bound) const
42 {
43  if (x <= lower_bound || x >= upper_bound)
44  return 0.0;
45  else
46  return (NormalDistribution::pdf(x, mean, std_dev)) /
47  (NormalDistribution::cdf(upper_bound, mean, std_dev) -
48  NormalDistribution::cdf(lower_bound, mean, std_dev));
49 }
50 
51 Real
53  const Real & mean,
54  const Real & std_dev,
55  const Real & lower_bound,
56  const Real & upper_bound) const
57 {
58 
59  if (x <= lower_bound || x >= upper_bound)
60  return 0.0;
61  else
62  return (NormalDistribution::cdf(x, mean, std_dev) -
63  NormalDistribution::cdf(lower_bound, mean, std_dev)) /
64  (NormalDistribution::cdf(upper_bound, mean, std_dev) -
65  NormalDistribution::cdf(lower_bound, mean, std_dev));
66 }
67 
68 Real
70  const Real & mean,
71  const Real & std_dev,
72  const Real & lower_bound,
73  const Real & upper_bound) const
74 {
75  return NormalDistribution::quantile(NormalDistribution::cdf(lower_bound, mean, std_dev) +
76  p * (NormalDistribution::cdf(upper_bound, mean, std_dev) -
77  NormalDistribution::cdf(lower_bound, mean, std_dev)),
78  mean,
79  std_dev);
80 }
81 
82 Real
83 TruncatedNormalDistribution::pdf(const Real & x) const
84 {
86 }
87 
88 Real
89 TruncatedNormalDistribution::cdf(const Real & x) const
90 {
92 }
93 
94 Real
96 {
98 }
virtual Real pdf(const Real &x) const override
const Real & _upper_bound
The upper bound for the distribution.
A class used to generate a truncated normal distribution.
InputParameters validParams< TruncatedNormalDistribution >()
const Real & _lower_bound
The lower bound for the distribution.
const Real & _standard_deviation
The standard deviation of the distribution (sigma)
TruncatedNormalDistribution(const InputParameters &parameters)
virtual Real quantile(const Real &p) const override
InputParameters validParams< NormalDistribution >()
const Real & _mean
The mean (or expectation) of the distribution (mu)
virtual Real cdf(const Real &x) const override
registerMooseObject("StochasticToolsApp", TruncatedNormalDistribution)
A class used to generate a normal distribution.
virtual Real cdf(const Real &x) const override
virtual Real quantile(const Real &p) const override
virtual Real pdf(const Real &x) const override