12 #include "libmesh/utility.h" 25 MooseEnum bandwidth_rule(
"silverman standarddeviation userdefined");
26 MooseEnum kernel_function(
"gaussian uniform");
29 "bandwidth_rule", bandwidth_rule,
"Bandwidth rule for evaluating the bandwith.");
33 "Kernel function determines the shape of the underlying kernel for the kernel density.");
37 "Bandwidth controls the smoothness of the kernel density.");
38 params.
addParam<std::vector<Real>>(
"data",
"The data vector.");
39 params.
addParam<FileName>(
"file_name",
"Name of the CSV file.");
41 "file_column_name",
"Name of column in csv file to use, by default first column is used.");
47 _bandwidth_rule(getParam<
MooseEnum>(
"bandwidth_rule")),
48 _kernel_function(getParam<
MooseEnum>(
"kernel_function")),
49 _bandwidth(getParam<
Real>(
"bandwidth"))
52 paramError(
"data",
"data and file_name both cannot be set at the same time.");
58 _data = reader.
getData(getParam<std::string>(
"file_column_name"));
63 _data = getParam<std::vector<Real>>(
"data");
65 mooseError(
"Either 'data' or 'file_name' parameters must be specified to represent input data");
68 for (
unsigned i = 0; i <
_data.size(); ++i)
72 for (
unsigned i = 0; i <
_data.size(); ++i)
89 const Real & bandwidth,
90 const std::vector<Real> & data,
94 if (kernel_function ==
"gaussian")
96 for (
unsigned i = 0; i < data.size(); ++i)
98 value += 1 / (data.size() * bandwidth) *
Normal::pdf(((
x - data[i]) / bandwidth), 0.0, 1.0);
101 else if (kernel_function ==
"uniform")
103 for (
unsigned i = 0; i < data.size(); ++i)
105 value += 1 / (data.size() * bandwidth) *
Uniform::pdf(((
x - data[i]) / bandwidth), -1.0, 1.0);
109 ::mooseError(
"Invalid kernel function type ", std::string(kernel_function));
115 const Real & bandwidth,
116 const std::vector<Real> & data,
120 if (kernel_function ==
"gaussian")
122 for (
unsigned i = 0; i < data.size(); ++i)
127 else if (kernel_function ==
"uniform")
129 for (
unsigned i = 0; i < data.size(); ++i)
135 ::mooseError(
"Invalid kernel function type ", std::string(kernel_function));
141 const Real & bandwidth,
142 const std::vector<Real> & data,
146 if (kernel_function ==
"gaussian")
148 int index = std::round(p * (data.size() - 1));
151 else if (kernel_function ==
"uniform")
153 int index = std::round(p * (data.size() - 1));
157 ::mooseError(
"Invalid kernel function type ", std::string(kernel_function));
virtual Real cdf(const Real &x) const override
virtual Real pdf(const Real &x) const override
KernelDensity1D(const InputParameters ¶meters)
virtual Real pdf(const Real &x) const override
bool isParamValid(const std::string &name) const
const MooseEnum & _kernel_function
kernel_function helps the user select between the different kernel functions that are available ...
virtual Real cdf(const Real &x) const override
virtual Real quantile(const Real &p) const override
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
const std::vector< double > x
static const std::string mu
A class used to generate a KernelDensity1D distribution.
void paramError(const std::string ¶m, Args... args) const
const std::vector< std::vector< T > > & getData() const
static InputParameters validParams()
const MooseEnum & _bandwidth_rule
bandwidth_rule helps the user select between the different ways to define the bandwith ...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static InputParameters validParams()
void mooseError(Args &&... args) const
Real _bandwidth
The bandwith parameter which controls the smoothness of the distribution.
virtual Real quantile(const Real &p) const override
MooseUnits pow(const MooseUnits &, int)
registerMooseObject("StochasticToolsApp", KernelDensity1D)
std::vector< Real > _data
data helps get the vector data for building the kernel density