Skip to content

Writing reusable model components. #7487

Answered by ricardoV94
LeeviLindgren asked this question in Q&A
Discussion options

You must be logged in to vote

You can create a nested named model, see the fourth code example in the docs: https://www.pymc.io/projects/docs/en/stable/api/model/generated/pymc.model.core.Model.html

import pymc as pm

with pm.Model(name="root") as root:
    x = pm.Normal("x")  # Variable wil be named "root::x"

    with pm.Model(name='first') as first:
        # Variable will belong to root and first
        y = pm.Normal("y", mu=x)  # Variable wil be named "root::first::y"

    # Can pass parent model explicitly
    with pm.Model(name='second', model=root) as second:
        # Variable will belong to root and second
        z = pm.Normal("z", mu=y)  # Variable wil be named "root::second::z"

    # Set None for standa…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by LeeviLindgren
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants