# Simple Beta-Bernoulli model and HMC inference

Hello, I am trying HMC inference on simple Beta-Bernoulli model, but it seems doesn’t work. I get correct samples from Beta distributed variable, but posteriors from Empirical variable are not in [0;1] rage, they are negative in most cases.

``````import edward as ed
import tensorflow as tf
from edward.models import (
Beta,
Bernoulli,
Empirical
)

x_prob = Beta(0.3, 1.0)
x = Bernoulli(probs=x_prob)

qx_prob = Empirical(params=tf.Variable(tf.zeros(10)))

inference = ed.HMC({x_prob: qx_prob}, data={x: 1})
inference.run(n_steps=10)

samples = x_prob.sample(10).eval()
print("samples: " + str(samples))

params = qx_prob.params.eval()
print("params: " + str(params))

mean = qx_prob.mean().eval()
print("mean: " + str(mean))
``````

Output sample:
samples: [ 0.08889898 0.00208424 0.5681445 0.01588311 0.01571349 0.00344653 0.20849131 0.05374139 0.34170994 0.17989925]
params: [-1.26416469 -1.35929894 -1.35929894 1.10303259 1.10303259 0.05707812 -3.77804422 -3.77804422 -1.0335499 -0.17189652]
mean: -1.04812

Yeah, something seems odd. I just tried the same with MetropolisHastings and the result looks good, note that I also set the sample_shape to be greater than 1 in order to get smoother likelihood values.

``````N = 100

x_prob = Beta(0.3, 1.0)
x = Bernoulli(x_prob, sample_shape=N, dtype=tf.float32)
qx_prob = Empirical(params=tf.Variable(tf.ones(10000) * .5))

x_proposal = Normal(loc=x_prob, scale=0.1)
inference = ed.MetropolisHastings({x_prob: qx_prob}, {x_prob: x_proposal}, data={x: tf.ones(N)})
inference.run()
``````

Perhaps @dustin can comment on this.