# A Bayesian Modeling Approach to Situated Design of Personalized Soundscaping Algorithms
## 2 Methods
### Factor Graphs and Message Passing-Based Inference
#### 2.3.4 Automating Inference and Variational Free Energy Evaluation  
For frequently-used elementary factor nodes, the message update rules (20) and (22) can be derived analytically and saved in a lookup table. Message passing-based inference then resorts mainly to substituting the current argument values in worked-out update rules. A few open source toolboxes exist for supporting this type of \"automated\" message passing-based inference. In this paper, we selected ReactiveMP (ReactiveMP is available at [[https://github.com/biaslab/ReactiveMPjl](https://github.com/biaslab/ReactiveMPjl)]([https://github.com/biaslab/ReactiveMPjl](https://github.com/biaslab/ReactiveMPjl)), accessed on 1 July 2021), the successor of ForneyLab (ForneyLab is available at [[https://github.com/biaslab/ForneyLab.jl](https://github.com/biaslab/ForneyLab.jl)]([https://github.com/biaslab/ForneyLab.jl](https://github.com/biaslab/ForneyLab.jl)), accessed on 1 July 2021) [25], to realize the previously described inference tasks (2), (3) and (5). ReactiveMP is an open source Julia package for message passing-based inference that specifically aims to excel at real-time inference in dynamic models. This package allows us to specify a generative model and to perform automated inference on this model. The desired distributions of (2), (3) and (5) are therefore automatically calculated. Furthermore, ReactiveMP automatically evaluates the performance of the model on the data by calculating the Bethe free energy [46], which equals the variational free energy for acyclic graphs. This free energy is calculated using node-local free energies and the edge-local entropies of the random variables, where we can also impose local constraints on these variables for a trade-off between tractability and accuracy of the free energy calculation [47]. In this paper we have introduced the Algonquin model in (8) and the Gaussian scale sum model in (11). Inference in these models is non-trivial and therefore in the next two subsections we will describe how to perform message passing-based inference in these models, such that we can automate message passing in the proposed generative models of Section 2.2. Furthermore we derive the node-local free energies for the automated evaluation of model performance using the variational free energy. Figure 8: Example of a situational sketch of (22) where a variational message \(\vec{v}(x_{j})\) flows out of an arbitrary node \(f(x_{1},\ x_{2},\ldots,x_{n})\) with marginals \(q(x_{\setminus j})\). 2.3.5. Message Passing-Based Inference in the Algonquin Model  
Exact inference in the Algonquin model of (8) leads to intractable inference, because the non-linear relationship leads to non-Gaussian distributions [9]. Approximate inference by variational message passing also results in difficulties. For the variational messages the expectation has to be determined over the mean term of (8). The expectation over this so-called log-sum-exp relationship has, however, no analytical solution and needs to be approximated as in [9; 48; 49]. Ref. [50] gives an overview of the available approximations methods. In this paper we will comply with the original approximation from [9]:  
\[\ln\left(\sum_{k=1}^{K}\exp(s_{k})\right)\approx\ln\left(\sum_{k=1}^{K}\exp(s_{ k})\right)\Bigg{|}_{s_{k}=E[s_{k}]}+\
abla_{s}\ln\left(\sum_{k=1}^{K}\exp(s_{k}) \right)\Bigg{|}_{s_{k}=E[s_{k}]}^{\top}(s-E[s]), \tag{24}\]  
where the notation of (8) is altered to prevent clutter. The subscript (and former superscript) \(k\) now denotes the source index and the frame and frequency bin indices are omitted. With this approximation, the mean of (8) is approximated using a first-order vector Taylor expansion. The function is linearly expanded around the mean of the constituent signals \(s_{k}\). Table 1 gives an overview of the Algonquin node of (8). This node has been generalized with respect to [9] to accommodate for more than 2 sources and to also allow for inferring the noise precision \(\gamma_{x}\).