Permalink
Browse files

Merge pull request #12746 from aeslaughter/distributions-12720

Improve DistributionInterface
  • Loading branch information...
aeslaughter committed Jan 23, 2019
2 parents a86c5ed + 5b00c95 commit 29442b0c0fb451ead398396cec168d67b754c4c4
Showing with 981 additions and 122 deletions.
  1. +4 −4 framework/include/distributions/Distribution.h
  2. +54 −2 framework/include/distributions/DistributionInterface.h
  3. +1 −1 framework/include/ics/RandomIC.h
  4. +0 −6 framework/include/outputs/Output.h
  5. +1 −1 framework/include/samplers/Sampler.h
  6. +1 −1 framework/src/distributions/Distribution.C
  7. +6 −5 framework/src/distributions/DistributionInterface.C
  8. +0 −12 framework/src/outputs/Output.C
  9. +10 −0 modules/stochastic_tools/doc/content/bib/stochastic_tools.bib
  10. +31 −0 modules/stochastic_tools/doc/content/source/distributions/JohnsonSBDistribution.md
  11. +30 −0 modules/stochastic_tools/doc/content/source/distributions/LogisticDistribution.md
  12. +8 −8 modules/stochastic_tools/include/distributions/BoostDistribution.h
  13. +62 −0 modules/stochastic_tools/include/distributions/JohnsonSBDistribution.h
  14. +44 −0 modules/stochastic_tools/include/distributions/LogisticDistribution.h
  15. +17 −13 modules/stochastic_tools/include/distributions/NormalDistribution.h
  16. +19 −3 modules/stochastic_tools/include/distributions/TruncatedNormalDistribution.h
  17. +7 −3 modules/stochastic_tools/include/distributions/UniformDistribution.h
  18. +8 −3 modules/stochastic_tools/include/distributions/WeibullDistribution.h
  19. +107 −0 modules/stochastic_tools/src/distributions/JohnsonSBDistribution.C
  20. +68 −0 modules/stochastic_tools/src/distributions/LogisticDistribution.C
  21. +25 −18 modules/stochastic_tools/src/distributions/NormalDistribution.C
  22. +48 −12 modules/stochastic_tools/src/distributions/TruncatedNormalDistribution.C
  23. +29 −9 modules/stochastic_tools/src/distributions/UniformDistribution.C
  24. +37 −10 modules/stochastic_tools/src/distributions/WeibullDistribution.C
  25. +51 −0 modules/stochastic_tools/test/include/utils/TestDistributionDirectPostprocessor.h
  26. +1 −1 modules/stochastic_tools/test/include/utils/TestDistributionPostprocessor.h
  27. +52 −0 modules/stochastic_tools/test/src/utils/TestDistributionDirectPostprocessor.C
  28. +3 −0 modules/stochastic_tools/test/tests/distributions/gold/johnsonsb_out.csv
  29. +3 −0 modules/stochastic_tools/test/tests/distributions/gold/logistic_out.csv
  30. +1 −0 modules/stochastic_tools/test/tests/distributions/gold/normal_direct_out.csv
  31. +59 −0 modules/stochastic_tools/test/tests/distributions/johnsonsb.i
  32. +57 −0 modules/stochastic_tools/test/tests/distributions/logistic.i
  33. +57 −0 modules/stochastic_tools/test/tests/distributions/normal_direct.i
  34. +43 −0 modules/stochastic_tools/test/tests/distributions/normal_direct_type_error.i
  35. +37 −10 modules/stochastic_tools/test/tests/distributions/tests
@@ -27,22 +27,22 @@ class Distribution : public MooseObject
/**
* Compute the probability with given probability distribution function (PDF) at x
*/
virtual Real pdf(const Real & x) = 0;
virtual Real pdf(const Real & x) const = 0;

/**
* Compute the cumulative probability with given cumulative probability distribution (CDF) at x
*/
virtual Real cdf(const Real & x) = 0;
virtual Real cdf(const Real & x) const = 0;

/**
* Compute the inverse CDF (quantile function) value for given variable value y
*/
virtual Real quantile(const Real & y) = 0;
virtual Real quantile(const Real & y) const = 0;

/**
* Compute the median of the distribution
*/
virtual Real median();
virtual Real median() const;
};

#endif /* DISTRIBUTION_H */
@@ -38,26 +38,78 @@ class DistributionInterface
*/
DistributionInterface(const MooseObject * moose_object);

///@{
/**
* Get a distribution with a given name
* @param name The name of the parameter key of the distribution to retrieve
* @return The distribution with name associated with the parameter 'name'
*/
Distribution & getDistribution(const std::string & name);
const Distribution & getDistribution(const std::string & name) const;

template <typename T>
const T & getDistribution(const std::string & name) const;
///@}

///@{
/**
* Get a distribution with a given name
* @param name The name of the distribution to retrieve
* @return The distribution with name 'name'
*/
Distribution & getDistributionByName(const DistributionName & name);
const Distribution & getDistributionByName(const DistributionName & name) const;

template <typename T>
const T & getDistributionByName(const std::string & name) const;
///@}

private:
/// Parameters of the object with this interface
const InputParameters & _dni_params;

/// Reference to FEProblemBase instance
FEProblemBase & _dni_feproblem;

/// Pointer to the MooseObject
const MooseObject * _dni_moose_object_ptr;
};

template <typename T>
const T &
DistributionInterface::getDistribution(const std::string & name) const
{
try
{
const T & dist = dynamic_cast<const T &>(getDistribution(name));
return dist;
}
catch (std::bad_cast & exception)
{
DistributionName dist_name = _dni_params.get<DistributionName>(name);
mooseError("The '",
_dni_moose_object_ptr->name(),
"' object failed to retrieve '",
dist_name,
"' distribution with the desired type.");
}
}

template <typename T>
const T &
DistributionInterface::getDistributionByName(const std::string & name) const
{
try
{
const T & dist = dynamic_cast<const T &>(getDistribution(name));
return dist;
}
catch (std::bad_cast & exception)
{
mooseError("The '",
_dni_moose_object_ptr->name(),
"' object failed to retrieve '",
name,
"' distribution with the desired type.");
}
}

#endif /* DISTRIBUTIONINTERFACE_H */
@@ -50,7 +50,7 @@ class RandomIC : public RandomICBase, public DistributionInterface
const Real _max;

/// Distribution object optionally used to define distribution of random numbers
Distribution * _distribution;
Distribution const * _distribution;
};

#endif // RANDOMIC_H
@@ -110,12 +110,6 @@ class Output : public MooseObject,
*/
virtual const OutputOnWarehouse & advancedExecuteOn() const;

/**
* (DEPRECATED) Return the support output execution times
* @param default_type The default MultiMooseEnum option
*/
static MultiMooseEnum getExecuteOptions(std::string default_type = "");

/**
* Return an ExecFlagEnum object with the available execution flags for Output objects.
*/
@@ -154,7 +154,7 @@ class Sampler : public MooseObject, public SetupInterface, public DistributionIn
void reinit(const std::vector<DenseMatrix<Real>> & data);

/// Map used to store the perturbed parameters and their corresponding distributions
std::vector<Distribution *> _distributions;
std::vector<Distribution const *> _distributions;

/// Distribution names
const std::vector<DistributionName> & _distribution_names;
@@ -23,7 +23,7 @@ validParams<Distribution>()
Distribution::Distribution(const InputParameters & parameters) : MooseObject(parameters) {}

