Math#

This submodule contains various mathematical functions. Most of them are imported directly from pytensor.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 PyTensor 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

Logistic sigmoid function (1 / (1 + exp(-x)), also known as expit or inverse logit

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 PyTensor 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 PyTensor optimization, not for user building a graph as this have the consequence that model isn't always in the graph.

stack(tensors[, axis])

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

gt

a > b

le

a <= b

ge

a >= b

eq

a == b

neq

a != b

switch

if cond then ift else iff

clip

Clip x to be between min and max.

where

if cond then ift else iff

and_

bitwise a & b

or_

bitwise a | b

abs

|`a`|

exp

e^`a`

log

base e logarithm of a

cos

cosine of a

sin

sine of a

tan

tangent of a

cosh

hyperbolic cosine of a

sinh

hyperbolic sine of a

tanh

hyperbolic tangent of a

sqr

square of a

sqrt

square root of a

erf

error function

erfinv

inverse error function

dot(l, r)

Return a symbolic dot product.

maximum

elemwise maximum.

minimum

elemwise minimum.

sgn(a)

sign of a

ceil

ceiling of a

floor

floor of a

matrix_inverse

Generalizes a core Op to work with batched dimensions.

sigmoid

Logistic sigmoid function (1 / (1 + exp(-x)), also known as expit or inverse logit

logsumexp(x[, axis, keepdims])

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

invlogit

Logistic sigmoid function (1 / (1 + exp(-x)), also known as expit or inverse logit

logit(p)