Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Richer textual representation of parameter relationships #7538

Open
ricardoV94 opened this issue Oct 14, 2024 · 0 comments
Open

Richer textual representation of parameter relationships #7538

ricardoV94 opened this issue Oct 14, 2024 · 0 comments

Comments

@ricardoV94
Copy link
Member

ricardoV94 commented Oct 14, 2024

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)
@ricardoV94 ricardoV94 changed the title Constant fold values in model textual representation Richer textual representation of parameter relationships Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant