Introduction

The density function of the Uniform distribution:

$$ f(x; a,b) = \frac{1}{b-a} \times \mathbf{1}[ a \leq x \leq b] $$

Parameters:

  • a_par is $a$
  • b_par is $b$

Density


Definition:

 
template<typename Ta, typename Tb>
statslib_constexpr
return_t<Ta> dunif(const Ta x, const Tb a_par, const Tb b_par, const bool log_form = false);

Computes the density function.


Examples:

 
// parameters
double a = -1.0;
double b = 1.0;

// standard input
double dens_val = stats::dunif(0.5,a,b);
double log_dens_val = stats::dunif(0.5,a,b,true);

// Armadillo input
arma::mat X(10,1);
X.fill(0.5);

arma::mat dens_vals_mat = stats::dunif(X,a,b);
arma::mat log_dens_vals_mat = stats::dunif(X,a,b,true);

Probability


Definition:

 
template<typename Ta, typename Tb>
statslib_constexpr
return_t<Ta> punif(const Ta x, const Tb a_par, const Tb b_par, const bool log_form = false);

Computes the cumulative distribution function (CDF).


Examples:

// parameters
double a = -1.0;
double b = 1.0;

// standard input
double prob_val = stats::punif(0.5,a,b);
double log_prob_val = stats::punif(0.5,a,b,true);

// Armadillo input
arma::mat X(10,1);
X.fill(0.5);

arma::mat prob_vals_mat = stats::punif(X,a,b);
arma::mat log_prob_vals_mat = stats::punif(X,a,b,true);

Quantile


Definition:

 
template<typename Ta, typename Tb>
statslib_constexpr
Ta qunif(const Ta p, const Tb a_par, const Tb b_par);

Computes the quantile function.


Examples:

 
// parameters
double a = -1.0;
double b = 1.0;

// standard input
double quant_val = stats::qunif(0.7,a,b);

// Armadillo input
arma::mat X(10,1);
X.fill(0.7);

arma::mat quant_vals_mat = stats::qunif(X,a,b);

Random Sampling


Definition:

 
// random engine seeding
template<typename T>
statslib_inline
return_t<T> runif(const T a_par, const T b_par, rand_engine_t& engine);

// seeding values
template<typename T>
statslib_inline
return_t<T> runif(const T a_par, const T b_par, uint_t seed_val = std::random_device{}());

// U(0,1) draw
template<typename T = double>
statslib_inline
T runif();

// matrix output
template<typename mT, typename eT>
statslib_inline
mT runif(const uint_t n, const uint_t k, const eT a_par, const eT b_par);

Generates pseudo-random draws.


Examples:

// parameters
double a = -1.0;
double b = 1.0;

// standard input
double rand_val = stats::runif(a,b);

// Armadillo output: 10 x 1 matrix
arma::mat rand_mat = stats::runif<arma::mat>(10,1,a,b);