https://mooseframework.inl.gov
TruncatedNormal.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 "TruncatedNormal.h"
11 
12 registerMooseObject("StochasticToolsApp", TruncatedNormal);
13 
16 {
18  params.addClassDescription("Truncated normal distribution");
19  params.addParam<Real>(
20  "lower_bound", -std::numeric_limits<Real>::max(), "Lower bound of the distribution ");
21  params.addParam<Real>(
22  "upper_bound", std::numeric_limits<Real>::max(), "Upper bound of the distribution ");
23  return params;
24 }
25 
27  : Normal(parameters),
28  _lower_bound(getParam<Real>("lower_bound")),
29  _upper_bound(getParam<Real>("upper_bound"))
30 {
32  mooseError("lower_bound in truncated normal distribution must be less than upper_bound.");
33 }
34 
35 Real
36 TruncatedNormal::pdf(const Real & x,
37  const Real & mean,
38  const Real & std_dev,
39  const Real & lower_bound,
40  const Real & upper_bound)
41 {
42  if (x <= lower_bound || x >= upper_bound)
43  return 0.0;
44  else
45  return (Normal::pdf(x, mean, std_dev)) /
46  (Normal::cdf(upper_bound, mean, std_dev) - Normal::cdf(lower_bound, mean, std_dev));
47 }
48 
49 Real
50 TruncatedNormal::cdf(const Real & x,
51  const Real & mean,
52  const Real & std_dev,
53  const Real & lower_bound,
54  const Real & upper_bound)
55 {
56 
57  if (x <= lower_bound || x >= upper_bound)
58  return 0.0;
59  else
60  return (Normal::cdf(x, mean, std_dev) - Normal::cdf(lower_bound, mean, std_dev)) /
61  (Normal::cdf(upper_bound, mean, std_dev) - Normal::cdf(lower_bound, mean, std_dev));
62 }
63 
64 Real
66  const Real & mean,
67  const Real & std_dev,
68  const Real & lower_bound,
69  const Real & upper_bound)
70 {
71  return Normal::quantile(
72  Normal::cdf(lower_bound, mean, std_dev) +
73  p * (Normal::cdf(upper_bound, mean, std_dev) - Normal::cdf(lower_bound, mean, std_dev)),
74  mean,
75  std_dev);
76 }
77 
78 Real
79 TruncatedNormal::pdf(const Real & x) const
80 {
82 }
83 
84 Real
85 TruncatedNormal::cdf(const Real & x) const
86 {
88 }
89 
90 Real
91 TruncatedNormal::quantile(const Real & p) const
92 {
94 }
const Real & _standard_deviation
The standard deviation of the distribution (sigma)
Definition: Normal.h:43
virtual Real cdf(const Real &x) const override
Definition: Normal.C:74
A class used to generate a normal distribution.
Definition: Normal.h:17
TruncatedNormal(const InputParameters &parameters)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
A class used to generate a truncated normal distribution.
virtual Real cdf(const Real &x) const override
static InputParameters validParams()
Definition: Normal.C:23
virtual Real pdf(const Real &x) const override
Definition: Normal.C:68
const Real & _lower_bound
The lower bound for the distribution.
const Real & _upper_bound
The upper bound for the distribution.
const std::vector< double > x
virtual Real pdf(const Real &x) const override
static InputParameters validParams()
virtual Real quantile(const Real &p) const override
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Real & _mean
The mean (or expectation) of the distribution (mu)
Definition: Normal.h:40
registerMooseObject("StochasticToolsApp", TruncatedNormal)
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
virtual Real quantile(const Real &p) const override
Definition: Normal.C:80