heya! i’m very new to pyro, but i’ve some experience with pymc3. sorry about the long post, but to compensate, my questions are probably very simple
i found this tutorial where they have a similar noisy scale example as in official docs, and define a model like this:
def model(observations):
weight_prior = pyrodist.Uniform(0.0, 2.0)
weight = pyro.sample("weight1", weight_prior)
my_dist = pyrodist.Normal(weight, 0.1)
for i,observation in enumerate(observations):
measurement = pyro.sample(f'obs_{i}', my_dist, obs=observation)
now, i can kind of get how they think with looping through the observations and checking each individual observation, but it also feels really explicit compared to pymc3.
so i tried doing it similarly to what i would do in pymc3 like so:
def model3(observatories):
weight = pyro.sample('weight', pyrodists.Uniform(0, 2))
measurement = pyro.sample("measurement", pyrodists.Normal(weight, 0.1), obs=observatories)
this worked nicely. so my first question is; is there some reason for doing that explicit comparison from the tutorial?
i’m asking, because my feeling so far is that pyro is more explicit/needs more detailed code than pymc3, for example that you have to define a kernel for mcmc. but it may also just be that all the tutorials and examples i’ve seen so far happen to be very explicit?
secondly, about pyro.condition
, i went to official docs and found my model above was similar to the example there, namely
def scale(guess):
weight = pyro.sample("weight", dist.Normal(guess, 1.0))
return pyro.sample("measurement", dist.Normal(weight, 0.75))
and then you can wrap that function like this:
def deferred_conditioned_scale(measurement, guess):
return pyro.condition(scale, data={"measurement": measurement})(guess)
my question here is if i’m correct in thinking this “deferred” way of writing the function allows us to have a generative model for simulations (scale in this case) and then simply wrap that with the deferred function in order to do inference?
if so, how? because trying to run inference using the deferred function it complains i don’t have the guess parameter:
kernel4 = pyro.infer.NUTS(deferred_conditioned_scale)
mcmc4 = pyro.infer.MCMC(deferred_conditioned_scale, num_samples=2000)
mcmc4.run(obs)
...
deferred_conditioned_scale() missing 1 required positional argument: 'guess'
my experience with pymc3 is i’ll write simulation code with regular numpy and then write basically the same function with theano for pymc3 to be able to do its thing. so the ability to wrap with the deferred functions would be great!
i really like that you can iterate code and check results as you go in pyro, pymc3/theano can be very frustrating to debug if your model doesn’t compile for whatever reason.