STK++ 0.9.13
|
Categorical probability law. More...
#include <STK_Law_Categorical.h>
Public Types | |
typedef IUnivLaw< int > | Base |
Public Member Functions | |
Categorical () | |
Default constructor. | |
Categorical (Array2DVector< Real > const &prob) | |
constructor with given probabilities. | |
template<class OtherArray > | |
Categorical (OtherArray const &prob) | |
constructor with given probabilities. | |
virtual | ~Categorical () |
destructor | |
Array2DVector< Real > const & | prob () const |
Array2DVector< Real > const & | cumProb () const |
template<class OtherArray > | |
void | setProb (OtherArray const &prob) |
virtual int | rand () const |
virtual Real | cdf (Real const &t) const |
compute the cumulative distribution function Give the probability that a Categorical random variate is less or equal to t. | |
virtual Real | pdf (int const &x) const |
compute the probability distribution function (density) Give the value of the pdf at the point x. | |
virtual Real | lpdf (int const &x) const |
compute the log probability distribution function Give the value of the log-pdf at the point x. | |
virtual int | icdf (Real const &prob) const |
inverse cumulative distribution function The quantile is defined as the smallest value x such that F(x) >= p , where F is the cumulative distribution function. | |
![]() | |
virtual | ~IUnivLaw () |
Virtual destructor. | |
virtual Real | lcdf (Real const &t) const |
compute the lower tail log-cumulative distribution function Give the log-probability that a random variate is less or equal to t. | |
virtual Real | cdfc (Real const &t) const |
calculate the complement of cumulative distribution function, called in statistics the survival function. | |
virtual Real | lcdfc (Real const &t) const |
calculate the log-complement of cumulative distribution function Give the log-probability that a random variate is greater than t. | |
![]() | |
String const & | name () const |
Static Public Member Functions | |
template<class OtherArray > | |
static int | rand (OtherArray const &prob) |
template<class OtherArray > | |
static Real | lpdf (int const &x, OtherArray const &prob) |
compute the log probability distribution function Give the value of the log-pdf at the point x. | |
Protected Attributes | |
Array2DVector< Real > | prob_ |
probabilities in a Categorical trial | |
Array2DVector< Real > | cumProb_ |
cumulative probabilities in a Categorical trial | |
![]() | |
String | name_ |
Name of the Law. | |
Private Member Functions | |
void | computeCumProb () |
Additional Inherited Members | |
![]() | |
IUnivLaw (String const &name) | |
Constructor. | |
IUnivLaw (IUnivLaw const &law) | |
copy Constructor. | |
![]() | |
ILawBase (String const &name) | |
Constructor. | |
~ILawBase () | |
destructor. | |
Categorical probability law.
In probability theory and statistics, a categorical distribution (also called a "generalized Bernoulli distribution" or, less precisely, a "discrete distribution") is a probability distribution that describes the result of a random event that can take on one of K possible outcomes, with the probability of each outcome separately specified. There is not necessarily an underlying ordering of these outcomes, but numerical labels are attached for convenience in describing the distribution, often in the range 1 to K. Note that the K-dimensional categorical distribution is the most general distribution over a K-way event; any other discrete distribution over a size-K sample space is a special case. The parameters specifying the probabilities of each possible outcome are constrained only by the fact that each must be in the range 0 to 1, and all must sum to 1.
Note that, in some fields, such as machine learning and natural language processing, the categorical and multinomial distributions are conflated, and it is common to speak of a "multinomial distribution" when a categorical distribution is actually meant.
Definition at line 68 of file STK_Law_Categorical.h.
Definition at line 71 of file STK_Law_Categorical.h.
|
inline |
Default constructor.
Only one category
Definition at line 73 of file STK_Law_Categorical.h.
References computeCumProb().
|
inline |
constructor with given probabilities.
The probabilities will be normalized in order to have an overall sum of 1
prob | probabilities of success in a Categorical trial |
Definition at line 78 of file STK_Law_Categorical.h.
References computeCumProb().
|
inline |
constructor with given probabilities.
The probabilities will be normalized in order to have an overall sum of 1
prob | probabilities of success in a Categorical trial |
Definition at line 85 of file STK_Law_Categorical.h.
References computeCumProb(), prob(), and prob_.
|
inlinevirtual |
compute the cumulative distribution function Give the probability that a Categorical random variate is less or equal to t.
t | a real value |
Implements STK::Law::IUnivLaw< int >.
Definition at line 189 of file STK_Law_Categorical.h.
|
inlineprivate |
Definition at line 207 of file STK_Law_Categorical.h.
References computeCumProb(), cumProb_, prob_, STK::IArray2D< Derived >::resize(), STKINVALIDARGUMENT_ERROR_NO_ARG, and STK::sum().
Referenced by Categorical(), Categorical(), Categorical(), computeCumProb(), and setProb().
|
inline |
Definition at line 93 of file STK_Law_Categorical.h.
References cumProb_.
inverse cumulative distribution function The quantile is defined as the smallest value x such that F(x) >= p , where F is the cumulative distribution function.
prob | a probability number |
Implements STK::Law::IUnivLaw< int >.
Definition at line 197 of file STK_Law_Categorical.h.
References cumProb_, icdf(), prob(), and STKDOMAIN_ERROR_1ARG.
Referenced by icdf().
compute the log probability distribution function Give the value of the log-pdf at the point x.
x | a binary value |
Reimplemented from STK::Law::IUnivLaw< int >.
Definition at line 181 of file STK_Law_Categorical.h.
References prob_.
|
inlinestatic |
compute the log probability distribution function Give the value of the log-pdf at the point x.
x | the value to compute the lpdf. |
prob | the probability of each value |
Definition at line 146 of file STK_Law_Categorical.h.
References prob().
compute the probability distribution function (density) Give the value of the pdf at the point x.
x | an integer value |
Implements STK::Law::IUnivLaw< int >.
Definition at line 174 of file STK_Law_Categorical.h.
References prob_.
|
inline |
Definition at line 91 of file STK_Law_Categorical.h.
References prob_.
Referenced by Categorical(), icdf(), lpdf(), rand(), and setProb().
|
inlinevirtual |
Implements STK::Law::IUnivLaw< int >.
Definition at line 160 of file STK_Law_Categorical.h.
References cumProb_.
Referenced by STK::CategoricalBase< Derived >::rand(), STK::MixtureSemiLearner::randomZi(), STK::IMixtureDensity< Derived >::sample(), STK::IMixtureModel< Derived >::sample(), and STK::IMixtureComposer::sStep().
|
inlinestatic |
Definition at line 129 of file STK_Law_Categorical.h.
References prob().
|
inline |
prob | the probability of success to set |
Definition at line 97 of file STK_Law_Categorical.h.
References computeCumProb(), prob(), and prob_.
|
protected |
cumulative probabilities in a Categorical trial
Definition at line 153 of file STK_Law_Categorical.h.
Referenced by cdf(), computeCumProb(), cumProb(), icdf(), and rand().
|
protected |
probabilities in a Categorical trial
Definition at line 151 of file STK_Law_Categorical.h.
Referenced by Categorical(), cdf(), computeCumProb(), lpdf(), pdf(), prob(), and setProb().