Permalink
Browse files

Merge pull request #12707 from jiangwen84/non_boost_distribution

Add non-boost normal, truncated_normal and translated weibull distributions
  • Loading branch information...
aeslaughter committed Jan 22, 2019
2 parents 8c471fc + ddb612d commit fa9a5100e0c1567ca3d51b199642ca14d7ed114f
Showing with 735 additions and 78 deletions.
  1. +7 −0 modules/stochastic_tools/doc/content/bib/stochastic_tools.bib
  2. +6 −6 ...tools/doc/content/source/distributions/{LognormalDistribution.md → BoostLognormalDistribution.md}
  3. +31 −0 modules/stochastic_tools/doc/content/source/distributions/BoostNormalDistribution.md
  4. +44 −0 modules/stochastic_tools/doc/content/source/distributions/BoostWeibullDistribution.md
  5. +4 −5 modules/stochastic_tools/doc/content/source/distributions/NormalDistribution.md
  6. +32 −0 modules/stochastic_tools/doc/content/source/distributions/TruncatedNormalDistribution.md
  7. +4 −23 modules/stochastic_tools/doc/content/source/distributions/WeibullDistribution.md
  8. +8 −7 ...s/stochastic_tools/include/distributions/{LognormalDistribution.h → BoostLognormalDistribution.h}
  9. +29 −0 modules/stochastic_tools/include/distributions/BoostNormalDistribution.h
  10. +29 −0 modules/stochastic_tools/include/distributions/BoostWeibullDistribution.h
  11. +24 −4 modules/stochastic_tools/include/distributions/NormalDistribution.h
  12. +40 −0 modules/stochastic_tools/include/distributions/TruncatedNormalDistribution.h
  13. +18 −4 modules/stochastic_tools/include/distributions/WeibullDistribution.h
  14. +4 −4 modules/stochastic_tools/src/distributions/{LognormalDistribution.C → BoostLognormalDistribution.C}
  15. +30 −0 modules/stochastic_tools/src/distributions/BoostNormalDistribution.C
  16. +30 −0 modules/stochastic_tools/src/distributions/BoostWeibullDistribution.C
  17. +45 −6 modules/stochastic_tools/src/distributions/NormalDistribution.C
  18. +62 −0 modules/stochastic_tools/src/distributions/TruncatedNormalDistribution.C
  19. +40 −6 modules/stochastic_tools/src/distributions/WeibullDistribution.C
  20. +1 −1 modules/stochastic_tools/test/tests/distributions/{lognormal.i → boost_lognormal.i}
  21. +58 −0 modules/stochastic_tools/test/tests/distributions/boost_normal.i
  22. +58 −0 modules/stochastic_tools/test/tests/distributions/boost_weibull.i
  23. 0 modules/stochastic_tools/test/tests/distributions/gold/{lognormal_out.csv → boost_lognormal_out.csv}
  24. +2 −0 modules/stochastic_tools/test/tests/distributions/gold/boost_weibull_out.csv
  25. +1 −1 modules/stochastic_tools/test/tests/distributions/gold/normal_out.csv
  26. +2 −0 modules/stochastic_tools/test/tests/distributions/gold/truncated_normal_out.csv
  27. +0 −1 modules/stochastic_tools/test/tests/distributions/gold/weibull_out.csv
  28. +65 −9 modules/stochastic_tools/test/tests/distributions/tests
  29. +59 −0 modules/stochastic_tools/test/tests/distributions/truncated_normal.i
  30. +1 −0 modules/stochastic_tools/test/tests/distributions/weibull.i
  31. +1 −1 modules/stochastic_tools/test/tests/samplers/monte_carlo/monte_carlo_weibull.i
