## 2 Materials and Methods
### Methods  
#### 2.2.1 Disentangled Autoencoder  
In general, an autoencoder consists in two main blocks (networks): an _encoder_ and a _decoder_ which are designed to perform (i) encoding of the input data into a lower dimensional latent embedding, and (ii) reconstruction of the input from the lower dimensional space. This can be seen as a composition of two functions such that the output \(x^{\prime}=f_{d}(\theta;f_{e}(\phi;x))\) where \(f_{e}(\phi;\cdot)\) and \(f_{d}(\theta;\cdot)\) are the encoder and decoder functions, respectively, and \(\phi\) and \(\theta\) are their corresponding parameters that are learned through an optimization process (Figure 1). The objective function for this optimization process could be, for example, the mean squared error or the cross entropy. The main goal when designing an autoencoder is to obtain a latent representation \(z\) of the input which captures the main traits of the modelled domain that generalise well to unseen data while being robust to noise. The encoded sample \(z\) can be obtained by drawing a sample from a multinormal distribution:  
\[N_{x}\sim N(\mu_{x},\Sigma_{x}),\text{ with }\Sigma_{x}=(\Sigma_{x}^{LT}) \Sigma_{x}^{LT}, \tag{1}\]  
thereby yielding better generalization properties [20]. Several variants of the basic autoencoder have been proposed, including denoising autoencoder [21] and sparse autoencoder [22]. In the present work, the model is based on the \(\beta-\)variational autoencoder [23] for disentangled representation learning. The latent loss from the original variational autoencoder formulation by [PERSON] and [PERSON] [20] is multiplied with a constant value \(\beta>1\). This additional weighting factor promotes independence of the latent dimensions as it enforces stronger similarity between the learned distribution and the standard multivariate normal prior. Independence between individual dimensions results in more disentangled features [24]. The basic components, namely the encoder, sampler, and decoder, are extended by a classifier and a discriminator, leveraging the class label information. In the context of differently stained histology images, the class label denotes the domain of the data (i.e., H&E or type of immune stain: CD44, FOXP3, etc.). The overall model architecture is depicted in Figure 1. Let \(\chi\) be the set of categories in the data, with \(|x|\)  
Figure 1: Architecture for the proposed model, extending the \(\beta\)-Variational Autoencoder with a supervised classifier and discriminator component. denoting the set cardinality, i.e., the number of different categories. The classifier is trained to predict the class label distribution  
\[q_{\psi}(\overline{y}_{s}|\underline{z}_{s})=\sigma(\hat{y}_{s})_{i}=\frac{e^{ \hat{y}_{si}}}{\sum_{j=1}^{K}e^{\hat{y}_{si}}} \tag{2}\]  
From activations \(\hat{y}_{s}\) approximating the true label \(y\in\chi\) from a subspace of the latent code \(z_{s}\) for an input \(x\). Therefore, it serves as a measurement of class-related information contained in the code subset. The discriminator works in an equivalent way on the complementary subspace of the latent code, \(z_{m}\), predicting the same label. The difference lies in how the loss terms are used in updating the model parameters. The weights of the individual network components, parameterized by \(\Phi\), \(\psi\), \(\phi\), and \(\theta\) for the encoder, classifier, discriminator, and decoder respectively, are optimized with different objective functions during joint model training.