Skip to content

Richer textual representation of parameter relationships #7538

Open
@ricardoV94

Description

@ricardoV94

Description

One easy gain is to get rid of useless f() that depend only on contants.

import pymc as pm
from pymc.printing import str_for_model

with pm.Model() as m:
    x = pm.Exponential("x", lam=2)

str_for_model(m)
# x ~ Exponential(f())

Instead if we rewrite the graph first:

import pymc as pm
from pymc.printing import str_for_model

from pytensor.graph.rewriting.utils import rewrite_graph
from pymc.model.fgraph import fgraph_from_model, model_from_fgraph

with pm.Model() as m:
    x = pm.Exponential("x", lam=2)

fgraph, _ = fgraph_from_model(m)
new_m = model_from_fgraph(rewrite_graph(fgraph))
str_for_model(new_m)
# x ~ Exponential(0.5)

We may also want to use pytensor pretty print to show the content of some of the functions:

import pytensor.tensor as pt
from pytensor.printing import pprint

x = pt.matrix("x")
y = pt.matrix("y")
mu = pm.math.dot(x, y.T) ** 2
    
pprint(mu)
# ((x \dot y.T) ** 2)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions