https://mooseframework.inl.gov
Uniform.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 "Uniform.h"
11 
12 registerMooseObject("StochasticToolsApp", Uniform);
13 
16 {
18  params.addClassDescription("Continuous uniform distribution.");
19  params.addParam<Real>("lower_bound", 0.0, "Distribution lower bound");
20  params.addParam<Real>("upper_bound", 1.0, "Distribution upper bound");
21  return params;
22 }
23 
24 Uniform::Uniform(const InputParameters & parameters)
25  : Distribution(parameters),
26  _lower_bound(getParam<Real>("lower_bound")),
27  _upper_bound(getParam<Real>("upper_bound"))
28 {
30  mooseError("The lower bound is larger than the upper bound!");
31 }
32 
33 Real
34 Uniform::pdf(const Real & x, const Real & lower_bound, const Real & upper_bound)
35 {
36  if (x < lower_bound || x > upper_bound)
37  return 0.0;
38  else
39  return 1.0 / (upper_bound - lower_bound);
40 }
41 
42 Real
43 Uniform::cdf(const Real & x, const Real & lower_bound, const Real & upper_bound)
44 {
45  if (x < lower_bound)
46  return 0.0;
47  else if (x > upper_bound)
48  return 1.0;
49  else
50  return (x - lower_bound) / (upper_bound - lower_bound);
51 }
52 
53 Real
54 Uniform::quantile(const Real & y, const Real & lower_bound, const Real & upper_bound)
55 {
56  if (y < 0 || y > 1)
57  ::mooseError("The cdf_value provided is out of range 0 to 1.");
58  else
59  return y * (upper_bound - lower_bound) + lower_bound;
60 }
61 
62 Real
63 Uniform::pdf(const Real & x) const
64 {
65  return pdf(x, _lower_bound, _upper_bound);
66 }
67 
68 Real
69 Uniform::cdf(const Real & x) const
70 {
71  return cdf(x, _lower_bound, _upper_bound);
72 }
73 
74 Real
75 Uniform::quantile(const Real & y) const
76 {
78 }
static Real pdf(const Real &x, const Real &lower_bound, const Real &upper_bound)
Definition: Uniform.C:34
static InputParameters validParams()
Definition: Uniform.C:15
A class used to generate uniform distribution.
Definition: Uniform.h:17
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const std::vector< double > y
const std::vector< double > x
registerMooseObject("StochasticToolsApp", Uniform)
static Real cdf(const Real &x, const Real &lower_bound, const Real &upper_bound)
Definition: Uniform.C:43
Uniform(const InputParameters &parameters)
Definition: Uniform.C:24
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static Real quantile(const Real &y, const Real &lower_bound, const Real &upper_bound)
Definition: Uniform.C:54
static InputParameters validParams()
const Real & _lower_bound
The lower bound for the uniform distribution.
Definition: Uniform.h:34
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
const Real & _upper_bound
The upper bound for the uniform distribution.
Definition: Uniform.h:37