Migrating simple Poisson/Gamma model from Pymc3

Hello!
Following this Pymc3 notebook, I have been trying to migrate some of the models to Turing.

The Estimating a rate from Poisson data: an idealized example example is a simple bayesian model with a Gamma prior for a Poisson Distribution. On my turing implementation I get a theta with ~2.4 mean. On the notebook, the mean is around 0.8.

My code:

@model poisson_model(y) = begin
    theta_1 ~ Gamma(3, 5)
    y ~ Poisson(2*theta_1)
end
model_p = poisson_model(3)
chain2 = sample(model_p, NUTS(), 50000);

What could be wrong with my code? Sorry if it is simple, I am new to Julia and turing :slight_smile:

Pymc3 code for reference:

with pm.Model() as poisson_model:
    theta = pm.Gamma('theta', alpha=3, beta=5)
    post = pm.Poisson('post', mu=2 * theta, observed=3)

Welcome. One possibility is that the Gamma distribution in Python and Julia are parameterized differently. What is the mean of your Gamma prior in PyMC3?

using Distributions
mean(Gamma(3 ,5))

Output:
15.0

Indeed, that appears to be the case:

using Turing, Random

@model poisson_model(y) = begin
    theta_1 ~ Gamma(3, 1/5)
    y ~ Poisson(2*theta_1)
end
Random.seed!(58844)
model_p = poisson_model(3)
chain2 = sample(model_p, NUTS(), 50000);

Output:

Summary Statistics
  parameters      mean       std   naive_se      mcse          ess      rhat 
      Symbol   Float64   Float64    Float64   Float64      Float64   Float64 

     theta_1    0.8557    0.3500     0.0016    0.0023   23968.1460    1.0000

Quantiles
  parameters      2.5%     25.0%     50.0%     75.0%     97.5% 
      Symbol   Float64   Float64   Float64   Float64   Float64 

     theta_1    0.3098    0.6009    0.8094    1.0604    1.6653
1 Like

Perfect! Thank you!!

1 Like