@@ -9,3 +9,10 @@ @article{saltelli2002making
publisher={Elsevier},
url={https://doi.org/10.1016/S0010-4655(02)00280-1}
}

@book{Kennedy1980,
title = {Statistical Computing},
author = {Kennedy and Gentle},
year = {1980},
publisher = {Marcel Dekker}
}
@@ -1,7 +1,7 @@
# LognormalDistribution
# BoostLognormalDistribution

!alert warning
The lognormalDistribution object requires that libMesh be configured to utilize an external
The BoostLognormalDistribution object requires that libMesh be configured to utilize an external
[Boost](www.boost.org) library. This may be done by using the `--with-boost` configuration option
when compiling libMesh.

@@ -30,10 +30,10 @@ where $m$ is the location parameter and $s$ is the scale parameter ($s > 0$).
The following input file defines a lognormal distribution with the location parameter -0.371 and the
scale parameter 0.52.

!listing modules/stochastic_tools/test/tests/distributions/lognormal.i block=Distributions
!listing modules/stochastic_tools/test/tests/distributions/boost_lognormal.i block=Distributions

!syntax parameters /Distributions/LognormalDistribution
!syntax parameters /Distributions/BoostLognormalDistribution

!syntax inputs /Distributions/LognormalDistribution
!syntax inputs /Distributions/BoostLognormalDistribution

!syntax children /Distributions/LognormalDistribution
!syntax children /Distributions/BoostLognormalDistribution
@@ -0,0 +1,31 @@
# BoostNormalDistribution

!alert warning
The BoostNormalDistribution object requires that libMesh be configured to utilize an external
[Boost](www.boost.org) library. This may be done by using the `--with-boost` configuration option
when compiling libMesh.

## Description

The normal (or Gaussian) distribution object defines a
[normal distribution](https://en.wikipedia.org/wiki/Normal_distribution) function with the provided
`mean` and `standard_deviation` parameters. The probability density function (PDF) of the normal
distribution is given by the [eq:normal].

\begin{equation}
\label{eq:normal}
f(x \; | \; \mu, \sigma^2) = \frac{1}{\sqrt{2\pi\sigma^2} } \; e^{ -\frac{(x-\mu)^2}{2\sigma^2} }
\end{equation}
where $\mu$ is the mean and $\sigma$ is the standard deviation ($\sigma > 0$) of the distribution.

## Example Input Syntax

The following input file defines a normal distribution with a mean of 0 and a standard deviation of 1.

!listing modules/stochastic_tools/test/tests/distributions/boost_normal.i block=Distributions

!syntax parameters /Distributions/BoostNormalDistribution

!syntax inputs /Distributions/BoostNormalDistribution

!syntax children /Distributions/BoostNormalDistribution
@@ -0,0 +1,44 @@
# BoostWeibullDistribution

!alert warning
The BoostWeibullDistribution object requires that libMesh be configured to utilize an external
[Boost](www.boost.org) library. This may be done using the `--with-boost` configuration option
when compiling libMesh.

## Description

As the name suggests, the BoostWeibullDistribution object defines a Weibull distribution which
has a probability density function (PDF) defined as

\begin{equation}
f(x;\lambda,k) =
\begin{cases}
\frac{k}{\lambda}\left(\frac{x}{\lambda}\right)^{k-1}e^{-(x/\lambda)^{k}} & x\geq0 ,\\
0 & x<0,
\end{cases}
\end{equation}
where $k > 0$ and defines the shape parameter and $\lambda > 0$ and defines the scale parameter.

The cumulative distribution function (CDF) is defined as
\begin{equation}
F(x;k,\lambda) =
\begin{cases}
1- e^{-(x/\lambda)^k}\ & x\geq0, \\
0 & x<0.
\end{cases}
\end{equation}

The quantile function is defined as
\begin{equation}
Q(p;k,\lambda) = \lambda {(-\ln(1-p))}^{1/k} \quad 0 \leq p < 1.
\end{equation}

## Example Input Syntax

!listing modules/stochastic_tools/test/tests/distributions/boost_weibull.i block=Distributions

!syntax parameters /Distributions/BoostWeibullDistribution

!syntax inputs /Distributions/BoostWeibullDistribution

!syntax children /Distributions/BoostWeibullDistribution
@@ -1,10 +1,5 @@
# NormalDistribution

!alert warning
The NormalDistribution object requires that libMesh be configured to utilize an external
[Boost](www.boost.org) library. This may be done by using the `--with-boost` configuration option
when compiling libMesh.

## Description

The normal (or Gaussian) distribution object defines a
@@ -18,6 +13,8 @@ f(x \; | \; \mu, \sigma^2) = \frac{1}{\sqrt{2\pi\sigma^2} } \; e^{ -\frac{(x-\mu
\end{equation}
where $\mu$ is the mean and $\sigma$ is the standard deviation ($\sigma > 0$) of the distribution.

This implementation of a normal distribution uses a numerical approximation described in [cite:Kennedy1980].

## Example Input Syntax

The following input file defines a normal distribution with a mean of 0 and a standard deviation of 1.
@@ -29,3 +26,5 @@ The following input file defines a normal distribution with a mean of 0 and a st
!syntax inputs /Distributions/NormalDistribution

!syntax children /Distributions/NormalDistribution

!bibtex bibliography
@@ -0,0 +1,32 @@
# TruncatedNormalDistribution

## Description

The truncated normal (or Gaussian) distribution object defines a
[normal distribution](https://en.wikipedia.org/wiki/Normal_distribution) function with the provided
`mean`, `standard_deviation` and truncation range (`lower_bound` and `upper_bound`) parameters. The probability density function (PDF) of the truncated normal
distribution is given by the [eq:truncated_normal].

\begin{equation}
\label{eq:truncated_normal}
\psi(x \; | \; \mu, \sigma^2, a, b) = \begin{cases}
\frac{\phi((x \; | \; \mu, \sigma^2)}{\Phi(x\;|\;\mu,\sigma^2,b)-\Phi(x\;|\;\mu,\sigma^2,a)},& \text{if } a<x<b\\
0, & \text{otherwise}
\end{cases}
\end{equation}

The parameters $\mu$ and $\sigma$ are the mean and standard deviation of the general normal PDF. The $\phi((x \; | \; \mu, \sigma^2)$ and $\Phi((x \; | \; \mu, \sigma^2)$ are the general normal PDF and cumulative distribution function (CDF).

## Example Input Syntax

The following input file defines a normal distribution with a mean of 0 and a standard deviation of 1 and truncation range (-10,10).

!listing modules/stochastic_tools/test/tests/distributions/truncated_normal.i block=Distributions

!syntax parameters /Distributions/TruncatedNormalDistribution

!syntax inputs /Distributions/TruncatedNormalDistribution

!syntax children /Distributions/TruncatedNormalDistribution

!bibtex bibliography
@@ -1,37 +1,18 @@
# WeibullDistribution

!alert warning
The WeibullDistribution object requires that libMesh be configured to utilize an external
[Boost](www.boost.org) library. This may be done using the `--with-boost` configuration option
when compiling libMesh.

## Description

As the name suggests, the WeibullDistribution object defines a Weibull distribution which
The WeibullDistribution object defines a translated Weibull distribution which
has a probability density function (PDF) defined as

\begin{equation}
f(x;\lambda,k) =
f(x;\lambda,k,\theta) =
\begin{cases}
\frac{k}{\lambda}\left(\frac{x}{\lambda}\right)^{k-1}e^{-(x/\lambda)^{k}} & x\geq0 ,\\
\frac{k}{\lambda}\left(\frac{x-\theta}{\lambda}\right)^{k-1}e^{-(\frac{x-\theta}{\lambda})^{k}} & x\geq0 ,\\
0 & x<0,
\end{cases}
\end{equation}
where $k > 0$ and defines the shape parameter and $\lambda > 0$ and defines the scale parameter.

The cumulative distribution function (CDF) is defined as
\begin{equation}
F(x;k,\lambda) =
\begin{cases}
1- e^{-(x/\lambda)^k}\ & x\geq0, \\
0 & x<0.
\end{cases}
\end{equation}

The quantile function is defined as
\begin{equation}
Q(p;k,\lambda) = \lambda {(-\ln(1-p))}^{1/k} \quad 0 \leq p < 1.
\end{equation}
where $k > 0$ and defines the shape parameter, $\lambda > 0$ and defines the scale parameter and $\theta$ is the location parameter of the distribution.

## Example Input Syntax

@@ -7,23 +7,24 @@
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#ifndef LOGNORMALDISTRIBUTION_H
#define LOGNORMALDISTRIBUTION_H
#ifndef BOOSTLOGNORMALDISTRIBUTION_H
#define BOOSTLOGNORMALDISTRIBUTION_H

#include "BoostDistribution.h"

class LognormalDistribution;
class BoostLognormalDistribution;

template <>
InputParameters validParams<LognormalDistribution>();
InputParameters validParams<BoostLognormalDistribution>();

/**
* A class used to generate Lognormal distribution via Boost
*/
class LognormalDistribution : public BoostDistribution<boost::math::lognormal_distribution<Real>>
class BoostLognormalDistribution
: public BoostDistribution<boost::math::lognormal_distribution<Real>>
{
public:
LognormalDistribution(const InputParameters & parameters);
BoostLognormalDistribution(const InputParameters & parameters);
};

#endif // LOGNORMALDISTRIBUTION_H
#endif // BOOSTLOGNORMALDISTRIBUTION_H
@@ -0,0 +1,29 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#ifndef BOOSTNORMALDISTRIBUTION_H
#define BOOSTNORMALDISTRIBUTION_H

#include "BoostDistribution.h"

class BoostNormalDistribution;

template <>
InputParameters validParams<BoostNormalDistribution>();

/**
* A class used to generate Normal distribution via Boost
*/
class BoostNormalDistribution : public BoostDistribution<boost::math::normal_distribution<Real>>
{
public:
BoostNormalDistribution(const InputParameters & parameters);
};

#endif // BOOSTNORMALDISTRIBUTION_H
@@ -0,0 +1,29 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#ifndef BOOSTWEIBULLDISTRIBUTION_H
#define BOOSTWEIBULLDISTRIBUTION_H

#include "BoostDistribution.h"

class BoostWeibullDistribution;

template <>
InputParameters validParams<BoostWeibullDistribution>();

/**
* A class used to generate Weibull distribution via Boost
*/
class BoostWeibullDistribution : public BoostDistribution<boost::math::weibull_distribution<Real>>
{
public:
BoostWeibullDistribution(const InputParameters & parameters);
};

#endif // BOOSTWEIBULLDISTRIBUTION_H
@@ -10,20 +10,40 @@
#ifndef NORMALDISTRIBUTION_H
#define NORMALDISTRIBUTION_H

#include "BoostDistribution.h"
#include "Distribution.h"

class NormalDistribution;

template <>
InputParameters validParams<NormalDistribution>();

/**
* A class used to generate Normal distribution via Boost
* A class used to generate a normal distribution
*/
class NormalDistribution : public BoostDistribution<boost::math::normal_distribution<Real>>
class NormalDistribution : public Distribution
{
public:
NormalDistribution(const InputParameters & parameters);

virtual Real pdf(const Real & x) override;
virtual Real cdf(const Real & x) override;

/**
* Compute the quantile
* @param p The cdf for which the quantile is evaluated
**/
virtual Real quantile(const Real & p) override;

protected:
/// Coefficients for the rational function used to approximate the quantile:
const std::vector<Real> _a;
const std::vector<Real> _b;

/// The mean (or expectation) of the distribution (mu)
Real _mean;

/// The standard deviation of the distribution (sigma)
Real _standard_deviation;
};

#endif // NORMALDISTRIBUTION_H
#endif /* NORMALDISTRIBUTION_H */
@@ -0,0 +1,40 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#ifndef TRUNCATEDNORMALDISTRIBUTION_H
#define TRUNCATEDNORMALDISTRIBUTION_H

#include "NormalDistribution.h"

class TruncatedNormalDistribution;

template <>
InputParameters validParams<TruncatedNormalDistribution>();

/**
* A class used to generate a truncated normal distribution
*/
class TruncatedNormalDistribution : public NormalDistribution
{
public:
TruncatedNormalDistribution(const InputParameters & parameters);

virtual Real pdf(const Real & x) override;
virtual Real cdf(const Real & x) override;
virtual Real quantile(const Real & p) override;

protected:
/// The lower bound for the distribution
const Real & _lower_bound;

/// The upper bound for the distribution
const Real & _upper_bound;
};

#endif /* TRUNCATEDNORMALDISTRIBUTION_H */
Oops, something went wrong.

0 comments on commit fa9a510

Please sign in to comment.