Math#

This submodule contains various mathematical functions. Most of them are imported directly from aesara.tensor (see there for more details). Doing any kind of math with PyMC random variables, or defining custom likelihoods or priors requires you to use these Aesara expressions rather than NumPy or Python code.

Functions exposed in pymc namespace#

expand_packed_triangular(n, packed[, lower, ...])

Convert a packed triangular matrix into a two dimensional array.

logit(p)

invlogit(x[, eps])

The inverse of the logit function, 1 / (1 + exp(-x)).

probit(p)

invprobit(x)

logsumexp(x[, axis, keepdims])

Compute the log of the sum of exponentials of input elements.

Functions exposed in pymc.math#

dot(l, r)

Return a symbolic dot product.

constant(x[, name, ndim, dtype])

Return a TensorConstant with value x.

flatten(x[, ndim])

Return a copy of the array collapsed into one dimension.

zeros_like(model[, dtype, opt])

equivalent of numpy.zeros_like Parameters ---------- model : tensor dtype : data-type, optional opt : If True, we will return a constant instead of a graph when possible. Useful for Aesara optimization, not for user building a graph as this have the consequence that model isn't always in the graph.

ones_like(model[, dtype, opt])

equivalent of numpy.ones_like Parameters ---------- model : tensor dtype : data-type, optional opt : If True, we will return a constant instead of a graph when possible. Useful for Aesara optimization, not for user building a graph as this have the consequence that model isn't always in the graph.

stack(*tensors, **kwargs)

Stack tensors in sequence on given axis (default is 0).

concatenate(tensor_list[, axis])

Alias for `join`(axis, *tensor_list).

sum(input[, axis, dtype, keepdims, acc_dtype])

Computes the sum along the given axis(es) of a tensor input.

prod(input[, axis, dtype, keepdims, ...])

Computes the product along the given axis(es) of a tensor input.

lt

a < b Generalizes a scalar Op to tensors.

gt

a > b Generalizes a scalar Op to tensors.

le

a <= b Generalizes a scalar Op to tensors.

ge

a >= b Generalizes a scalar Op to tensors.

eq

a == b Generalizes a scalar Op to tensors.

neq

a != b Generalizes a scalar Op to tensors.

switch

if cond then ift else iff Generalizes a scalar Op to tensors.

clip

Clip x to be between min and max.

where

if cond then ift else iff Generalizes a scalar Op to tensors.

and_

bitwise a & b Generalizes a scalar Op to tensors.

or_

bitwise a | b Generalizes a scalar Op to tensors.

exp

e^`a` Generalizes a scalar Op to tensors.

log

base e logarithm of a Generalizes a scalar Op to tensors.

cos

cosine of a Generalizes a scalar Op to tensors.

sin

sine of a Generalizes a scalar Op to tensors.

tan

tangent of a Generalizes a scalar Op to tensors.

cosh

hyperbolic cosine of a Generalizes a scalar Op to tensors.

sinh

hyperbolic sine of a Generalizes a scalar Op to tensors.

tanh

hyperbolic tangent of a Generalizes a scalar Op to tensors.

sqr

square of a Generalizes a scalar Op to tensors.

sqrt

square root of a Generalizes a scalar Op to tensors.

erf

error function Generalizes a scalar Op to tensors.

erfinv

inverse error function Generalizes a scalar Op to tensors.

dot(l, r)

Return a symbolic dot product.

maximum

elemwise maximum.

minimum

elemwise minimum.

sgn

sign of a Generalizes a scalar Op to tensors.

ceil

ceiling of a Generalizes a scalar Op to tensors.

floor

floor of a Generalizes a scalar Op to tensors.

det

Matrix determinant.

matrix_inverse

Computes the inverse of a matrix \(A\).

extract_diag

Return specified diagonals.

matrix_dot(*args)

Shorthand for product between several dots.

trace(X)

Returns the sum of diagonal elements of matrix X.

sigmoid

Logistic sigmoid function (1 / (1 + exp(x)), also known as expit or inverse logit Generalizes a scalar Op to tensors.

logsumexp(x[, axis, keepdims])

Compute the log of the sum of exponentials of input elements.

invlogit(x[, eps])

The inverse of the logit function, 1 / (1 + exp(-x)).

logit(p)