# Extending Partial Domain Adaptation Algorithms to the Open-Set Setting
## 3 Theory and Methodology  
The upshot of OSDA is the development of methods for partially labeling an unlabeled dataset by using a model trained on a related dataset. Unlike typical DA, we assume that there exist target instances with labels that are not contained in the source label space, i.e., outlier instances. We are interested in identifying those instances so as to ignore them during the adaptation procedure. The rest of the instances, i.e., transfer-relevant ones, can potentially be reliably labeled through the adaptation procedure. As in typical DA works, we also assume a machine learning problem described by a domain \(\mathcal{D}=\{\mathcal{X},\mathcal{X}\}\) and a task \(\mathcal{T}=\{\mathcal{Y},\mathcal{Y}|X\}\), where \(X\) is a random variable (the covariates) taking values in \(\mathcal{X}\) and \(Y\) is a random variable (the labels) taking values in \(\mathcal{Y}\). We assume the existence of two problems \((\mathcal{D}_{\mathcal{S}},\mathcal{T}_{\mathcal{S}})\) and \((\mathcal{D}_{\mathcal{T}},\mathcal{T}_{\mathcal{T}})\), where (a) \(\mathcal{X}_{\mathcal{S}}=\mathcal{X}_{\mathcal{T}}\) and (b) \(Pr(X_{\mathcal{S}})\
eq Pr(X_{\mathcal{T}})\). In the OSDA setting, we assume that \(\mathcal{Y}_{\mathcal{S}}\cap\mathcal{Y}_{\mathcal{T}}\
eq\emptyset\) and  
\[P(Y_{\mathcal{S}}=y\mid X_{\mathcal{S}}=x,y\in\mathcal{Y}_{\mathcal{S}}\cap \mathcal{Y}_{\mathcal{T}})=Pr(Y_{\mathcal{T}}=y\mid X_{\mathcal{T}}=x,y\in \mathcal{Y}_{\mathcal{S}}\cap\mathcal{Y}_{\mathcal{T}})\;. \tag{1}\]  
Our aim is to align the distributions of instances in the source and target domains with labels in \(\mathcal{Y}_{\mathcal{S}}\cap\mathcal{Y}_{\mathcal{T}}\). Moreover, we want to identify instances that are _probably_ transfer relevant with respect to some confidence measure or heuristic. In the following, we describe DIWAN. Specifically, five neural networks are used: the source and target representer networks \(M_{\mathcal{S}},M_{\mathcal{T}}\), a _re-weighting network_\(\mathcal{W}\), a _constrained_ domain discriminator \(D\), and a source classifier \(C\). \(M_{\mathcal{S}}\) and \(C\) are pre-trained in a standard supervised way on the source dataset. The target representer is typically initialized as \(M_{\mathcal{S}}\). During training, weights are assigned to each instance \(x\). These are:  
\[w^{\mathcal{S}}(x):=\frac{1-\mathcal{W}(M_{\mathcal{S}}(x))}{1-E[\mathcal{W}( M_{\mathcal{S}}(x))]},\;w^{\mathcal{T}}(x):=\frac{\mathcal{W}(M_{\mathcal{T}}(x))}{ E[\mathcal{W}(M_{\mathcal{T}}(x))]}\;, \tag{2}\]  
Figure 1: Alignment with source and target outliers. (**Left**): Source and target domain distributions. The blue dashed line denotes a decision boundary _before_ adaptation. (**Right**): The effect of adaptation; common labels align, while source/target outlier instances are mainly ignored. This is best viewed in color. for the source and target, respectively. These choices are explained in the next section. \(W^{5},W^{T}\) denote the collection of weights for a fixed \(M_{S},M_{T}\) and \(\mathcal{W}\). The expectation above is estimated by averages over mini-batches. The objective function used is  
\[\min_{\mathcal{W}}\,\mathcal{L}_{\mathcal{W}}=-E_{x_{S}\sim X_{S}}[\log( \mathcal{W}(M_{S}(x_{S})))]-E_{x_{T}\sim X_{T}}[\log(1-\mathcal{W}(M_{T}(x_{T}) ))]. \tag{3}\]  
For \(\mathcal{W}\) and for \(M_{T},D\), we have, given \(W^{S},W^{T}\),  
\[\max_{M_{T}}\,\min_{D}\,\mathcal{L}=-E_{x_{S}\sim X_{S}}[W^{S}\log(D(M_{S}(x_{S })))]-E_{x_{T}\sim X_{T}}[W^{T}\log(1-D(M_{T}(x_{T}))]. \tag{4}\]  
Here, \(W^{S}(x),W^{T}(x)\) is used to emphasize that the weights are computed for all instances before \(M_{T}\) is updated. The pseudocode for DIWAN is provided in Algorithm 1. A visual overview of the five neural networks and the training procedure is illustrated in Figure 2.  
Figure 2: Illustration of the five neural networks involved in the DIWAN algorithm. On the **top**, the re-weighting network is trained from the source and target representer network representations of the source and target data, respectively.