https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Private Member Functions | Private 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
 
bool isKokkosObject () const
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
const std::string & name () const
 
std::string typeAndName () const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
MooseObjectName uniqueName () const
 
const InputParametersparameters () const
 
const hit::Node * getHitNode () const
 
bool hasBase () const
 
const std::string & getBase () const
 
const TgetParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const TqueryParam (const std::string &name) const
 
const TgetRenamedParam (const std::string &old_name, const std::string &new_name) const
 
T getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &name) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (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
 
std::string messagePrefix (const bool hit_prefix=true) const
 
std::string errorPrefix (const std::string &) const
 
void mooseError (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecatedNoTrace (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
void callMooseError (std::string msg, const bool with_prefix, const hit::Node *node=nullptr, const bool show_trace=true) 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)
 
static void callMooseError (MooseApp *const app, const InputParameters &params, std::string msg, const bool with_prefix, const hit::Node *node, const bool show_trace=true)
 

Public Attributes

 usingCombinedWarningSolutionWarnings
 
const ConsoleStream _console
 

Static Public Attributes

static const std::string type_param
 
static const std::string name_param
 
static const std::string unique_name_param
 
static const std::string app_param
 
static const std::string moose_base_param
 
static const std::string kokkos_object_param
 

Protected Member Functions

void flagInvalidSolutionInternal (const InvalidSolutionID invalid_solution_id) const
 
InvalidSolutionID registerInvalidSolutionInternal (const std::string &message, const bool warning) const
 
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
 
const MooseEnum_kernel_function
 kernel_function helps the user select between the different kernel functions that are available
 
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
 
const bool & _enabled
 
MooseApp_app
 
Factory_factory
 
ActionFactory_action_factory
 
const std::string & _type
 
const std::string & _name
 
const InputParameters_pars
 
MooseApp_pg_moose_app
 
const std::string _prefix
 
const Parallel::Communicator & _communicator
 

Static Private Member Functions

static const hit::Node * getHitNode (const InputParameters &params)
 
static std::string messagePrefix (const InputParameters &params, const bool hit_prefix)
 

Private Attributes

const ParallelParamObject_parent
 
const MooseBase_si_moose_base
 
const FEProblemBase_si_problem
 

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}
const double mu
std::vector< Real > _data
data helps get the vector data for building the kernel density
const MooseEnum & _kernel_function
kernel_function helps the user select between the different kernel functions that are available
Real _bandwidth
The bandwith parameter which controls the smoothness of the distribution.
const MooseEnum & _bandwidth_rule
bandwidth_rule helps the user select between the different ways to define the bandwith
const InputParameters & parameters() const
void paramError(const std::string &param, Args... args) const
void mooseError(Args &&... args) const
bool isParamValid(const std::string &name) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

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 std::vector< double > x
virtual Real cdf(const Real &x) const override

Referenced by cdf().

◆ 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
static Real cdf(const Real &x, const Real &lower_bound, const Real &upper_bound)
Definition Uniform.C:43
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ 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

Referenced by pdf().

◆ 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}
virtual Real pdf(const Real &x) const override
Definition Normal.C:68
static Real pdf(const Real &x, const Real &lower_bound, const Real &upper_bound)
Definition Uniform.C:34

◆ quantile() [1/2]

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

Implements Distribution.

Definition at line 174 of file KernelDensity1D.C.

175{
177}
const Real p
virtual Real quantile(const Real &p) const override

Referenced by quantile().

◆ 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}
virtual Real quantile(const Real &p) const override
Definition Normal.C:80
static Real quantile(const Real &y, const Real &lower_bound, const Real &upper_bound)
Definition Uniform.C:54

◆ 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}
static InputParameters validParams()
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
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: