Hi, I’m creating a simple linear regression example.
import pyro
def model(x, y=None):
theta_0 = pyro.param("theta_0", torch.randn(1))
theta_1 = pyro.param("theta_1", torch.randn(1))
with pyro.plate("data", len(x)):
return pyro.sample(
"obs", pyro.distributions.Normal(x * theta_1 + theta_0, 1.0), obs=y
)
For different runs, I want to draw samples from the model along with the theta_0
and theta_1
that generated the data.
For a given x
, I can generate data as:
import torch
x = torch.linspace(-5.0, 5.0, 100)
y = x * 4 + 5 + torch.randn(100)
y_model= model(x)
and get the corresponding parameters as:
pyro.param("theta_0")
pyro.param("theta_1")
-
I was wondering if there’s a simpler or better way to do this – get the thetas and the sampled data. My motivation is to show different samples of theta_0 and theta_1 and how they draw different lines.
-
Secondly, how can I use my model to evaluate the log-likelihood of certain given observations given some parameter inputs
theta_0
andtheta_1
?