pymc.icdf#

pymc.icdf(rv, value, warn_rvs=None, **kwargs)[source]#

Create a graph for the inverse CDF of a random variable.

Parameters
rvTensorVariable
valuetensor_like

Should be the same type (shape and dtype) as the rv.

warn_rvsbool, default True

Warn if RVs were found in the icdf graph. This can happen when a variable has other random variables as inputs. In that case, those random variables should be replaced by their respective values.

Returns
icdfTensorVariable
Raises
RuntimeError

If the icdf cannot be derived.

Examples

Create a compiled function that evaluates the icdf of a variable

import pymc as pm
import pytensor.tensor as pt

mu = pt.scalar("mu")
rv = pm.Normal.dist(mu, 1.0)

value = pt.scalar("value")
rv_icdf = pm.icdf(rv, value)

# Use .eval() for debugging
print(rv_icdf.eval({value: 0.9, mu: 0.0}))  # 1.28155157

# Compile a function for repeated evaluations
rv_icdf_fn = pm.compile_pymc([value, mu], rv_icdf)
print(rv_icdf_fn(value=0.9, mu=0.0))  # 1.28155157

Derive the graph for a transformation of a RandomVariable

import pymc as pm
import pytensor.tensor as pt

mu = pt.scalar("mu")
rv = pm.Normal.dist(mu, 1.0)
exp_rv = pt.exp(rv)

value = pt.scalar("value")
exp_rv_icdf = pm.icdf(exp_rv, value)

# Use .eval() for debugging
print(exp_rv_icdf.eval({value: 0.9, mu: 0.0}))  # 3.60222448

# Compile a function for repeated evaluations
exp_rv_icdf_fn = pm.compile_pymc([value, mu], exp_rv_icdf)
print(exp_rv_icdf_fn(value=0.9, mu=0.0))  # 3.60222448