**4. A few caveats and additional remarks**

For some neutron scattering techniques, the raw data are not immediately available for a reliable lineshape analysis since collected intensities are affected by many spurious contributions. Indeed, the intensity ultimately detected contains, beside the genuine signal from sample, the unwanted ones coming from the empty cell, multiple scattering, sample environment, background; furthermore, it partly results from misguiding effects such as sample auto-shielding and detector efficiency. The importance or even the presence of such spurious effects changes for different neutron techniques; in this perspective, dedicated considerations and suitable adjustments to the recursive method proposed might be required. Data in the test discussed here are assumed to be already corrected for all these effects, that is, already cleaned from any unwanted contribution. Therefore, this is an ideal case, which might be not always straightforward applicable. Differently a reducing data routine has to be performed in advance. Nevertheless, depending on the technique an effort might be done to recognize some quality parameter to draw out the same conclusions that we can get from the model parameters we have seen here above. It is also true that in other neutron techniques, the possibility to reduce the data rapidly letting them available for an *on the run* analysis is preventing the problems here aforesaid and this is even more true for IXS.

Overall, the results of the test discussed are not surprising, as an improvement of the statistical accuracy expectedly enhances the precision of the parameters' determination. Nonetheless, this simple analysis shows how informed decisions about ending or continuing a measurement can be taken based on quantitative grounds. The knowledge of an entire multi-dimensional joint posterior distribution, the evolution of its mode, and overall shape upon increase of the acquisition time could help us to establish not only if data collected are sufficiently integrated but if further counting can enhance the measurement's insight. To this purpose, we can illustrate briefly an example slightly different from the one proposed before. Let us assume that the dynamic structure factor features two pairs of inelastic peaks (shoulders), for example, not only the one observed in the previous example, but, as normally the case for liquids [16, 26], an additional one which, for some reason, does not emerge clearly from the spectral shape. For instance, at low *Q*'s, the first pair can be completely submerged by the resolution tails, while at larger *Q*'s, the paired modes can become

highly damped barely standing out from the background, while, at even larger *Q*'s, they can move out of the energy window covered. Furthermore, if the counting statistics is poor, the marginal posterior distribution for the number of modes can convey ambiguous information and, in some instances, the presence of the second pair of inelastic modes can be overlooked. With an on-line analysis of spectra under collection, one can likely appreciate the possible evolution of such a distribution upon increasing the integration time. For instance, at the early stages of the experiment such a distribution may lead to infer a single pair of inelastic modes, while two (or more) pairs can be inferred as the measurement progresses. However, the incorporation of the Occam's razor principle [11, 27] in the Bayes theorem represents a safe antidote against the risk of overparametrization, especially when the counting statistics is still poor. This can be sufficient to keep the value of *k* from exceeding its true value, which in this example is known to be 2. **Figure 9** (top panel) illustrates how the posterior distribution of the number of modes *k* evolves as a function of the integration time. This trend has a straightforward explanation if one considers the gradually improving of statistical accuracy. At the beginning of the measurement, the algorithm could struggle to establish the true value of *k* assigning not negligible probability to models with a redundant number of modes. As the data are further *harvested*, the posterior distribution becomes more accurate and the number of modes converges to the most plausible one (i.e., *k* ¼ 2). In **Figure 9** (bottom panel), we show the evolution of the posterior distribution of *k* as a function of the measurement acquisition time when a different prior for *k* is chosen. Since we have simulated experimental runs from a model with two DHOs, in this specific case, we know that the best model to fit the data must have two inelastic modes. Therefore, the chosen prior is a modified binomial distribution which privileges a solution with two inelastic modes. In this case, the prior was:

$$P(k) = \binom{k\_{\max} - \mathbf{1}}{k - \mathbf{1}} \pi^{k - 1} (\mathbf{1} - \pi)^{k\_{\max} - (k - 1)} \tag{9}$$

where *kmax* is the maximum number of modes contemplated by the model and we set *π* ¼ 0*:*3. With this *π* value, the variable ð Þ� *k* � 1 B*in k*ð Þ *max* � 1; *π* and the different values of the prior are reported in **Figure 9** (inset of bottom panel). In this figure, we have included also the results obtained by considering only a single experimental run.

#### **Figure 12.**

*Posterior distribution function for the number k of inelastic modes detected in the spectrum after only one experimental run.*

*Bayesian Inference as a Tool to Optimize Spectral Acquisition in Scattering Experiments DOI: http://dx.doi.org/10.5772/intechopen.103850*

**Figure 13.** *Posterior distribution for the lower excitation frequency after one experimental run and 60 runs.*

It appears that, when we have a firm prior knowledge about the system at hand, the posterior distribution converges to its asymptotic value even faster. In fact after five experimental runs we obtain a probability *P k*ð Þ ¼ 2 already close to 90%. In **Figure 12**, we show instead the values of the posterior distribution for *k* attained after a single experimental run. When, as in this case, the counting statistics is really poor the probabilities associated to values of *k* different from the expected value, that is, the one of the generating model (*k* ¼ 2) is not negligible. Finally, the evolution of the posterior for the low-frequency excitation shift strikingly emerges from **Figure 13** in which we compare the results obtained either after a single run or after 60 runs.
