Zephyr Scientific Library (zscilib)
Files | Functions
Probability

Probability-related functions. More...

Files

file  probability.h
 API header file for probability in zscilib.
 

Functions

zsl_real_t zsl_prob_uni_pdf (zsl_real_t *a, zsl_real_t *b, zsl_real_t *x)
 Computes the image of a value x of the uniform probability distribution function (PDF), which has zero probability everywhere except in the interval (a, b). More...
 
int zsl_prob_uni_mean (zsl_real_t *a, zsl_real_t *b, zsl_real_t *m)
 Computes the mean of a uniform probability distribution function of interval (a, b). More...
 
int zsl_prob_uni_var (zsl_real_t *a, zsl_real_t *b, zsl_real_t *v)
 Computes the variance of a uniform probability distribution function of interval (a, b). More...
 
zsl_real_t zsl_prob_uni_cdf (zsl_real_t *a, zsl_real_t *b, zsl_real_t *x)
 Computes the image of a value x of the uniform cumulative distribution function (CDF) with interval (a, b). More...
 
zsl_real_t zsl_prob_normal_pdf (zsl_real_t *m, zsl_real_t *s, zsl_real_t *x)
 Computes the image of a value x of the normal probability distribution function (PDF) of mean 'm' and standard deviation 's'. More...
 
zsl_real_t zsl_prob_normal_cdf (zsl_real_t *m, zsl_real_t *s, zsl_real_t *x)
 Computes the image of a value x of the normal cumulative distribution function (CDF) of mean 'm' and standard deviation 's'. More...
 
zsl_real_t zsl_prob_erf_inv (zsl_real_t *x)
 Computes the value of the inverse error fuction of a value 'x' using the Chebyshev interpolation to estimate the value of the function. More...
 
zsl_real_t zsl_prob_normal_cdf_inv (zsl_real_t *m, zsl_real_t *s, zsl_real_t *x)
 Computes the inverse of the normal cumulative distribution function of a value x. More...
 
int zsl_prob_factorial (int *n)
 Computes the factorial of a natural number, i. e., the finite product n * (n - 1) * (n - 2) * (n - 3) * ... * 3 * 2 * 1. More...
 
int zsl_prob_binomial_coef (int *n, int *k, int *c)
 Computes binomial coefficient of n and k (commonly writen as 'n over k'). More...
 
zsl_real_t zsl_prob_binomial_pdf (int *n, zsl_real_t *p, int *x)
 Computes the image of a value x of the binomial probability distribution function (PDF). More...
 
int zsl_prob_binomial_mean (int *n, zsl_real_t *p, zsl_real_t *m)
 Computes the mean of a binomial probability distribution function. More...
 
int zsl_prob_binomial_var (int *n, zsl_real_t *p, zsl_real_t *v)
 Computes the variance of a binomial probability distribution function. More...
 
zsl_real_t zsl_prob_binomial_cdf (int *n, zsl_real_t *p, int *x)
 Computes the image of a value x of the ubinomial cumulative distribution function (CDF). More...
 
int zsl_prob_entropy (struct zsl_vec *v, zsl_real_t *h)
 Computes the Shannon entropy of a set of events with given probabilities. More...
 
int zsl_prob_bayes (zsl_real_t *pa, zsl_real_t *pb, zsl_real_t *pba, zsl_real_t *pab)
 Computes the probability of an event A to occur given the event B, based on the probability of A, B and the probability of B given A, using the Bayes' Theorem. More...
 

Detailed Description

Probability-related functions.

Function Documentation

◆ zsl_prob_bayes()

int zsl_prob_bayes ( zsl_real_t pa,
zsl_real_t pb,
zsl_real_t pba,
zsl_real_t pab 
)

Computes the probability of an event A to occur given the event B, based on the probability of A, B and the probability of B given A, using the Bayes' Theorem.

