<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/probability/blob/v0.25.0/tensorflow_probability/python/math/__init__.py) |

TensorFlow Probability math functions.

## Modules

[`hypergeometric`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/hypergeometric) module: Implements hypergeometric functions in TensorFlow.

[`ode`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/ode) module: TensorFlow Probability ODE solvers.

[`psd_kernels`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/psd_kernels) module: Positive-semidefinite kernels package.

## Classes

[`class MinimizeTraceableQuantities`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/MinimizeTraceableQuantities): Namedtuple of quantities that may be traced from [`tfp.math.minimize`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/minimize).

## Functions

[`atan_difference(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/atan_difference): Difference of arctan(x) and arctan(y).

[`batch_interp_rectilinear_nd_grid(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/batch_interp_rectilinear_nd_grid): Multi-linear interpolation on a rectilinear grid.

[`batch_interp_regular_1d_grid(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/batch_interp_regular_1d_grid): Linear `1-D` interpolation on a regular (constant spacing) grid.

[`batch_interp_regular_nd_grid(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/batch_interp_regular_nd_grid): Multi-linear interpolation on a regular (constant spacing) grid.

[`bessel_iv_ratio(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/bessel_iv_ratio): Computes `I_{v} (z) / I_{v - 1} (z)` in a numerically stable way.

[`bessel_ive(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/bessel_ive): Computes exponentially scaled modified Bessel function of the first kind.

[`bessel_kve(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/bessel_kve): Computes exponentially scaled modified Bessel function of the 2nd kind.

[`betainc(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/betainc): Computes the regularized incomplete beta function element-wise.

[`betaincinv(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/betaincinv): Computes the inverse of [`tfp.math.betainc`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/betainc) with respect to `x`.

[`bracket_root(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/bracket_root): Finds bounds that bracket a root of the objective function.

[`cholesky_concat(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/cholesky_concat): Concatenates `chol @ chol.T` with additional rows and columns.

[`cholesky_update(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/cholesky_update): Returns cholesky of chol @ chol.T + multiplier \* u @ u.T.

[`clip_by_value_preserve_gradient(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/clip_by_value_preserve_gradient): Clips values to a specified min and max while leaving gradient unaltered.

[`custom_gradient(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/custom_gradient): Embeds a custom gradient into a `Tensor`.

[`dawsn(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/dawsn): Computes Dawson's integral element-wise.

[`dense_to_sparse(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/dense_to_sparse): Converts dense `Tensor` to `SparseTensor`, dropping `ignore_value` cells.

[`diag_jacobian(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/diag_jacobian): Computes diagonal of the Jacobian matrix of `ys=fn(xs)` wrt `xs`.

[`erfcinv(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/erfcinv): Computes the inverse of [`tf.math.erfc`](https://www.tensorflow.org/api_docs/python/tf/math/erfc) of `z` element-wise.

[`erfcx(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/erfcx): Computes the scaled complementary error function exp(x\*\*) \* erfc(x).

[`fill_triangular(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/fill_triangular): Creates a (batch of) triangular matrix from a vector of inputs.

[`fill_triangular_inverse(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/fill_triangular_inverse): Creates a vector from a (batch of) triangular matrix.

[`find_root_chandrupatla(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/find_root_chandrupatla): Finds root(s) of a scalar function using Chandrupatla's method.

[`find_root_secant(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/find_root_secant): Finds root(s) of a function of single variable using the secant method.

[`gram_schmidt(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/gram_schmidt): Implementation of the modified Gram-Schmidt orthonormalization algorithm.

[`hpsd_logdet(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/hpsd_logdet): Computes `log|det(matrix)|`, where `matrix` is a HPSD matrix.

[`hpsd_quadratic_form_solve(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/hpsd_quadratic_form_solve): Computes `rhs^T matrix^-1 rhs`, where `matrix` is HPSD.

[`hpsd_quadratic_form_solvevec(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/hpsd_quadratic_form_solvevec): Computes `rhs^T matrix^-1 rhs`, where `matrix` is HPSD.

[`hpsd_solve(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/hpsd_solve): Computes `matrix^-1 rhs`, where `matrix` is HPSD.

[`hpsd_solvevec(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/hpsd_solvevec): Computes `matrix^-1 rhs`, where `matrix` is HPSD.

[`igammacinv(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/igammacinv): Computes the inverse to [`tf.math.igammac`](https://www.tensorflow.org/api_docs/python/tf/math/igammac) with respect to `p`.

[`igammainv(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/igammainv): Computes the inverse to [`tf.math.igamma`](https://www.tensorflow.org/api_docs/python/tf/math/igamma) with respect to `p`.

[`interp_regular_1d_grid(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/interp_regular_1d_grid): Linear `1-D` interpolation on a regular (constant spacing) grid.

[`lambertw(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/lambertw): Computes Lambert W of `z` element-wise.

[`lambertw_winitzki_approx(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/lambertw_winitzki_approx): Computes Winitzki approximation to Lambert W function at z \>= -1/exp(1).

[`lbeta(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/lbeta): Returns log(Beta(x, y)).

[`log1mexp(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/log1mexp): Compute `log(1 - exp(-|x|))` elementwise in a numerically stable way.

[`log1psquare(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/log1psquare): Numerically stable calculation of `log(1 + x**2)` for small or large `|x|`.

[`log_add_exp(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/log_add_exp): Computes `log(exp(x) + exp(y))` in a numerically stable way.

[`log_bessel_ive(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/log_bessel_ive): Computes `log(tfp.math.bessel_ive(v, z))`.

[`log_bessel_kve(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/log_bessel_kve): Computes `log(tfp.math.bessel_kve(v, z))`.

[`log_combinations(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/log_combinations): Log multinomial coefficient.

[`log_cosh(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/log_cosh): Compute `log(cosh(x))` in a numerically stable way.

[`log_cumsum_exp(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/log_cumsum_exp): Computes log(cumsum(exp(x))). (deprecated)

[`log_gamma_correction(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/log_gamma_correction): Returns the error of the Stirling approximation to lgamma(x) for x \>= 8.

[`log_gamma_difference(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/log_gamma_difference): Returns lgamma(y) - lgamma(x + y), accurately.

[`log_sub_exp(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/log_sub_exp): Compute `log(exp(max(x, y)) - exp(min(x, y)))` in a numerically stable way.

[`logerfc(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/logerfc): Computes the logarithm of [`tf.math.erfc`](https://www.tensorflow.org/api_docs/python/tf/math/erfc) of `x` element-wise.

[`logerfcx(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/logerfcx): Computes the logarithm of [`tfp.math.erfcx`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/erfcx) of `x` element-wise.

[`low_rank_cholesky(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/low_rank_cholesky): Computes a low-rank approximation to the Cholesky decomposition.

[`lu_matrix_inverse(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/lu_matrix_inverse): Computes a matrix inverse given the matrix's LU decomposition.

[`lu_reconstruct(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/lu_reconstruct): The inverse LU decomposition, `X == lu_reconstruct(*tf.linalg.lu(X))`.

[`lu_solve(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/lu_solve): Solves systems of linear eqns `A X = RHS`, given LU factorizations.

[`minimize(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/minimize): Minimize a loss function using a provided optimizer.

[`minimize_stateless(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/minimize_stateless): Minimize a loss expressed as a pure function of its parameters.

[`owens_t(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/owens_t): Computes Owen's T function of `h` and `a` element-wise.

[`pivoted_cholesky(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/pivoted_cholesky): Computes the (partial) pivoted cholesky decomposition of `matrix`.

[`reduce_kahan_sum(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/reduce_kahan_sum): Reduces the input tensor along the given axis using Kahan summation.

[`reduce_log_harmonic_mean_exp(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/reduce_log_harmonic_mean_exp): Computes `log(1 / mean(1 / exp(input_tensor)))`.

[`reduce_logmeanexp(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/reduce_logmeanexp): Computes `log(mean(exp(input_tensor)))`.

[`reduce_weighted_logsumexp(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/reduce_weighted_logsumexp): Computes `log(abs(sum(weight * exp(elements across tensor dimensions))))`.

[`round_exponential_bump_function(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/round_exponential_bump_function): Function supported on \[-1, 1\], smooth on the real line, with a round top.

[`scan_associative(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/scan_associative): Perform a scan with an associative binary operation, in parallel.

[`secant_root(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/secant_root): Finds root(s) of a function of single variable using the secant method. (deprecated)

[`smootherstep(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/smootherstep): Computes a sigmoid-like interpolation function on the unit-interval.

[`soft_sorting_matrix(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/soft_sorting_matrix): Computes a matrix representing a continuous relaxation of sorting.

[`soft_threshold(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/soft_threshold): Soft Thresholding operator.

[`softplus_inverse(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/softplus_inverse): Computes the inverse softplus, i.e., x = softplus_inverse(softplus(x)).

[`sparse_or_dense_matmul(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/sparse_or_dense_matmul): Returns (batched) matmul of a SparseTensor (or Tensor) with a Tensor.

[`sparse_or_dense_matvecmul(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/sparse_or_dense_matvecmul): Returns (batched) matmul of a (sparse) matrix with a column vector.

[`sqrt1pm1(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/sqrt1pm1): Compute `sqrt(x + 1) - 1` elementwise in a numerically stable way.

[`trapz(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/trapz): Integrate y(x) on the specified axis using the trapezoidal rule.

[`value_and_gradient(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/math/value_and_gradient): Computes `f(*args, **kwargs)` and its gradients wrt to `args`, `kwargs`.