https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
12registerMooseObject("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
35Real
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
49Real
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
64Real
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
78Real
79TruncatedNormal::pdf(const Real & x) const
80{
82}
83
84Real
85TruncatedNormal::cdf(const Real & x) const
86{
88}
89
90Real
const std::vector< double > x
const Real p
registerMooseObject("StochasticToolsApp", TruncatedNormal)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void mooseError(Args &&... args) const
A class used to generate a normal distribution.
Definition Normal.h:18
const Real & _standard_deviation
The standard deviation of the distribution (sigma)
Definition Normal.h:43
const Real & _mean
The mean (or expectation) of the distribution (mu)
Definition Normal.h:40
static InputParameters validParams()
Definition Normal.C:23
virtual Real cdf(const Real &x) const override
Definition Normal.C:74
virtual Real pdf(const Real &x) const override
Definition Normal.C:68
virtual Real quantile(const Real &p) const override
Definition Normal.C:80
A class used to generate a truncated normal distribution.
virtual Real pdf(const Real &x) const override
virtual Real cdf(const Real &x) const override
static InputParameters validParams()
const Real & _lower_bound
The lower bound for the distribution.
virtual Real quantile(const Real &p) const override
const Real & _upper_bound
The upper bound for the distribution.
TruncatedNormal(const InputParameters &parameters)