Parameters
paProbability of the event A.
pbProbability of the event B.
pbaProbability of the event B given the event A.
pabProbability of the event A given the event B.
Returns
0 on success, -EINVAL if the probabilities are greater than one or negative, or if P(B|A) * P(A) > P(B).

Definition at line 301 of file probability.c.

◆ zsl_prob_binomial_cdf()

zsl_real_t zsl_prob_binomial_cdf ( int *  n,
zsl_real_t p,
int *  x 
)

Computes the image of a value x of the ubinomial cumulative distribution function (CDF).

Parameters
nThe number of times the experiment has been done.
pThe probability of the outcome.
xThe number of times we want the outcome.
Returns
0 on success, -EINVAL if n is negative or the probability is not between 0 and 1.

Definition at line 244 of file probability.c.

◆ zsl_prob_binomial_coef()

int zsl_prob_binomial_coef ( int *  n,
int *  k,
int *  c 
)

Computes binomial coefficient of n and k (commonly writen as 'n over k').

Parameters
nThe first input natural number.
kThe second input natural number. This number can be negative or bigger than 'n', but then the function will be returning zero.
cThe combinatory number of 'n' over 'k'.
Returns
0 on success, -EINVAL if n is negative.

Definition at line 168 of file probability.c.

Referenced by zsl_prob_binomial_cdf(), and zsl_prob_binomial_pdf().

◆ zsl_prob_binomial_mean()

int zsl_prob_binomial_mean ( int *  n,
zsl_real_t p,
zsl_real_t m 
)

Computes the mean of a binomial probability distribution function.

Parameters
nThe number of times the experiment has been done.
pThe probability of the outcome.
mThe mean value of the binomial distribution.
Returns
0 on success, -EINVAL if n is negative or the probability is not between 0 and 1.

Definition at line 208 of file probability.c.

◆ zsl_prob_binomial_pdf()

zsl_real_t zsl_prob_binomial_pdf ( int *  n,
zsl_real_t p,
int *  x 
)

Computes the image of a value x of the binomial probability distribution function (PDF).

The binomial distribution describes how likely it is to get the same outcome of an experiment exactly 'x' out of the 'n' times the experiment is repeated. In this formula, 'p' is the probability to get such outcome.

Parameters
nThe number of times the experiment has been done.
pThe probability of the outcome.
xThe number of times we want the outcome.
Returns
0 on success, -EINVAL if n is negative or the probability is not between 0 and 1.

Definition at line 189 of file probability.c.

◆ zsl_prob_binomial_var()

int zsl_prob_binomial_var ( int *  n,
zsl_real_t p,
zsl_real_t v 
)

Computes the variance of a binomial probability distribution function.

Parameters
nThe number of times the experiment has been performed.
pThe probability of the outcome.
vThe variance value of the binomial distribution.
Returns
0 on success, -EINVAL if n is negative or the probability is not between 0 and 1.

Definition at line 226 of file probability.c.

◆ zsl_prob_entropy()

int zsl_prob_entropy ( struct zsl_vec v,
zsl_real_t h 
)

Computes the Shannon entropy of a set of events with given probabilities.

Parameters
vThe vector with the probabilities of the events.
hThe Shannon entropy of the probabilities in v.
Returns
0 on success, -EINVAL if the probabilities in v don't add up to 1 or any of the probabilities is negative.

Definition at line 274 of file probability.c.

◆ zsl_prob_erf_inv()

zsl_real_t zsl_prob_erf_inv ( zsl_real_t x)

Computes the value of the inverse error fuction of a value 'x' using the Chebyshev interpolation to estimate the value of the function.

Parameters
xThe input value, between -1 and 1 (not included).
Returns
The image of the inverse error function of the value x, and -EINVAL if x is outside the open interval (-1, 1).

Definition at line 95 of file probability.c.

Referenced by zsl_prob_normal_cdf_inv().

◆ zsl_prob_factorial()

int zsl_prob_factorial ( int *  n)

Computes the factorial of a natural number, i. e., the finite product n * (n - 1) * (n - 2) * (n - 3) * ... * 3 * 2 * 1.

