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

A class used to generate a KernelDensity1D distribution. More...

#include <KernelDensity1D.h>

Inheritance diagram for KernelDensity1D:
[legend]

Public Types

typedef DataFileName DataFileParameterType
 

Public Member Functions

 KernelDensity1D (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 &bandwidth, const std::vector< Real > &data, const MooseEnum &kernel_function)
 
static Real cdf (const Real &x, const Real &bandwidth, const std::vector< Real > &data, const MooseEnum &kernel_function)
 
static Real quantile (const Real &p, const Real &bandwidth, const std::vector< Real > &data, const MooseEnum &kernel_function)
 

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 MooseEnum_bandwidth_rule
 bandwidth_rule helps the user select between the different ways to define the bandwith More...
 
const MooseEnum_kernel_function
 kernel_function helps the user select between the different kernel functions that are available More...
 
Real _bandwidth
 The bandwith parameter which controls the smoothness of the distribution. More...
 
std::vector< Real_data
 data helps get the vector data for building the kernel density 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
 

Detailed Description

A class used to generate a KernelDensity1D distribution.

Definition at line 17 of file KernelDensity1D.h.

Constructor & Destructor Documentation

◆ KernelDensity1D()

KernelDensity1D::KernelDensity1D ( const InputParameters parameters)

Definition at line 45 of file KernelDensity1D.C.

47  _bandwidth_rule(getParam<MooseEnum>("bandwidth_rule")),
48  _kernel_function(getParam<MooseEnum>("kernel_function")),
49  _bandwidth(getParam<Real>("bandwidth"))
50 {
51  if (isParamValid("data") && isParamValid("file_name"))
52  paramError("data", "data and file_name both cannot be set at the same time.");
53  else if (isParamValid("file_name"))
54  {
55  MooseUtils::DelimitedFileReader reader(getParam<FileName>("file_name"));
56  reader.read();
57  if (isParamValid("file_column_name"))
58  _data = reader.getData(getParam<std::string>("file_column_name"));
59  else
60  _data = reader.getData(0);
61  }
62  else if (isParamValid("data"))
63  _data = getParam<std::vector<Real>>("data");
64  else
65  mooseError("Either 'data' or 'file_name' parameters must be specified to represent input data");
66  Real mu = 0;
67  Real sd = 0;
68  for (unsigned i = 0; i < _data.size(); ++i)
69  {
70  mu += _data[i] / _data.size();
71  }
72  for (unsigned i = 0; i < _data.size(); ++i)
73  {
74  sd += Utility::pow<2>((_data[i] - mu)) / _data.size();
75  }
76  sd = std::pow(sd, 0.5);
77  if (_bandwidth_rule == "silverman")
78  {
79  _bandwidth = 1.06 * sd * std::pow(_data.size(), -0.2);
80  }
81  else if (_bandwidth_rule == "standarddeviation")
82  {
83  _bandwidth = sd;
84  }
85 }
Distribution(const InputParameters &parameters)
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 ...
static const std::string mu
Definition: NS.h:123
void paramError(const std::string &param, Args... args) const
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
void mooseError(Args &&... args) const
const InputParameters & parameters() const
Real _bandwidth
The bandwith parameter which controls the smoothness of the distribution.
MooseUnits pow(const MooseUnits &, int)
std::vector< Real > _data
data helps get the vector data for building the kernel density

Member Function Documentation

◆ cdf() [1/2]

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

Implements Distribution.

Definition at line 168 of file KernelDensity1D.C.

169 {
171 }
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
const std::vector< double > x
Real _bandwidth
The bandwith parameter which controls the smoothness of the distribution.
std::vector< Real > _data
data helps get the vector data for building the kernel density

◆ cdf() [2/2]

Real KernelDensity1D::cdf ( const Real x,
const Real bandwidth,
const std::vector< Real > &  data,
const MooseEnum kernel_function 
)
static

Definition at line 114 of file KernelDensity1D.C.

118 {
119  Real value = 0;
120  if (kernel_function == "gaussian")
121  {
122  for (unsigned i = 0; i < data.size(); ++i)
123  {
124  value += 1.0 / (data.size()) * Normal::cdf(x, data[i], bandwidth);
125  }
126  }
127  else if (kernel_function == "uniform")
128  {
129  for (unsigned i = 0; i < data.size(); ++i)
130  {
131  value += 1.0 / (data.size()) * Uniform::cdf((x - data[i]) / bandwidth, -1.0, 1.0);
132  }
133  }
134  else
135  ::mooseError("Invalid kernel function type ", std::string(kernel_function));
136  return value;
137 }
virtual Real cdf(const Real &x) const override
Definition: Normal.C:74
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
const std::vector< double > x
static Real cdf(const Real &x, const Real &lower_bound, const Real &upper_bound)
Definition: Uniform.C:43
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ pdf() [1/2]

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

