prophys.symbolic

prophys.symbolic#

Symbolic expressions: parameters, inputs, operators and elementwise functions.

Every model quantity in prophys is an Expr, a lazily evaluated, differentiable expression graph. Leaves are constants (Const), fitted parameters (Param) and data placeholders (Input). Functions such as exp(), sqrt() or where() combine them elementwise. The special functions (erf(), ndtr(), owens_t(), …) are evaluated by optimized native kernels with exact gradients. The most common names are also exported at the top level (prp.exp, prp.Param, …).

Classes

Const

A fixed constant leaf holding a Python scalar, NumPy array or JAX array.

Expr

Base class of every symbolic expression node.

Op

An expression node that applies a pure function to the values of its child expressions.

Param

A named, learnable leaf fitted by calibration or optimization.

Input

A named placeholder for data supplied at evaluation time.

BinaryState

A learnable on/off design decision that stays differentiable.

CategoricalState

A learnable choice among k discrete states that stays differentiable.

Surrogate

Wrap an arbitrary pure callable, compatible with JAX, as a symbolic node.

Functions

op

Build an Op node applying a JAX function to expressions.

wrap

Return value as an expression, wrapping non-Expr values in a Const.

abs_

Elementwise absolute value of an expression (named abs_ to avoid shadowing the builtin).

arctan2

Elementwise arctangent of y / x over all four quadrants, in radians in [-pi, pi].

clip

Elementwise clamp of an expression to the interval [lo, hi].

concatenate

Join expressions along an existing axis.

cos

Elementwise cosine of an expression given in radians.

deg2rad

Elementwise conversion of an angle expression from degrees to radians.

dot

Dot product of two expressions, with jnp.dot semantics (inner product of vectors).

exp

Elementwise exponential e**x of an expression.

log

Elementwise natural logarithm of an expression.

log10

Elementwise base-10 logarithm of an expression.

logsumexp

Numerically stable log(sum(exp(x))) over axis (all elements when axis=None).

maximum

Elementwise maximum of two broadcastable expressions.

mean

Arithmetic mean of an expression over axis (all elements when axis=None).

minimum

Elementwise minimum of two broadcastable expressions.

norm

Euclidean (L2) norm of an expression along axis (the last axis by default).

prod

Product of an expression over axis (all elements when axis=None).

rad2deg

Elementwise conversion of an angle expression from radians to degrees.

relu

Elementwise rectified linear unit max(x, 0) of an expression.

sigmoid

Elementwise logistic sigmoid 1 / (1 + exp(-x)) of an expression.

tanh

Elementwise hyperbolic tangent of an expression.

sign

Elementwise sign of an expression: -1, 0 or +1.

sin

Elementwise sine of an expression given in radians.

softmax

Smooth, differentiable approximation of the maximum along axis.

softmin

Smooth, differentiable approximation of the minimum along axis.

softplus

Elementwise softplus log(1 + exp(x)) of an expression, a smooth positive ramp.

sqrt

Elementwise square root of an expression.

stack

Stack expressions of the same shape along a new axis.

sum_

Sum of an expression over axis (all elements when axis=None).

tan

Elementwise tangent of an expression given in radians.

where

Elementwise selection: a where cond is true, otherwise b.

erf

Elementwise error function erf(x) = 2/sqrt(pi) * integral_0^x exp(-t^2) dt.

erfc

Elementwise complementary error function 1 - erf(x), accurate far into the upper tail.

erfcx

Elementwise scaled complementary error function exp(x^2) erfc(x), free of underflow for large x.

ndtr

Elementwise standard normal cumulative distribution function Phi(x).

log_ndtr

Elementwise logarithm of the standard normal CDF, log Phi(x), accurate in the lower tail.

exp1

Elementwise exponential integral E1(x) for x > 0 (e.g. the Theis well function).

i0e

Elementwise exponentially scaled modified Bessel function of the first kind, exp(-|x|) I0(x).

i1e

Elementwise exponentially scaled modified Bessel function of the first kind, exp(-|x|) I1(x).

k0e

Elementwise scaled modified Bessel function of the second kind, exp(x) K0(x) for x > 0.

k1e

Elementwise scaled modified Bessel function of the second kind, exp(x) K1(x) for x > 0.

owens_t

Elementwise Owen's T function T(h, a).

Exceptions

ShapeError

Raised when shapes are incompatible, such as a distribution's sample shape and its parameters' batch shape.

Constants and objects

Env