Parameters
nNatural number to compute its factorial.
Returns
The factorial of the input number n. If the input number is negative, it returns -EINVAL.

Definition at line 151 of file probability.c.

Referenced by zsl_prob_binomial_coef().

◆ zsl_prob_normal_cdf()

zsl_real_t zsl_prob_normal_cdf ( zsl_real_t m,
zsl_real_t s,
zsl_real_t x 
)

Computes the image of a value x of the normal cumulative distribution function (CDF) of mean 'm' and standard deviation 's'.

Parameters
mMean value of the normal distribution.
sStandard deviation of the normal distribution.
xValue to calculate its image.
Returns
The normal cumulative density image of the value x, otherwise an appropriate error code.

Definition at line 86 of file probability.c.

◆ zsl_prob_normal_cdf_inv()

zsl_real_t zsl_prob_normal_cdf_inv ( zsl_real_t m,
zsl_real_t s,
zsl_real_t x 
)

Computes the inverse of the normal cumulative distribution function of a value x.

Parameters
mMean value of the normal distribution.
sStandard deviation of the normal distribution.
xValue to calculate its image. Must be in the open interval (0, 1).
Returns
The inverse of the normal cumulative distribution function of 'x'. If x >= 1 or x is negative of zero, it returns -EINVAL.

Definition at line 134 of file probability.c.

◆ zsl_prob_normal_pdf()

zsl_real_t zsl_prob_normal_pdf ( zsl_real_t m,
zsl_real_t s,
zsl_real_t x 
)

Computes the image of a value x of the normal probability distribution function (PDF) of mean 'm' and standard deviation 's'.

Parameters
mMean value of the normal distribution.
sStandard deviation of the normal distribution.
xValue to calculate its image.
Returns
The normal probility of the value x, otherwise an appropriate error code.

Definition at line 76 of file probability.c.

◆ zsl_prob_uni_cdf()

zsl_real_t zsl_prob_uni_cdf ( zsl_real_t a,
zsl_real_t b,
zsl_real_t x 
)

Computes the image of a value x of the uniform cumulative distribution function (CDF) with interval (a, b).

Parameters
aThe lower bound of the interval in which the probability is not zero.
bThe higher bound of the interval in which the probability is not zero.
xValue to calculate its image.
Returns
The uniform cumulative density image of the value x. If b <= a, then it returns -EINVAL.

Definition at line 58 of file probability.c.

◆ zsl_prob_uni_mean()

int zsl_prob_uni_mean ( zsl_real_t a,
zsl_real_t b,
zsl_real_t m 
)

Computes the mean of a uniform probability distribution function of interval (a, b).

Parameters
aThe lower bound of the interval in which the probability is not zero.
bThe higher bound of the interval in which the probability is not zero.
mThe arithmetic mean of the uniform probability distribution.
Returns
0 on success, and -EINVAL if b <= a.

Definition at line 30 of file probability.c.

◆ zsl_prob_uni_pdf()

zsl_real_t zsl_prob_uni_pdf ( zsl_real_t a,
zsl_real_t b,
zsl_real_t x 
)

Computes the image of a value x of the uniform probability distribution function (PDF), which has zero probability everywhere except in the interval (a, b).

Parameters
aThe lower bound of the interval in which the probability is not zero.
bThe higher bound of the interval in which the probability is not zero.
xValue to calculate its image.
Returns
The uniform probility of the value x. If b <= a, then it returns -EINVAL.

Definition at line 14 of file probability.c.

◆ zsl_prob_uni_var()

int zsl_prob_uni_var ( zsl_real_t a,
zsl_real_t b,
zsl_real_t v 
)

Computes the variance of a uniform probability distribution function of interval (a, b).

Parameters
aThe lower bound of the interval in which the probability is not zero.
bThe higher bound of the interval in which the probability is not zero.
vThe variance of the uniform probability distribution.
Returns
0 on success, and -EINVAL if b <= a.

Definition at line 44 of file probability.c.