Implements Distribution.

Definition at line 162 of file KernelDensity1D.C.

163 {
165 }
virtual Real pdf(const Real &x) const override
const MooseEnum & _kernel_function
kernel_function helps the user select between the different kernel functions that are available ...
const std::vector< double > x
Real _bandwidth
The bandwith parameter which controls the smoothness of the distribution.
std::vector< Real > _data
data helps get the vector data for building the kernel density

◆ pdf() [2/2]

Real KernelDensity1D::pdf ( const Real x,
const Real bandwidth,
const std::vector< Real > &  data,
const MooseEnum kernel_function 
)
static

Definition at line 88 of file KernelDensity1D.C.

92 {
93  Real value = 0;
94  if (kernel_function == "gaussian")
95  {
96  for (unsigned i = 0; i < data.size(); ++i)
97  {
98  value += 1 / (data.size() * bandwidth) * Normal::pdf(((x - data[i]) / bandwidth), 0.0, 1.0);
99  }
100  }
101  else if (kernel_function == "uniform")
102  {
103  for (unsigned i = 0; i < data.size(); ++i)
104  {
105  value += 1 / (data.size() * bandwidth) * Uniform::pdf(((x - data[i]) / bandwidth), -1.0, 1.0);
106  }
107  }
108  else
109  ::mooseError("Invalid kernel function type ", std::string(kernel_function));
110  return value;
111 }
static Real pdf(const Real &x, const Real &lower_bound, const Real &upper_bound)
Definition: Uniform.C:34
virtual Real pdf(const Real &x) const override
Definition: Normal.C:68
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
const std::vector< double > x
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ quantile() [1/2]

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

Implements Distribution.

Definition at line 174 of file KernelDensity1D.C.

175 {
177 }
const MooseEnum & _kernel_function
kernel_function helps the user select between the different kernel functions that are available ...
virtual Real quantile(const Real &p) const override
Real _bandwidth
The bandwith parameter which controls the smoothness of the distribution.
std::vector< Real > _data
data helps get the vector data for building the kernel density

◆ quantile() [2/2]

Real KernelDensity1D::quantile ( const Real p,
const Real bandwidth,
const std::vector< Real > &  data,
const MooseEnum kernel_function 
)
static

Definition at line 140 of file KernelDensity1D.C.

144 {
145  Real value = 0;
146  if (kernel_function == "gaussian")
147  {
148  int index = std::round(p * (data.size() - 1));
149  value = (Normal::quantile(p, data[index], bandwidth));
150  }
151  else if (kernel_function == "uniform")
152  {
153  int index = std::round(p * (data.size() - 1));
154  value = (Uniform::quantile(p, -1.0, 1.0) * bandwidth + data[index]);
155  }
156  else
157  ::mooseError("Invalid kernel function type ", std::string(kernel_function));
158  return value;
159 }
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
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
virtual Real quantile(const Real &p) const override
Definition: Normal.C:80

◆ validParams()

InputParameters KernelDensity1D::validParams ( )
static

Definition at line 22 of file KernelDensity1D.C.

23 {
25  MooseEnum bandwidth_rule("silverman standarddeviation userdefined");
26  MooseEnum kernel_function("gaussian uniform");
27  params.addClassDescription("KernelDensity1D distribution");
29  "bandwidth_rule", bandwidth_rule, "Bandwidth rule for evaluating the bandwith.");
31  "kernel_function",
32  kernel_function,
33  "Kernel function determines the shape of the underlying kernel for the kernel density.");
34  params.addRangeCheckedParam<Real>("bandwidth",
35  1.0,
36  "bandwidth > 0",
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.");
40  params.addParam<std::string>(
41  "file_column_name", "Name of column in csv file to use, by default first column is used.");
42  return params;
43 }
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static InputParameters validParams()
void addClassDescription(const std::string &doc_string)
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)

Member Data Documentation

◆ _bandwidth

Real KernelDensity1D::_bandwidth
protected

The bandwith parameter which controls the smoothness of the distribution.

Definition at line 49 of file KernelDensity1D.h.

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

◆ _bandwidth_rule

const MooseEnum& KernelDensity1D::_bandwidth_rule
protected

bandwidth_rule helps the user select between the different ways to define the bandwith

Definition at line 43 of file KernelDensity1D.h.

Referenced by KernelDensity1D().

◆ _data

std::vector<Real> KernelDensity1D::_data
protected

data helps get the vector data for building the kernel density

Definition at line 52 of file KernelDensity1D.h.

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

◆ _kernel_function

const MooseEnum& KernelDensity1D::_kernel_function
protected

kernel_function helps the user select between the different kernel functions that are available

Definition at line 46 of file KernelDensity1D.h.

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


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