https://mooseframework.inl.gov
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
TruncatedNormal Class Reference

A class used to generate a truncated normal distribution. More...

#include <TruncatedNormal.h>

Inheritance diagram for TruncatedNormal:
[legend]

Public Types

typedef DataFileName DataFileParameterType
 

Public Member Functions

 TruncatedNormal (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
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
virtual const std::string & name () const
 
std::string typeAndName () const
 
std::string errorPrefix (const std::string &error_type) const
 
void callMooseError (std::string msg, const bool with_prefix) const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
const InputParametersparameters () const
 
MooseObjectName uniqueName () const
 
const T & getParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const T * queryParam (const std::string &name) const
 
const T & getRenamedParam (const std::string &old_name, const std::string &new_name) const
 
getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &nm) const
 
void paramError (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
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void mooseError (Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseInfo (Args &&... args) 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 &mean, const Real &std_dev, const Real &lower_bound, const Real &upper_bound)
 
static Real cdf (const Real &x, const Real &mean, const Real &std_dev, const Real &lower_bound, const Real &upper_bound)
 
static Real quantile (const Real &p, const Real &mean, const Real &std_dev, const Real &lower_bound, const Real &upper_bound)
 
static Real pdf (const Real &x, const Real &mean, const Real &std_dev)
 
static Real cdf (const Real &x, const Real &mean, const Real &std_dev)
 
static Real quantile (const Real &p, const Real &mean, const Real &std_dev)
 

Public Attributes

const ConsoleStream _console
 

Protected Member Functions

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_lower_bound
 The lower bound for the distribution. More...
 
const Real_upper_bound
 The upper bound for the distribution. More...
 
const Real_mean
 The mean (or expectation) of the distribution (mu) More...
 
const Real_standard_deviation
 The standard deviation of the distribution (sigma) More...
 
const bool & _enabled
 
MooseApp_app
 
const std::string _type
 
const std::string _name
 
const InputParameters_pars
 
Factory_factory
 
ActionFactory_action_factory
 
MooseApp_pg_moose_app
 
const std::string _prefix
 
const Parallel::Communicator & _communicator
 

Static Protected Attributes

static const std::array< Real, 6 > _a
 
static const std::array< Real, 6 > _b
 

Detailed Description

A class used to generate a truncated normal distribution.

Definition at line 17 of file TruncatedNormal.h.

Constructor & Destructor Documentation

◆ TruncatedNormal()

TruncatedNormal::TruncatedNormal ( const InputParameters parameters)

Definition at line 26 of file TruncatedNormal.C.

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 }
Normal(const InputParameters &parameters)
Definition: Normal.C:33
const Real & _lower_bound
The lower bound for the distribution.
const Real & _upper_bound
The upper bound for the distribution.
void mooseError(Args &&... args) const
const InputParameters & parameters() const

Member Function Documentation

◆ cdf() [1/3]

Real TruncatedNormal::cdf ( const Real x) const
overridevirtual

Reimplemented from Normal.

Definition at line 85 of file TruncatedNormal.C.

86 {
88 }
const Real & _standard_deviation
The standard deviation of the distribution (sigma)
Definition: Normal.h:43
virtual Real cdf(const Real &x) const override
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
const Real & _mean
The mean (or expectation) of the distribution (mu)
Definition: Normal.h:40

◆ cdf() [2/3]

Real Normal::cdf ( const Real x,
const Real mean,
const Real std_dev 
)
staticinherited

Definition at line 48 of file Normal.C.

49 {
50  return 0.5 * (1.0 + std::erf((x - mean) / (std_dev * std::sqrt(2.0))));
51 }
const std::vector< double > x

◆ cdf() [3/3]

Real TruncatedNormal::cdf ( const Real x,
const Real mean,
const Real std_dev,
const Real lower_bound,
const Real upper_bound 
)
static

Definition at line 50 of file TruncatedNormal.C.

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 }
virtual Real cdf(const Real &x) const override
Definition: Normal.C:74
const std::vector< double > x

◆ pdf() [1/3]

Real TruncatedNormal::pdf ( const Real x) const
overridevirtual

Reimplemented from Normal.

Definition at line 79 of file TruncatedNormal.C.

Referenced by TruncatedGaussian::function().

80 {
82 }
const Real & _standard_deviation
The standard deviation of the distribution (sigma)
Definition: Normal.h:43
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
const Real & _mean
The mean (or expectation) of the distribution (mu)
Definition: Normal.h:40

◆ pdf() [2/3]

