JWS C Library
C language utility library
pmf.h File Reference

Declarations for univariate probability mass functions. More...

#include <jwsc/config.h>
#include <stdlib.h>
#include <inttypes.h>
Include dependency graph for pmf.h:

Go to the source code of this file.

Functions

poission_pmf

Computes the Poission pmf at a point.

float poisson_pmf_f (float lambda, uint32_t n)
 Computes the double precision Poisson pmf at a point.
double poisson_pmf_d (double lambda, uint32_t n)
 Computes the double precision Poisson pmf at a point.
sample_poisson_pmf

Draws a random sample from the Poisson pmf.

uint32_t sample_poisson_pmf_f (float lambda, uint32_t a, uint32_t b)
 Draws a single precision random sample from the Poisson pmf.
uint32_t sample_poisson_pmf_d (double lambda, uint32_t a, uint32_t b)
 Draws a double precision random sample from the Poisson pmf.
bernoulli_pmf

Computes the Bernoulli pmf at a point.

float bernoulli_pmf_f (float p, uint32_t n)
 Computes the single precision Bernoulli pmf at a point.
double bernoulli_pmf_d (double p, uint32_t n)
 Computes the double precision Bernoulli pmf at a point.
sample_bernoulli_pmf

Draws a random sample from the Bernoulli pmf.

uint8_t sample_bernoulli_pmf_f (float p)
 Draws a single precision random sample from the Bernoulli pmf.
uint8_t sample_bernoulli_pmf_d (double p)
 Draws a double precision random sample from the Bernoulli pmf.
geometric_pmf

Computes the Geometric pmf at a point.

float geometric_pmf_f (float p, uint32_t n)
 Computes the single precision Geometric pmf at a point.
double geometric_pmf_d (double p, uint32_t n)
 Computes the double precision Geometric pmf at a point.
log_geometric_pmf

Computes the log of the Geometric pmf at a point.

float log_geometric_pmf_f (float p, uint32_t n)
 Computes the single precision log Geometric pmf at a point.
double log_geometric_pmf_d (double p, uint32_t n)
 Computes the double precision log Geometric pmf at a point.
sample_geometric_pmf

Draws a random sample from the Geometric pmf.

uint32_t sample_geometric_pmf_f (float p)
 Draws a single precision random sample from the Geometric pmf.
uint32_t sample_geometric_pmf_d (double p)
 Draws a double precision random sample from the Geometric pmf.

Detailed Description

Declarations for univariate probability mass functions.

Author:
Joseph Schlecht
License:
Creative Commons BY-NC-SA 3.0

Definition in file pmf.h.


Function Documentation

float poisson_pmf_f ( float  lambda,
uint32_t  n 
)

Computes the double precision Poisson pmf at a point.

Parameters:
lambdaMean and variance of the Poisson.
nValue to get the probability of.
Returns:
Probability of n according to the specified Poisson.
Warning:
The computation in this function takes O(n) multiplications so as to maintain numerical stability. If lambda <= 0 and n == 0, 1 is returned. Otherwise, if lambda <= 0 and n != 0, 0 is returned.

Definition at line 88 of file pmf.c.

double poisson_pmf_d ( double  lambda,
uint32_t  n 
)

Computes the double precision Poisson pmf at a point.

Parameters:
lambdaMean and variance of the Poisson.
nValue to get the probability of.
Returns:
Probability of n according to the specified Poisson.
Warning:
The computation in this function takes O(n) multiplications so as to maintain numerical stability. If lambda <= 0 and n == 0, 1 is returned. Otherwise, if lambda <= 0 and n != 0, 0 is returned.

Definition at line 146 of file pmf.c.

uint32_t sample_poisson_pmf_f ( float  lambda,
uint32_t  a,
uint32_t  b 
)

Draws a single precision random sample from the Poisson pmf.

Parameters:
lambdaMean and variance of the Poisson.
aLower bound of the sampling interval.
bUpper bound of the sampling interval.
Returns:
A random sample from the Poisson distrition with parameter lambda over the integer interval [a,b].
Warning:
The computation in this function takes O(n) multiplications so as to maintain numerical stability. If lambda <= 0 and lambda is not in the range [a,b], a or b is returned, which ever is closest to lambda. Otherwise if lambda <= 0 and lambda is in the range [a,b], lambda is returned.
Note:
Does not seed the rand() function. If this is desired, srand() must be called prior to calling this function.

Definition at line 222 of file pmf.c.

uint32_t sample_poisson_pmf_d ( double  lambda,
uint32_t  a,
uint32_t  b 
)

Draws a double precision random sample from the Poisson pmf.

