Special functions

Beta

numpy_sugar.special.beta_isf(a, b, x)[source]

Inverse of the Beta survival function.

Parameters:
  • a (array_like) – parameter a.
  • b (array_like) – parameter b.
  • x (array_like) – evaluation point.

Chi-squared

numpy_sugar.special.chi2_sf(k, x)

Chi-squared distribution [1] survival function.

Parameters:
  • k (array_like) – Degrees of fredom.
  • x (array_like) – Evaluation point.
Returns:

Survival function of the \(\chi_k^2\)

distribution.

Return type:

numpy.ndarray

References

[1] https://en.wikipedia.org/wiki/Chi-squared_distribution

Gamma

numpy_sugar.special.lgamma(x)

Natural logarithm of the Gamma function [1].

Parameters:x (array_like) – evaluation point.
Returns:Log-gamma of x.
Return type:numpy.ndarray

References

[1] https://en.wikipedia.org/wiki/Gamma_function

Log sum

numpy_sugar.special.logbinom(a, b)

Natural logarithm of Binomial coefficient: \(\log{a \choose b}\).

numpy_sugar.special.logaddexp(x, y)

Numerically-stable numpy.log(numpy.exp(x)+numpy.exp(y)).

Parameters:
  • x (array_like) – First array.
  • y (array_like) – Second array.
Returns:

numpy.log(numpy.exp(x)+numpy.exp(y)).

numpy_sugar.special.logaddexps(x, y, sx, sy)

Numerically-stable numpy.log(sx*numpy.exp(x)+sy*numpy.exp(y)).

numpy_sugar.special.logaddexpss(x, y, sx, sy, r, sign)[source]

Numerically-stable numpy.log(sx*numpy.exp(x)+sy*numpy.exp(y)).

Suppose you are interested in computing:

sx[i]*exp(x[i]) + sy[i]*exp(y[i])

where sx[i] and sy[i] are either -1 or +1. Often a direct calculation of the above is numerically innacurate. Instead, let:

sign[i]*exp(r[i]) = sx[i]*exp(x[i]) + sy[i]*exp(y[i])

This function accurately computes r[i] and sign[i], where sign[i] is either -1 or +1.

numpy_sugar.special.logsumexp(x)[source]

Numerically-stable numpy.log(sum(numpy.exp(x))).

Parameters:x (array_like) – We want the sum of their exponentiated values but in a numerically-stable way.
Returns:numpy.log(sum(numpy.exp(x))).

Normal

numpy_sugar.special.normal_pdf(x)

P.d.f. of the Normal distribution.

Parameters:x (array_like) – evaluation point.
numpy_sugar.special.normal_cdf(x)

C.d.f. of the Normal distribution.

Parameters:x (array_like) – evaluation point.
numpy_sugar.special.normal_icdf(x)

Inverse of the c.d.f. of the Normal distribution.

Parameters:x (array_like) – evaluation point.
numpy_sugar.special.normal_sf(x)

Survival function of the Normal distribution.

Parameters:x (array_like) – evaluation point.
numpy_sugar.special.normal_isf(x)

Inverse of the survival function of the Normal distribution.

Parameters:x (array_like) – evaluation point.
numpy_sugar.special.normal_logpdf(x)

Natural logarithm of the p.d.f. of the Normal distribution.

Parameters:x (array_like) – evaluation point.
numpy_sugar.special.normal_logcdf(x)

Natural logarithm of the c.d.f. of the Normal distribution.

Parameters:x (array_like) – evaluation point.
numpy_sugar.special.normal_logsf(x)

Natural logarithm of the survival function of the Normal distribution.

Parameters:x (array_like) – evaluation point.

Pearson

numpy_sugar.special.r_squared(x, y)[source]

Coefficient of determination between x and y.

It equals to scipy.stats.pearsonr(x, y)[0]**2.

Parameters:
  • x (array_like) – First array.
  • y (array_like) – Second array.
Returns:

Squared Pearson correlation.

numpy_sugar.special.beta_isf(a, b, x)[source]

Inverse of the Beta survival function.

Parameters:
  • a (array_like) – parameter a.
  • b (array_like) – parameter b.
  • x (array_like) – evaluation point.
numpy_sugar.special.logaddexpss(x, y, sx, sy, r, sign)[source]

Numerically-stable numpy.log(sx*numpy.exp(x)+sy*numpy.exp(y)).

Suppose you are interested in computing:

sx[i]*exp(x[i]) + sy[i]*exp(y[i])

where sx[i] and sy[i] are either -1 or +1. Often a direct calculation of the above is numerically innacurate. Instead, let:

sign[i]*exp(r[i]) = sx[i]*exp(x[i]) + sy[i]*exp(y[i])

This function accurately computes r[i] and sign[i], where sign[i] is either -1 or +1.

numpy_sugar.special.logsumexp(x)[source]

Numerically-stable numpy.log(sum(numpy.exp(x))).

Parameters:x (array_like) – We want the sum of their exponentiated values but in a numerically-stable way.
Returns:numpy.log(sum(numpy.exp(x))).
numpy_sugar.special.r_squared(x, y)[source]

Coefficient of determination between x and y.

It equals to scipy.stats.pearsonr(x, y)[0]**2.

Parameters:
  • x (array_like) – First array.
  • y (array_like) – Second array.
Returns:

Squared Pearson correlation.