pymc.model.fgraph.clone_model#

pymc.model.fgraph.clone_model(model)[source]#

Clone a PyMC model.

Recreates a PyMC model with clones of the original variables. Shared variables will point to the same container but be otherwise different objects. Constants are not cloned.

Examples

import pymc as pm
from pymc.model.fgraph import clone_model

with pm.Model() as m:
    p = pm.Beta("p", 1, 1)
    x = pm.Bernoulli("x", p=p, shape=(3,))

with clone_model(m) as clone_m:
    # Access cloned variables by name
    clone_x = clone_m["x"]

    # z will be part of clone_m but not m
    z = pm.Deterministic("z", clone_x + 1)