Parameters:
lambdaMean and variance of the Poisson.
aLower bound of the sampling interval.
bUpper bound of the sampling interval.
Returns:
A random sample from the Poisson distrition with parameter lambda over the integer interval [a,b].
Warning:
The computation in this function takes O(n) multiplications so as to maintain numerical stability. If lambda <= 0 and lambda is not in the range [a,b], a or b is returned, which ever is closest to lambda. Otherwise if lambda <= 0 and lambda is in the range [a,b], lambda is returned.
Note:
Does not seed the rand() function. If this is desired, srand() must be called prior to calling this function.

Definition at line 281 of file pmf.c.

float bernoulli_pmf_f ( float  p,
uint32_t  n 
)

Computes the single precision Bernoulli pmf at a point.

Parameters:
pProbability of success, i.e., n == 1.
nValue to get the probability of. Must be either 0 or 1.
Returns:
Probability of n according to the specified Bernoulli.
Warning:
If n > 1, it is considered as 1.

Definition at line 340 of file pmf.c.

double bernoulli_pmf_d ( double  p,
uint32_t  n 
)

Computes the double precision Bernoulli pmf at a point.

Parameters:
pProbability of success, i.e., n == 1.
nValue to get the probability of. Must be either 0 or 1.
Returns:
Probability of n according to the specified Bernoulli.
Warning:
If n > 1, it is considered as 1.

Definition at line 353 of file pmf.c.

uint8_t sample_bernoulli_pmf_f ( float  p)

Draws a single precision random sample from the Bernoulli pmf.

Parameters:
pProbability of success.
Returns:
A random sample from the Bernoulli distrition with parameter p over the integer interval [0,1].
Note:
Does not seed the rand() function. If this is desired, srand() must be called prior to calling this function.

Definition at line 377 of file pmf.c.

uint8_t sample_bernoulli_pmf_d ( double  p)

Draws a double precision random sample from the Bernoulli pmf.

Parameters:
pProbability of success.
Returns:
A random sample from the Bernoulli distrition with parameter p over the integer interval [0,1].
Note:
Does not seed the rand() function. If this is desired, srand() must be called prior to calling this function.

Definition at line 402 of file pmf.c.

float geometric_pmf_f ( float  p,
uint32_t  n 
)

Computes the single precision Geometric pmf at a point.

Parameters:
pProbability of success, must be in (0,1).
nNumber of failures before a success, must be >= 0.

Computes

 (1-p)^n * p 
Note:
The value p must be in (0,1).
Returns:
Probability of n according to the specified Geometric.

Definition at line 440 of file pmf.c.

double geometric_pmf_d ( double  p,
uint32_t  n 
)

Computes the double precision Geometric pmf at a point.

Parameters:
pProbability of success, must be in (0,1).
nNumber of failures before a success, must be >= 0.

Computes

 (1-p)^n * p 
Note:
The value p must be in (0,1).
Returns:
Probability of n according to the specified Geometric.

Definition at line 469 of file pmf.c.

float log_geometric_pmf_f ( float  p,
uint32_t  n 
)

Computes the single precision log Geometric pmf at a point.

Parameters:
pProbability of success, must be in (0,1).
nNumber of failures before a success, must be >= 0.

Computes

 log((1-p)^n * p) 
Note:
The value p must be in (0,1).
Returns:
Probability of n according to the specified Geometric.

Definition at line 508 of file pmf.c.

double log_geometric_pmf_d ( double  p,
uint32_t  n 
)

Computes the double precision log Geometric pmf at a point.

Parameters:
pProbability of success, must be in (0,1).
nNumber of failures before a success, must be >= 0.

Computes

 (1-p)^n * p 
Note:
The value p must be in (0,1).
Returns:
Probability of n according to the specified Geometric.

Definition at line 537 of file pmf.c.

uint32_t sample_geometric_pmf_f ( float  p)

Draws a single precision random sample from the Geometric pmf.

Parameters:
pProbability of success, must be in (0,1).
Returns:
A random sample from the geometric distribution with parameter p.
Warning:
The parameter p must be >= 0.
Note:
Does not seed the rand() function. If this is desired, srand() must be called prior to calling this function.

Definition at line 574 of file pmf.c.

uint32_t sample_geometric_pmf_d ( double  p)

Draws a double precision random sample from the Geometric pmf.

Parameters:
pProbability of success, must be in (0,1).
Returns:
A random sample from the geometric distribution with parameter p.
Warning:
The parameter p must be >= 0.
Note:
Does not seed the rand() function. If this is desired, srand() must be called prior to calling this function.

Definition at line 595 of file pmf.c.