35#ifndef STK_LAW_CATEGORICAL_H
36#define STK_LAW_CATEGORICAL_H
84 template <
class OtherArray>
96 template<
class OtherArray>
101 virtual int rand()
const;
113 virtual Real pdf(
int const& x)
const;
119 virtual Real lpdf(
int const& x)
const;
128 template<
class OtherArray>
131 Real u = Law::generator.randUnif(),
cum = 0.;
132 for(
int k =
prob.begin(); k<
prob.lastIdx(); k++)
135 if (
u<=
cum)
return k;
137 return prob.lastIdx();
145 template<
class OtherArray>
162 Real u = Law::generator.randUnif();
211 for (
int k=
prob_.begin(); k<
prob_.end(); ++k)
A Array2DVector is a one dimensional horizontal container.
In this file we define the interface base class IUnivLaw for all probabilities laws.
#define STKDOMAIN_ERROR_1ARG(Where, Arg, Error)
#define STKINVALIDARGUMENT_ERROR_NO_ARG(Where, Error)
#define _T(x)
Let x unmodified.
Derived & resize(Range const &I, Range const &J)
resize the array.
Categorical probability law.
void setProb(OtherArray const &prob)
virtual Real pdf(int const &x) const
compute the probability distribution function (density) Give the value of the pdf at the point x.
Array2DVector< Real > const & cumProb() const
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.
virtual ~Categorical()
destructor
Array2DVector< Real > const & prob() const
virtual Real cdf(Real const &t) const
compute the cumulative distribution function Give the probability that a Categorical random variate i...
Categorical(OtherArray const &prob)
constructor with given probabilities.
virtual Real lpdf(int const &x) const
compute the log probability distribution function Give the value of the log-pdf at the point x.
Array2DVector< Real > cumProb_
cumulative probabilities in a Categorical trial
Categorical(Array2DVector< Real > const &prob)
constructor with given probabilities.
Categorical()
Default constructor.
static int rand(OtherArray const &prob)
virtual int icdf(Real const &prob) const
inverse cumulative distribution function The quantile is defined as the smallest value x such that F...
Array2DVector< Real > prob_
probabilities in a Categorical trial
Interface base class for all the univariate distributions.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Arrays::SumOp< Lhs, Rhs >::result_type sum(Lhs const &lhs, Rhs const &rhs)
convenience function for summing two arrays
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.
Arithmetic properties of STK fundamental types.