Module Owl_maths Source Maths: fundamental and advanced mathematical functions.
This module contains some basic and advanced mathematical operations. If you cannot find some function in this module, try Stats module.
Please refer to Scipy documentation.
Basic functionsSource val add : float -> float -> float``add x y`` returns :math:`x + y`.
Source val sub : float -> float -> float``sub x y`` returns :math:`x - y`.
Source val mul : float -> float -> float``mul x y`` returns :math:`x * y`.
Source val div : float -> float -> float``div x y`` returns :math:`x / y`.
Source val fmod : float -> float -> float``fmod x y`` returns :math:`x % y`.
Source val atan2 : float -> float -> float``atan2 y x`` returns :math:`\arctan(y/x)`, accounting for the sign of the arguments; this is the angle to the vector :math:`(x, y)` counting from the x-axis.
Source val abs : float -> float``abs x`` returns :math:`|x|`.
Source val neg : float -> float``neg x`` returns :math:`-x`.
Source val reci : float -> float``reci x`` returns :math:`1/x`.
Source val floor : float -> float``floor x`` returns the largest integer :math:`\leq x`.
Source val ceil : float -> float``ceil x`` returns the smallest integer :math:`\geq x`.
Source val round : float -> float``round x`` rounds, towards the bigger integer when on the fence.
Source val trunc : float -> float``trunc x`` integer part.
Source val sqr : float -> floatSource val sqrt : float -> floatSource val pow : float -> float -> float``pow x y`` returns :math:`x^y`.
Source val exp : float -> floatSource val exp2 : float -> floatSource val exp10 : float -> floatSource val expm1 : float -> float``expm1 x`` returns :math:`\exp(x) - 1` but more accurate for :math:`x \sim 0`.
Source val log : float -> float``log x`` natural logarithm
Source val log2 : float -> float``log2 x`` base-2 logarithm.
Source val log10 : float -> float``log10 x`` base-10 logarithm.
Source val logn : float -> float -> float``logn x`` base-n logarithm.
Source val log1p : float -> float``log1p x`` returns :math:`\log (x + 1)` but more accurate for :math:`x \sim 0`. Inverse of ``expm1``.
Source val logabs : float -> float``logabs x`` returns :math:`\log(|x|)`.
Source val sigmoid : float -> float``sigmoid x`` returns the logistic sigmoid function :math:`1 / (1 + \exp(-x))`.
Source val signum : float -> float``signum x`` returns the sign of :math:`x`: -1, 0 or 1.
Source val softsign : float -> floatSource val softplus : float -> float``softplus x`` returns :math:`\log(1 + \exp(x))`.
Source val relu : float -> float``relu x`` returns :math:`\max(0, x)`.
Source val sin : float -> float``sin x`` returns :math:`\sin(x)`.
Source val cos : float -> float``cos x`` returns :math:`\cos(x)`.
Source val tan : float -> float``tan x`` returns :math:`\tan(x)`.
Source val cot : float -> float``cot x`` returns :math:`1/\tan(x)`.
Source val sec : float -> float``sec x`` returns :math:`1/\cos(x)`.
Source val csc : float -> float``csc x`` returns :math:`1/\sin(x)`.
Source val asin : float -> float``asin x`` returns :math:`\arcsin(x)`.
Source val acos : float -> float``acos x`` returns :math:`\arccos(x)`.
Source val atan : float -> float``atan x`` returns :math:`\arctan(x)`.
Source val acot : float -> floatInverse function of ``cot``.
Source val asec : float -> floatInverse function of ``sec``.
Source val acsc : float -> floatInverse function of ``csc``.
Source val sinh : float -> floatReturns :math:`\sinh(x)`.
Source val cosh : float -> float``cosh x`` returns :math:`\cosh(x)`.
Source val tanh : float -> float``tanh x`` returns :math:`\tanh(x)`.
Source val coth : float -> float``coth x`` returns :math:`\coth(x)`.
Source val sech : float -> float``sech x`` returns :math:`1/\cosh(x)`.
Source val csch : float -> float``csch x`` returns :math:`1/\sinh(x)`.
Source val asinh : float -> floatInverse function of ``sinh``.
Source val acosh : float -> floatInverse function of ``cosh``.
Source val atanh : float -> floatInverse function of ``tanh``.
Source val acoth : float -> floatInverse function of ``coth``.
Source val asech : float -> floatInverse function of ``sech``.
Source val acsch : float -> floatInverse function of ``csch``.
Source val sinc : float -> float``sinc x`` returns :math:`\sin(x)/x` and :math:`1` for :math:`x=0`.
Source val logsinh : float -> float``logsinh x`` returns :math:`\log(\sinh(x))` but handles large :math:`|x|`.
Source val logcosh : float -> float``logcosh x`` returns :math:`\log(\cosh(x))` but handles large :math:`|x|`.
Source val sindg : float -> floatSine of angle given in degrees.
Source val cosdg : float -> floatCosine of the angle given in degrees.
Source val tandg : float -> floatTangent of angle given in degrees.
Source val cotdg : float -> floatCotangent of the angle given in degrees.
Source val hypot : float -> float -> float``hypot x y`` returns :math:`\sqrtx^2 + y^2`.
Source val xlogy : float -> float -> float``xlogy(x, y)`` returns :math:`x \log(y)`.
Source val xlog1py : float -> float -> float``xlog1py(x, y)`` returns :math:`x \log(y+1)`.
Source val logit : float -> float``logit(x)`` returns :math:`\logp/(1-p)`.
Source val expit : float -> float``expit(x)`` returns :math:`1/(1+\exp(-x))`.
Source val log1mexp : float -> float``log1mexp(x)`` returns :math:`log(1-exp(x))`.
Source val log1pexp : float -> float``log1pexp(x)`` returns :math:`log(1+exp(x))`.
Airy functionsSource val airy : float -> float * float * float * floatAiry function ``airy x`` returns ``(Ai, Ai', Bi, Bi')`` evaluated at :math:`x`. ``Ai'`` is the derivative of ``Ai`` whilst ``Bi'`` is the derivative of ``Bi``.
Bessel functionsBessel function of the first kind of order 0.
Bessel function of the first kind of order 1.
Source val jv : float -> float -> floatBessel function of real order.
Bessel function of the second kind of order 0.
Bessel function of the second kind of order 1.
Source val yv : float -> float -> floatBessel function of the second kind of real order.
Source val yn : int -> float -> floatBessel function of the second kind of integer order.
Modified Bessel function of order 0.
Source val i0e : float -> floatExponentially scaled modified Bessel function of order 0.
Modified Bessel function of order 1.
Source val i1e : float -> floatExponentially scaled modified Bessel function of order 1.
Source val iv : float -> float -> floatModified Bessel function of the first kind of real order.
Modified Bessel function of the second kind of order 0, :math:`K_0`.
Source val k0e : float -> floatExponentially scaled modified Bessel function K of order 0.
Modified Bessel function of the second kind of order 1, :math:`K_1(x)`.
Source val k1e : float -> floatExponentially scaled modified Bessel function K of order 1.
Elliptic functionsSource val ellipj : float -> float -> float * float * float * floatJacobian Elliptic function ``ellipj u m`` returns ``(sn, cn, dn, phi)``.
Source val ellipk : float -> float``ellipk m`` returns the complete elliptic integral of the first kind.
Source val ellipkm1 : float -> floatFIXME. Complete elliptic integral of the first kind around :math:`m = 1`.
Source val ellipkinc : float -> float -> float``ellipkinc phi m`` incomplete elliptic integral of the first kind.
Source val ellipe : float -> float``ellipe m`` complete elliptic integral of the second kind.
Source val ellipeinc : float -> float -> float``ellipeinc phi m`` incomplete elliptic integral of the second kind.
Gamma FunctionsSource val gamma : float -> float``gamma z`` returns the value of the Gamma function
.. math:: \Gamma(z) = \int_0^\infty x^z-1 e^
x
}
dx = (z - 1)! .
The gamma function is often referred to as the generalized factorial since :math:`z\ gamma(z) = \gamma(z+1)` and :math:`gamma(n+1) = n!` for natural number :math:`n`.
Source val rgamma : float -> floatReciprocal Gamma function.
Source val loggamma : float -> floatLogarithm of the gamma function.
Source val gammainc : float -> float -> floatIncomplete gamma function.
Source val gammaincinv : float -> float -> floatInverse function of ``gammainc``.
Source val gammaincc : float -> float -> floatComplemented incomplete gamma integral.
Source val gammainccinv : float -> float -> floatInverse function of ``gammaincc``.
Source val psi : float -> float Beta functionsSource val beta : float -> float -> floatBeta function.
.. math:: \mathrmB(a, b) = \frac\Gamma(a) \Gamma(b)\Gamma(a+b)
Source val betainc : float -> float -> float -> floatIncomplete beta integral.
Source val betaincinv : float -> float -> float -> floatInverse function of ``betainc``.
FactorialsFactorial function ``fact n`` calculates :math:`n!`.
Source val log_fact : int -> floatLogarithm of factorial function ``log_fact n`` calculates :math:`\log n!`.
Source val doublefact : int -> floatDouble factorial function ``doublefact n`` calculates :math:`n!! = n(n-2)(n-4)\dots 2` or :math:`\dots 1`
Source val log_doublefact : int -> floatLogarithm of double factorial function.
Source val permutation : int -> int -> int``permutation n k`` returns the number :math:`n!/(n-k)!` of ordered subsets * of length :math:`k`, taken from a set of :math:`n` elements.
Source val permutation_float : int -> int -> float``permutation_float`` is like ``permutation`` but deals with larger range.
Source val combination : int -> int -> int``combination n k`` returns the number :math:`n!/(k!(n-k)!)` of subsets of k elements of a set of n elements. This is the binomial coefficient :math:`\binomnk`
Source val combination_float : int -> int -> float``combination_float`` is like ``combination`` but can deal with a larger range.
Source val log_combination : int -> int -> float``log_combination n k`` returns the logarithm of :math:`\binomnk`.
Error functionsSource val erf : float -> floatError function. :math:`\int_
\infty
}
^x \frac
\sqrt(2\pi) \exp(-(1/2) y^2) dy`
Source val erfc : float -> floatComplementary error function, :math:`\int^\infty_x \frac
\sqrt(2\pi) \exp(-(1/2) y^2) dy`
Source val erfcx : float -> floatScaled complementary error function, :math:`\exp(x^2) \mathrmrfc (x)`.
Source val erfinv : float -> floatInverse function of ``erf``.
Source val erfcinv : float -> floatInverse function of ``erfc``.
Dawson & Fresnel integralsSource val dawsn : float -> floatSource val fresnel : float -> float * floatFresnel trigonometric integrals. ``fresnel x`` returns a tuple consisting of ``(Fresnel sin integral, Fresnel cos integral)``.
Struve functionsSource val struve : float -> float -> float``struve v x`` returns the value of the Struve function of order :math:`v` at :math:`x`. The Struve function is defined as,
.. math:: H_v(x) = (z/2)^
+ 1} \sum_{n=0}^\infty \frac{(-1)^n (z/2)^{2n}}{\Gamma(n + \frac{3}{2}) \Gamma(n + v + \frac{3}{2})},
where :math:`\Gamma` is the gamma function. :math:`x` must be positive unless :math:`v` is an integer
Other special functionsSource val expn : int -> float -> floatExponential integral :math:`E_n`.
Source val shichi : float -> float * floatHyperbolic sine and cosine integrals, ``shichi x`` returns * :math:`(\mathrmshi, \mathrmchi)``.
Source val shi : float -> floatHyperbolic sine integral.
Source val chi : float -> floatHyperbolic cosine integral.
Source val sici : float -> float * floatSine and cosine integrals, ``sici x`` returns :math:`(\mathrmsi, \mathrmci)`.
Source val zeta : float -> float -> float``zeta x q`` returns the Hurwitz zeta function :math:`\zeta(x, q)`, which reduces to the Riemann zeta function :math:`\zeta(x)` when :math:`q=1`.
Source val zetac : float -> floatRiemann zeta function minus 1.
Raw statistical functionsSource val bdtr : int -> int -> float -> floatBinomial distribution cumulative distribution function.
``bdtr k n p`` calculates the sum of the terms :math:`0` through :math:`k` of the Binomial probability density.
.. math:: \mathrmdtr (k, n, p) = \sum_j=0^k {n\choosej
}
p^j (1-p)^n-j
Parameters: * ``k``: Number of successes. * ``n``: Number of events. * ``p``: Probability of success in a single event.
Returns: * Probability of :math:`k` or fewer successes in :math:`n` independent events with success probability :math:`p`.
Source val bdtrc : int -> int -> float -> floatBinomial distribution survival function.
``bdtrc k n p`` calculates the sum of the terms :math:`k + 1` through :math:`n` of the binomial probability density,
.. math:: \mathrmdtrc (k, n, p) = \sum_j=k+1^n {n\choosej
}
p^j (1-p)^n-j
Source val bdtri : int -> int -> float -> floatInverse function to ``bdtr`` with respect to :math:`p`.
Finds the event probability :math:`p` such that the sum of the terms 0 through :math:`k` of the binomial probability density is equal to the given cumulative probability :math:`y`.
Source val btdtr : float -> float -> float -> floatCumulative density function of the beta distribution.
``btdtr a b x`` returns the integral from 0 to :math:`x` of the beta probability density function,
.. math:: I = \int_0^x \frac\Gamma(a + b)\Gamma(a)\Gamma(b) t^a-1 (1-t)^-1 \,dt
where :math:`\Gamma` is the gamma function.
Parameters: * ``a``: Shape parameter (:math:`a > 0`). * ``b``: Shape parameter (:math:`a > 0`). * ``x``: Upper limit of integration, in :math:`0, 1`.
Returns: * Cumulative density function of the beta distribution with :math:`a` and :math:`b` at :math:`x`.
Source val btdtri : float -> float -> float -> floatThe :math:`p`-th quantile of the Beta distribution.
This function is the inverse of the beta cumulative distribution function, ``btdtr``, returning the value of :math:`x` for which :math:`\mathrmtdtr (a, b, x) = p`,
.. math:: p = \int_0^x \frac\Gamma(a + b)\Gamma(a)\Gamma(b) t^a-1 (1-t)^-1 \,dt
where :math:`\Gamma` is the gamma function.
Parameters: * ``a``: Shape parameter (:math:`a > 0`). * ``b``: Shape parameter (:math:`a > 0`). * ``x``: Cumulative probability, in :math:`0, 1`.
Returns: * The quantile corresponding to :math:`p`.
Helper functionsSource val is_nan : float -> bool``is_nan x`` returns ``true`` exactly if ``x`` is ``nan``.
Source val is_inf : float -> bool``is_inf x`` returns ``true`` exactly if ``x`` is ``infinity`` or ``neg_infinity``.
Source val is_normal : float -> bool``is_normal x`` returns ``true`` if ``x`` is a normal float number.
Source val is_subnormal : float -> bool``is_nan x`` returns ``true`` if ``x`` is subnormal float number.
Source val is_odd : int -> bool``is_odd x`` returns ``true`` exactly if ``x`` is odd.
Source val is_even : int -> bool``is_even x`` returns ``true`` exactly if ``x`` is even.
Source val is_pow2 : int -> bool``is_pow2 x`` return ``true`` exactly if ``x`` is an integer power of 2, e.g. 32, 64, etc.
Source val same_sign : float -> float -> bool``same_sign x y`` returns ``true`` if ``x`` and ``y`` have the same sign, otherwise it returns ``false``. Positive and negative zeros are special cases and always returns ``true``.
Source val is_simplex : float array -> bool``is_simplex x`` checks whether the vector :math:`x` lies on a simplex. In other words, :math:`\sum_i^K x_i = 1` and :math:`x_i \ge 0, \forall i \in 1,K`, where :math:`K` is the dimension of :math:`x`.
Source val is_int : float -> boolSource val is_sqr : int -> bool``is_sqr x`` checks if ``x`` is the square of an integer.
Source val mulmod : int -> int -> int -> int``mulmod a b m`` computes (a*b) mod m.
Source val powmod : int -> int -> int -> int``powmod a b m`` computes (a^b) mod m.
Source val is_prime : int -> bool``is_prime x`` returns ``true`` if ``x`` is a prime number. The function is deterministic for all numbers representable by an int. The function uses the Rabin–Miller primality test.
Source val fermat_fact : int -> int * int``fermat_fact x`` performs Fermat factorisation over ``x``, i.e. into two roughly equal factors. ``x`` must be an odd number.
Source val nextafter : float -> float -> float``nextafter from to`` returns the next representable double precision value of ``from`` in the direction of ``to``. If ``from`` equals ``to``, this value is returned.
Source val nextafterf : float -> float -> float``nextafter from to`` returns the next representable single precision value of ``from`` in the direction of ``to``. If ``from`` equals ``to``, this value is returned.