Hello, I’m new to Bayesian inference. After briefly looking at the page Bayesian Regression Using NumPyro — NumPyro documentation, I tried to conduct Bayesian inference using NumPyro. However, the inference results are different from my expected results. Could you please tell me why such differences occur?
Here is my model code
def model(mask_matrix,obs):
m,n = mask_matrix.shape[0],mask_matrix.shape[1]
with numpyro.plate("Z", n):
z = numpyro.sample("z", dist.Uniform(0.0, 1.0))
mu = jnp.array([1.0]*m)
# Here is the iterative method; is there an efficient vectorized form available?
for i in range(m):
for j in range(n):
if mask_matrix[i][j] == 1:
mu = mu.at[i].set(mu[i]*z[j])
numpyro.sample("obs", dist.Normal(mu, 1) ,obs=obs)
In my model, the probability of each data point $ y_j given the set of random variables Z is calculated as the product of the elements in Z that are involved in the operation where N_j is a set indicating which random variables in Z are involved in the computation for y_j $.
P(y_j |Z) = \prod_{i \in N_j } z_i
To test my model, I generated some synthetic data and performed inference using MCMC, but the results did not match my expectations. Why might this be the case?
Here is how i generated synthetic data:
import itertools
total_cnt = 5
#For the sake of simplicity, let's assume that the first i numbers in total_cnt are 0.
expected_0_cnt = 1
expected_1_cnt = total_cnt - expected_0_cnt
expected_result = [0.0] * expected_0_cnt + [1.0] * expected_1_cnt
idx_list = [i for i in range(total_cnt)]
all_idx_commbinations = []
# all_Permutation
for i in range(1,total_cnt+1):
all_idx_commbinations.append(list(itertools.combinations(idx_list,i)))
mask_matrix = []
obs = []
for combinations in all_idx_commbinations:
for combination in combinations:
# False for not choose, True for choose
tmp = [False for _ in range(total_cnt)]
product = 1.0
for idx in combination:
tmp[idx] = True
product *= expected_result[idx]
mask_matrix.append(tmp)
obs.append(product)
mask_matrix = pd.DataFrame(mask_matrix)
obs = pd.DataFrame(obs)
and the inference result is
The output I expected is Z=(0,0,1,1,1) but the inference result is Z = (0.75,0.75,0.75,0.75,0.75) .
Thank you in advance for your guidance