Real
Distribution::median()
Distribution::median() const
{
mooseError("The distribution '", name(), "' must override the median method.");
return 0;
@@ -21,19 +21,20 @@ validParams<DistributionInterface>()

DistributionInterface::DistributionInterface(const MooseObject * moose_object)
: _dni_params(moose_object->parameters()),
_dni_feproblem(*_dni_params.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"))
_dni_feproblem(*_dni_params.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
_dni_moose_object_ptr(moose_object)
{
}

Distribution &
DistributionInterface::getDistribution(const std::string & name)
const Distribution &
DistributionInterface::getDistribution(const std::string & name) const
{
DistributionName dist_name = _dni_params.get<DistributionName>(name);
return _dni_feproblem.getDistribution(dist_name);
}

Distribution &
DistributionInterface::getDistributionByName(const DistributionName & name)
const Distribution &
DistributionInterface::getDistributionByName(const DistributionName & name) const
{
return _dni_feproblem.getDistribution(name);
}
@@ -73,18 +73,6 @@ validParams<Output>()
return params;
}

MultiMooseEnum
Output::getExecuteOptions(std::string default_type)
{
// TODO: ExecFlagType
::mooseDeprecated("This version 'getExecuteOptions' was replaced by the "
"Output::getDefaultExecFlagEnum() static function.");
ExecFlagEnum exec_enum = MooseUtils::getDefaultExecFlagEnum();
exec_enum.addAvailableFlags(EXEC_FAILED);
exec_enum = default_type;
return exec_enum;
}

ExecFlagEnum
Output::getDefaultExecFlagEnum()
{
@@ -16,3 +16,13 @@ @book{Kennedy1980
year = {1980},
publisher = {Marcel Dekker}
}


@book{johnson1994continuous,
title = {Continuous Univariate Distributions},
author = {Johnson, N. L. and Kotz, S. and Balakrishnan, N.},
year = {1994},
publisher = {Wiley},
volume = {1},
chapter = {12}
}
@@ -0,0 +1,31 @@
# JohnsonSBDistribution

## Description

The Johnson Special Bounded (SB) distribution [cite:johnson1994continuous]
is related to the normal distribution. Four parameters
are needed: $\gamma$, $\delta$, $\lambda$, and $\epsilon$. It is a continuous distribution defined on
bounded range $\epsilon \leq x \leq \epsilon + \lambda$, and the distribution can be symmetric or
asymmetric.

Probability Density Function:

\begin{equation}
f(x) = \tfrac{\delta}{\lambda\sqrt{2\pi} z(1-z)} exp(-\tfrac{1}{2}(\gamma + \delta ln(\tfrac{z}{1-z}))^2),\,\textrm{where}\, z \equiv \tfrac{x-\zeta}{\lambda}
\end{equation}

Cumulative Density Function:

\begin{equation}
F(x) = \Phi(\gamma + \delta ln \tfrac{z}{1-z}),\,\textrm{where}\, z = \tfrac{x-\epsilon}{\lambda}
\end{equation}

!syntax description /Distributions/JohnsonSBDistribution

!syntax parameters /Distributions/JohnsonSBDistribution

!syntax inputs /Distributions/JohnsonSBDistribution

!syntax children /Distributions/JohnsonSBDistribution

!bibtex bibliography
@@ -0,0 +1,30 @@
# LogisticDistribution

## Description

The logistic distribution is a continuous distribution defined with a location ($\alpha$) and
shape ($\beta$) parameters.

Probability Density Function:

\begin{equation}
z(x) = \exp{-\frac{(x - \alpha)}{\beta}}
f(x) = \frac{z(x)}{(\alpha * (1.0 + z)^2)}
\end{equation}

Cumulative Density Function:

\begin{equation}
F(x) = \frac{1}{1+z(x)}
\end{equation}


!syntax description /Distributions/LogisticDistribution

!syntax parameters /Distributions/LogisticDistribution

!syntax inputs /Distributions/LogisticDistribution

!syntax children /Distributions/LogisticDistribution

!bibtex bibliography
@@ -50,10 +50,10 @@ class BoostDistribution : public Distribution
public:
BoostDistribution(const InputParameters & parameters);

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

protected:
/// This must be defined by the child class in the constructor
@@ -76,7 +76,7 @@ BoostDistribution<T>::BoostDistribution(const InputParameters & parameters)

template <typename T>
Real
BoostDistribution<T>::pdf(const Real & x)
BoostDistribution<T>::pdf(const Real & x) const
{
#ifdef LIBMESH_HAVE_EXTERNAL_BOOST
mooseAssert(_distribution_unique_ptr, "Boost distribution pointer not defined.");
@@ -88,7 +88,7 @@ BoostDistribution<T>::pdf(const Real & x)

template <typename T>
Real
BoostDistribution<T>::cdf(const Real & x)
BoostDistribution<T>::cdf(const Real & x) const
{
#ifdef LIBMESH_HAVE_EXTERNAL_BOOST
mooseAssert(_distribution_unique_ptr, "Boost distribution pointer not defined.");
@@ -100,7 +100,7 @@ BoostDistribution<T>::cdf(const Real & x)

template <typename T>
Real
BoostDistribution<T>::quantile(const Real & y)
BoostDistribution<T>::quantile(const Real & y) const
{
#ifdef LIBMESH_HAVE_EXTERNAL_BOOST
mooseAssert(_distribution_unique_ptr, "Boost distribution pointer not defined.");
@@ -112,7 +112,7 @@ BoostDistribution<T>::quantile(const Real & y)

template <typename T>
Real
BoostDistribution<T>::median()
BoostDistribution<T>::median() const
{
#ifdef LIBMESH_HAVE_EXTERNAL_BOOST
mooseAssert(_distribution_unique_ptr, "Boost distribution pointer not defined.");
@@ -0,0 +1,62 @@
//* 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 JOHNSONSBDISTRIBUTION_H
#define JOHNSONSBDISTRIBUTION_H

#include "NormalDistribution.h"

class JohnsonSBDistribution;

template <>
InputParameters validParams<JohnsonSBDistribution>();

/**
* A class used to generate a Johnson SB distribution
*/
class JohnsonSBDistribution : public NormalDistribution
{
public:
JohnsonSBDistribution(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;

Real pdf(const Real & x,
const Real & a,
const Real & b,
const Real & alpha_1,
const Real & alpha_2) const;
Real cdf(const Real & x,
const Real & a,
const Real & b,
const Real & alpha_1,
const Real & alpha_2) const;
Real quantile(const Real & p,
const Real & a,
const Real & b,
const Real & alpha_1,
const Real & alpha_2) const;

protected:
/// The lower location parameter, a
const Real & _lower;

/// The upper location parameter, b
const Real & _upper;

/// The first shape parameter, alpha_1
const Real & _alpha_1;

/// The second shape parameter, alpha_2
const Real & _alpha_2;
};

#endif
Oops, something went wrong.

0 comments on commit 29442b0

Please sign in to comment.