Real TruncatedNormal::pdf ( const Real x,
const Real mean,
const Real std_dev,
const Real lower_bound,
const Real upper_bound 
)
static

Definition at line 36 of file TruncatedNormal.C.

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 }
virtual Real cdf(const Real &x) const override
Definition: Normal.C:74
virtual Real pdf(const Real &x) const override
Definition: Normal.C:68
const std::vector< double > x

◆ pdf() [3/3]

Real Normal::pdf ( const Real x,
const Real mean,
const Real std_dev 
)
staticinherited

Definition at line 41 of file Normal.C.

42 {
43  return 1.0 / (std_dev * std::sqrt(2.0 * M_PI)) *
44  std::exp(-0.5 * Utility::pow<2>((x - mean) / std_dev));
45 }
const std::vector< double > x

◆ quantile() [1/3]

Real TruncatedNormal::quantile ( const Real p) const
overridevirtual

Reimplemented from Normal.

Definition at line 91 of file TruncatedNormal.C.

Referenced by IndependentGaussianMH::proposeSamples().

92 {
94 }
const Real & _standard_deviation
The standard deviation of the distribution (sigma)
Definition: Normal.h:43
const Real & _lower_bound
The lower bound for the distribution.
const Real & _upper_bound
The upper bound for the distribution.
virtual Real quantile(const Real &p) const override
const Real & _mean
The mean (or expectation) of the distribution (mu)
Definition: Normal.h:40

◆ quantile() [2/3]

Real Normal::quantile ( const Real p,
const Real mean,
const Real std_dev 
)
staticinherited

Definition at line 54 of file Normal.C.

55 {
56  const Real x = (p < 0.5 ? p : 1.0 - p);
57  const Real y = std::sqrt(-2.0 * std::log(x));
58  const Real y2 = y * y;
59  const Real y3 = y2 * y;
60  const Real y4 = y3 * y;
61  const Real sgn = (p - 0.5 < 0.0 ? -1.0 : 1.0);
62  const Real Zp = sgn * (y + (_a[0] + _a[1] * y + _a[2] * y2 + _a[3] * y3 + _a[4] * y4) /
63  (_b[0] + _b[1] * y + _b[2] * y2 + _b[3] * y3 + _b[4] * y4));
64  return Zp * std_dev + mean;
65 }
int sgn(T val)
The sign function.
Definition: Numerics.h:41
const std::vector< double > y
const std::vector< double > x
static const std::array< Real, 6 > _a
Definition: Normal.h:35
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::array< Real, 6 > _b
Definition: Normal.h:36

◆ quantile() [3/3]

Real TruncatedNormal::quantile ( const Real p,
const Real mean,
const Real std_dev,
const Real lower_bound,
const Real upper_bound 
)
static

Definition at line 65 of file TruncatedNormal.C.

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 }
virtual Real cdf(const Real &x) const override
Definition: Normal.C:74
virtual Real quantile(const Real &p) const override
Definition: Normal.C:80

◆ validParams()

InputParameters TruncatedNormal::validParams ( )
static

Definition at line 15 of file TruncatedNormal.C.

Referenced by TruncatedNormalDistribution::validParams().

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 }
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
static InputParameters validParams()
Definition: Normal.C:23
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void addClassDescription(const std::string &doc_string)

Member Data Documentation

◆ _a

const std::array< Real, 6 > Normal::_a
staticprotectedinherited
Initial value:
= {
{-0.322232431088, -1.0, -0.342242088547, -0.0204231210245, -0.0000453642210148}}

Coefficients for the rational function used to approximate the quantile

Definition at line 35 of file Normal.h.

Referenced by Normal::quantile().

◆ _b

const std::array< Real, 6 > Normal::_b
staticprotectedinherited
Initial value:
= {
{0.099348462606, 0.588581570495, 0.531103462366, 0.10353775285, 0.0038560700634}}

Definition at line 36 of file Normal.h.

Referenced by Normal::quantile().

◆ _lower_bound

const Real& TruncatedNormal::_lower_bound
protected

The lower bound for the distribution.

Definition at line 46 of file TruncatedNormal.h.

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

◆ _mean

const Real& Normal::_mean
protectedinherited

The mean (or expectation) of the distribution (mu)

Definition at line 40 of file Normal.h.

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

◆ _standard_deviation

const Real& Normal::_standard_deviation
protectedinherited

The standard deviation of the distribution (sigma)

Definition at line 43 of file Normal.h.

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

◆ _upper_bound

const Real& TruncatedNormal::_upper_bound
protected

The upper bound for the distribution.

Definition at line 49 of file TruncatedNormal.h.

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


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