 # Clarification regarding Example: importance sampling

``````def observe_T(T_obs, obs_name):
T_simulated = simulate(mu)
T_obs_dist = Normal(T_simulated, torch.tensor(time_measurement_sigma))
pyro.sample(obs_name, T_obs_dist, obs=T_obs)
``````

I don’t understand what these few lines is doing.

1. we already have observed_data obtained from running the simulator which is the ’ T_obs’ here, why would we want to use the ‘mu’ drawn from prior and run simulation again?
2. why use ‘pyro.sample’ to sample from the newly obtained ‘T_simulated’ with ‘obs’ being the observed data from the previous run of simulation?
3. the output of ‘def model’ is the ‘mu’ sampled from the prior which is totally not affected by whatever ‘def observe_T’ is doing. So why do it anyway?
4. I don’t fully understand what is the purpose of ‘def model’. Its input is observations obtained from simulator but its output is the parameter sampled from prior. what is the point of it?

Hi @zyzhang1130, I recommend reviewing the introductory tutorial Introduction to Pyro. Your conceptual questions about models and inference in Pyro are answered in detail there, and most other examples and tutorials, including the one you asked about, will not make sense without that foundation.

From the opening text:

A probabilistic program is a mix of ordinary deterministic computation and randomly sampled values representing a generative process for data. By observing the outcome of a probabilistic program, we can describe an inference problem, roughly translated as: “what must be true if this random choice had a certain observed value?” PPLs explicitly enforce a separation of concerns already implicit in the mathematics of probability between the specification of a model, a query to be answered, and an algorithm for computing the answer.

Hi, thanks for the reply. By reading the intro again, I think my part of my question 3 is answered. But I think there is still some discrepancies between that intro tutorial and the importance sampling example. For example, in Example model: Maximum-likelihood linear regression the observed RV is returned where as in the importance sampling example is it not.