How `pyro.plate` works with conditional Independence?

Sorry it is a little difficult for me to understand http://pyro.ai/examples/svi_part_ii.html .

Copy the paragraph:

def model(data):
    # sample f from the beta prior
    f = pyro.sample("latent_fairness", dist.Beta(alpha0, beta0))
    # loop over the observed data [WE ONLY CHANGE THE NEXT LINE]
    for i in pyro.plate("data_loop", len(data)):
        # observe datapoint i using the bernoulli likelihood
        pyro.sample("obs_{}".format(i), dist.Bernoulli(f), obs=data[i])

At every execution of the body of the for loop we enter a new (conditional) independence context which is then exited at the end of the for loop body. Let’s be very explicit about this:

  • because each observed pyro.sample statement occurs within a different execution of the body of the for loop, Pyro marks each observation as independent
  • this independence is properly a conditional independence given latent_fairness because latent_fairness is sampled outside of the context of data_loop .

Here , does it means latent_fairness doesn’t change in each for i in pyro.plate("data_loop", len(data)): ?
If I use range , latent_fairness would change along with range loop ?

latent_fairness is outside the plate. there is one common value of latent_fairness that is used by all sample statements in the plate.

Do you mean :
1.

for i in range(epoch):
    latent_fairness = model(xi)
    # latent_fairness  change here
    with plate('observe_data'):
           # latent_fairness doesn't change
for i in range(epoch):
    latent_fairness = model(xi)
    # latent_fairness change here
    for i in range(len(data)):
           # latent_fairness change too

And what will happen if I use range ?

i’m afraid i don’t understand what your pseudo code is doing. e.g. what is model(xi)?

It is batch input , each epoch only use one batch .