## 3 Agwan: A Generative Model for Labelled, Weighted Graphs
### Parameter Fitting
Denoting \(\textbf{Z}=\{z_{1},\ldots,z_{N}\}\) and assuming the indication vectors are independent given the mixing coefficients, the conditional distribution of \(Z\) given \(P\) is:  
\[f(Z|P)=\prod_{n=1}^{N}\prod_{m=1}^{M}p_{m}^{z_{nm}} \tag{8}\]  
Introducing the Dirichlet distribution as the prior distribution of the mixing coefficients, the probability function of \(P\) can be written as:  
\[f(P)=Dir(p|c)=C(\textbf{c})\prod_{m=1}^{M}p_{m}^{c_{m}-1} \tag{9}\]where \(C(\mathbf{c})=\frac{\Gamma(\widehat{c})}{\Gamma(c_{1})\cdots\Gamma(c_{M})}\) and \(\widehat{c}=\sum_{m=1}^{M}c_{m}\). We consider the observation \(\mathbf{x}_{n}\) and the unobserved indication vector \(\mathbf{z}_{n}\) as the _complete_ data. The conditional distribution of \(X=\{\mathbf{x}_{1},\ldots,\mathbf{x}_{N}\}\) and \(Z=\{\mathbf{z}_{1},\ldots,\mathbf{z}_{N}\}\) given the latent variables \(\{A,B,P\}\) is:  
\[ \begin{split}& f(\mathbf{X},\mathbf{Z}|\mathbf{A},\mathbf{B}, \mathbf{P})\\ =& f(\mathbf{X}|\mathbf{A},\mathbf{B},\mathbf{P}, \mathbf{Z})f(\mathbf{Z}|\mathbf{P})\\ =& f(\mathbf{X}|\mathbf{A},\mathbf{B},\mathbf{Z})f( \mathbf{Z}|\mathbf{P})\\ =&\prod_{n=1}^{N}\prod_{m=1}^{M}\left[p_{m}\mathbf{ Beta}(\mathbf{x}_{n}|\mathbf{a}_{m},\mathbf{b}_{m})\right]^{z_{nm}}\end{split}  \tag{10}\]  
The algorithm for Bayesian estimation of a BMM model is presented in Algorithm 2. An overview of the derivation of the algorithm from Equations (5)-(10) can be found in Appendix A. For full details of the derivations, refer to [26]. ```
0: Number of components \(M\), initial parameters for the Dirichlet distribution, initial parameters (element-wise) \(\alpha_{0}>0\), \(\beta_{0}>0\), \(\mu_{0}>0.6156\), \(\
u_{0}>0.6156\). Select initial parameters such that \(\mu_{0}/\alpha_{0}>1\) and \(\
u_{0}/\beta_{0}>1\). 1: Initialise \(r_{nm}\) with \(k\)-means
2: Calculate the initial guess of \(\overline{a}\) and \(\overline{v}\) from \(\alpha_{0},\beta_{0},\mu_{0},\
u_{0}\)
3:repeat
4: Update the hyperparameters \(c_{m}^{*}\), \(\mu_{lm}^{*}\), \(\alpha_{lm}^{*}\), \(\
u_{lm}^{*}\) and \(\beta_{lm}^{*}\)
5:until convergencereturn the current estimated hyperparameters
```  
**Algorithm 2** Bayesian estimation of a Beta Mixture Model (BMM)  
After initialisation (lines 1,2), Algorithm 2 iterates until the the current estimated model and the previous estimated model are sufficiently close (lines 3-5). The order of updating (line 4) does not matter, but each hyperparameter should be updated exactly once during each iteration. Refer to Appendix A for details of how the intermediate quantities are calculated (\(c_{m}^{*}\) is updated following Equation (A3), \(\mu_{lm}^{*}\) from Equation (A4), \(\alpha_{lm}^{*}\) from Equation (A5), \(\
u_{lm}^{*}\) from Equation (A6) and \(\beta_{lm}^{*}\) from Equation (A7). The expectations for these quantities are given in Equation (A8).) The algorithm returns the current estimated hyperparameters at the last iteration, which are used to get the approximating posterior distribution. The joint posterior distribution of \(a_{lm},b_{lm}\) (Equation (4)) is approximated by the product of two gamma distributions with parameters \(\mu_{lm}^{*},\alpha_{lm}^{*}\) and \(\
u_{lm}^{*},\beta_{lm}^{*}\) (Equations ( 5 ) and ( 7)). Agwan parameter fitting is performed by Algorithm 3. First, we estimate the vertex label priors (lines 1-3); Next, we sample the edge weights for each possible combination of vertex label values (lines 5-10); The proportion of non-edges is used to estimate the weight of mixture \(0\) (line 10). We estimate each scaled BMM \(\Omega^{ij}\) from the appropriate set of samples \(W^{ij}\) using Algorithm 2 as described above (lines 12-13). Finally, the mixture weights \(\omega_{m}^{ij}\) are normalised so that they sum to \(1\) (line 14).