# Inferring Urban Social Networks from Publicly Available Data
## 2 Materials and Methods
### Friendship Edges  
As said, the age labels define a partition of the vertex set \(V\) into \(n\) disjoint subsets \(V_{1},\ldots,V_{n}\). For each possible pair of groups \((V_{i},V_{j})\), the number of pairs of vertices \((u,v)\) such that \(u\in V_{i}\) and \(v\in V_{j}\) is  
\[m_{ij}= \begin{cases}|V_{i}|\cdot|V_{j}|&\text{if }i\
eq j\\ \frac{|V_{i}|\cdot(|V_{j}|-1)}{2}&\text{if }i=j\end{cases} \text{ with }\sum_{i\leq j}m_{ij}=\frac{N \cdot(N-1)}{2}, \tag{1}\]  
where \(|V_{i}|\) is the cardinality of \(V_{i}\). Each pair \((V_{i},V_{j})\) is also characterized by a mutual preference coefficient \(s_{ij,j}\in[0,1]\). For the scope of the present paper, we estimate the coefficients \(s_{ij,j}\) relying on the recent SOCRATES project [16] that makes it possible to easily extract aggregated social contact matrices from public available and well-established datasets. In Appendix B, we describe how we constructed the matrix \(S=\{s_{ij}\}\), and we show that any constant \(S\) corresponds to a condition of _age-homogeneous mixing_, i.e., to edge occurrence being independent of the age. To each pair \((u,v)\in V\times V\), we finally associate a distance \(d(u,v)\) computed based on the tile labels \(t_{u}\) and \(t_{v}\) as explained in Section 2.1. For each possible pair of vertices \(u,v\) that do not belong to the same household, the existence of the edge \((u,v)\) in the friendship graph \(G_{F}\) depends on the outcome of a Bernoulli trial with parameter \(\Pr[u,v]=\Pr[(u,v)\in E_{F}]\), defined as follows:  
\[\Pr[u,v]=\frac{\mu\cdot N}{2}\cdot\frac{m_{g_{u}g_{v}}\cdot s_{g_{u}g_{v}}}{ \sum_{i\leq j}(m_{i,j}\cdot s_{ij})}\cdot\frac{D(u,v)\cdot f_{u}\cdot f_{v}}{ \sum_{u^{\prime}\in V_{g_{u}},v^{\prime}\in V_{g_{v}}}(D(u^{\prime},v^{\prime })\cdot f_{u^{\prime}}\cdot f_{v^{\prime}})}, \tag{2}\]  
where \(\mu\) is a configuration parameter. In line with the guiding principles illustrated in Section 1, \(Pr[u,v]\) is set proportional to: \((i)\) the data-driven cohesion of groups \(g_{u}\) and \(g_{v}\), given by \(s_{g_{u},g_{v}^{\prime}}(i)\) the imposed distance-based penalization, quantified by \(D(u,v)\); and \((iii)\) the sociability of \(u\) and \(v\), measured by \(f_{u}\) and \(f_{v}\). By construction, (2) guarantees that, on average for the entire graph \(G_{F}\), the age-based social mixing determined by the matrix \(S\) is respected, and the average number of friends, i.e., the average degree of the graph \(G_{F}\), is exactly \(\mu\). These and other aspects related to the interpretation of (2) and the characteristics of \(G_{F}\) are discussed in the following. **A different expression for \(\Pr[u,v]\):** To each pair of age groups \((i,j)\) with \(i\leq j\), we can associate a subgraph as follows: if \(i=j\), \(G_{F}(i,i)=(V_{i},E_{F,i,j})\) is the subgraph of \(G_{F}\) induced by the vertices in \(V_{i}\); if \(i\
eq j\), \(G_{F}(i,j)=(V_{i}\sqcup V_{j},E_{F,i,j})\) is the _bipartite_ subgraph of \(G_{F}\) induced by the vertices in the disjoint union \(V_{i}\sqcup V_{j}\) and where only edges \((u,v)\) such that \(u\in V_{i}\) and \(v\in V_{j}\) are admissible. It is easy to verify that \(G_{F}\) is the disjoint union of these subgraphs, that is, \(E_{F}=\sqcup_{i\leq j}E_{F,i,j}\). By construction, \(E_{F,i,j}\leq m_{i,j}\) and, if the edge probability was uniquely determined by \(s_{i,j}\), the expected value of \(|E_{F,i,j}|\) would be \(M(i,j)=m_{ij}\cdot s_{ij,j}\), whereas the expected value of \(|E_{F}|\) would be \(M=\sum_{i\leq j}M(i,j)\). Let us define the _attraction_ between \(u\) and \(v\) as \(a(u,v)=D(u,v)\cdot f_{u}\cdot f_{v}\) and the _total attraction_ between groups \(i\) and \(j\) as \(A(i,j)=\sum_{u\in V_{i},v\in V_{j}}a(u,v)\).