I have implemented a simple case from “Bayesian Methods for Hackers” about the number of received messages.

Data was generated with the next parameters: size=100, Poisson1(20), Poisson2(50), and switch=70 day.

Estimations:

```
Poisson1, Poisson2, Switch
SVI: 20, 37, 51
NUTS: 20, 47, 70
```

Why NUTS is so much better? Should I improve the Guide function (`tau`

)?

```
def daily_messages_guide(data):
alpha_1 = pyro.param("alpha_1", torch.tensor(1.0),
constraint=constraints.positive)
pyro.sample("lambda_1", dist.Exponential(alpha_1))
alpha_2 = pyro.param("alpha_2", torch.tensor(1.0),
constraint=constraints.positive)
pyro.sample("lambda_2", dist.Exponential(alpha_2))
alpha0 = pyro.param("alpha0", torch.tensor(10.0))
beta0 = pyro.param("beta0", torch.tensor(5.0))
pyro.sample("tau", dist.Beta(alpha0, beta0))
def model(data):
alpha = 1.0 / data.mean()
lambda_1 = pyro.sample("lambda_1", dist.Exponential(alpha))
lambda_2 = pyro.sample("lambda_2", dist.Exponential(alpha))
tau = pyro.sample("tau", dist.Uniform(0, 1))
lambda1_size = (tau * data.size(0) + 1).long()
lambda2_size = data.size(0) - lambda1_size
lambda_ = torch.cat([lambda_1.expand((lambda1_size,)),
lambda_2.expand((lambda2_size,))])
with pyro.plate("data", data.size(0)):
pyro.sample("obs", dist.Poisson(lambda_), obs=data)
```