- class pymc_experimental.marginal_model.MarginalModel(*args, **kwargs)#
Subclass of PyMC Model that implements functionality for automatic marginalization of variables in the logp transformation
After defining the full Model, the marginalize method can be used to indicate a subset of variables that should be marginalized
Marginalization functionality is still very restricted. Only finite discrete variables can be marginalized. Deterministics and Potentials cannot be conditionally dependent on the marginalized variables.
Furthermore, not all instances of such variables can be marginalized. If a variable has batched dimensions, it is required that any conditionally dependent variables use information from an individual batched dimension. In other words, the graph connecting the marginalized variable(s) to the dependent variable(s) must be composed strictly of Elemwise Operations. This is necessary to ensure an efficient logprob graph can be generated. If you want to bypass this restriction you can separate each dimension of the marginalized variable into the scalar components and then stack them together. Note that such graphs will grow exponentially in the number of marginalized variables.
For the same reason, it’s not possible to marginalize RVs with multivariate dependent RVs.
Marginalize over a single variable
import pymc as pm from pymc_experimental import MarginalModel with MarginalModel() as m: p = pm.Beta("p", 1, 1) x = pm.Bernoulli("x", p=p, shape=(3,)) y = pm.Normal("y", pm.math.switch(x, -10, 10), observed=[10, 10, -10]) m.marginalize([x]) idata = pm.sample()
- __init__(*args, **kwargs)#
add_coord(name[, values, mutable, length])
Registers a dimension coordinate with the model.
add_coords(coords, *[, lengths])
Vectorized version of
Add a random graph variable to the named variables of the model.
Check that the starting values for MCMC do not cause the relevant log probability to evaluate to something invalid (e.g.
Compiled log probability density hessian function.
Compiled log probability density gradient function.
compile_fn(outs, *[, inputs, mode, point_fn])
Compiles an PyTensor function
compile_logp([vars, jacobian, sum])
Compiled log probability density function.
create_value_var(rv_var, transform[, value_var])
TensorVariablethat will be used as the random variable's "value" in log-likelihood graphs.
Hessian of the models log-probability w.r.t.
debug([point, fn, verbose])
Debug model function at point.
Gradient of the models log-probability w.r.t.
Evaluates shapes of untransformed AND transformed free variables.
Computes the initial point of the model.
Elemwise log-probability of the model.
Compile an PyTensor function that computes logp and gradient.
make_obs_var(rv_var, data, dims, transform, ...)
Create a TensorVariable for an observed random variable.
Checks if name has prefix and adds if needed
Checks if name has prefix and deletes if needed
Computes the log probability of point for all random variables in the model.
profile(outs, *[, n, point, profile])
Compiles and profiles an PyTensor function which returns
outsand takes values of model vars as a dict as an argument.
register_rv(rv_var, name[, observed, ...])
Register an (un)observed random variable with the model.
Clone and replace random variables in graphs with their value variables.
set_data(name, values[, coords])
Changes the values of a data variable in the model.
set_dim(name, new_length[, coord_values])
Update a mutable dimension.
Sets an initial value (strategy) for a random variable.
to_graphviz(*[, var_names, formatting])
Produce a graphviz Digraph from a PyMC model.
Update point a with b, without overwriting existing keys.
Tuples of dimension names for specific model variables.
List of random variables the model is defined in terms of (which excludes deterministics).
All the continuous value variables in the model
Coordinate values for model dimensions.
PyTensor scalar of log-probability of the observed variables and potential terms
The symbolic lengths of dimensions in the model.
All the discrete value variables in the model
Maps transformed variables to initial value placeholders.
PyTensor scalar of log-probability of the observed variables
PyTensor scalar of log-probability of the Potential terms
List of all random variables, including deterministic ones.
List of all random variables (including untransformed projections), as well as deterministics used as inputs and outputs of the model's log-likelihood graph
List of unobserved random variables used as inputs to the model's log-likelihood (which excludes deterministics).
PyTensor scalar of log-probability of the unobserved random variables (excluding deterministic).
PyTensor scalar of log-probability of the unobserved random variables (excluding deterministic) without jacobian term.