{'fraction_non_alphanumeric': 0.03209206586826347, 'fraction_numerical': 0.009870883233532935, 'mean_word_length': 4.6231750624753385, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 2, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Provably Uncertainty-Guided Universal Domain Adaptation

Universal domain adaptation (UniDA) aims to transfer the knowledge of common classes from source domain to target domain without any prior knowledge on the label set, which requires to distinguish the unknown samples from the known ones in the target domain. Like the traditional unsupervised domain adaptation problem, the misalignment between two domains exists due to the biased and less-discriminative embedding in target domain. Recent methods proposed to complete the domain misalignment by clustering target samples with the nearest neighbors or nearest prototypes. However, it is dangerous to do so because both known and unknown samples may distribute on the edges of source clusters. Meanwhile, other existing classifier-based methods could easily produce overconfident predictions for unknown samples because the supervised objectives in source domain leads the whole model to be biased towards the common classes. Therefore, to deal with the first issue, we propose to exploit the distribution of target samples and introduce an empirical estimation of the probability of a target sample belong to the unknown class. Then, based on the estimation, we propose a novel unknown samples discovering method in the linear subspace with a $\delta$-filter to estimate the uncertainty of each target sample, which can fully exploit the relationship between the target sample and its neighbors. Moreover, for the second issue, this paper well balances the confidence values of both known and unknown samples through an uncertainty-guided margin loss. It enforces a margin to source samples to encourage a similar intra-class variance of source samples to that of unknown samples.


INTRODUCTION
Unsupervised domain adaptation (UDA) [1], [2], [3], [4], [5] aims to transfer the learned knowledge from the labeled source domain to the unlabeled target domain so that the inter-sample affinities in the latter can be properly measured. The assumption of traditional unsupervised DA, i.e., closed-set DA, is that the source domain shares identical label set with the target domain, which significantly limits its applications in real-world scenarios. Thus, relaxations to this assumption have been investigated. Partial-set DA (PDA) [6], [7], [8], [9] assumes that target domain is not identical to source domain but its subset. On the contrary, Open-set DA (ODA) [10], [11], [12] assumes that target domain contains classes unknown to the source domain such that the source domain is a subset of the target domain. Open-partial DA (OPDA) [13], [14], [15] introduces private classes in both domains respectively, where the private classes in the target domain are unknown, and assumes that the common classes shared by the two domains have been identified. Universal DA (UniDA) [13], [14], [16] concerns about unsupervised DA with the most general setting, where no prior knowledge is required on the label set relationship between domains.
Similar to the traditional UDA problem, the domain misalignment exits due to the biased and less-discriminative embedding which can mislead the knowledge transformation and lead to the incorrect classification. In UniDA problem, the label spaces of two domains are not exactly overlapped which magnifies the domain bias. Thus, besides the misalignment between source and target common samples, a main challenge of UniDA is distinguishing the unknown target samples and avoiding mismatching the target samples to the source private classes.
To deal with that, a popular method [14], [17], [18] is to complete the alignment between samples in common classes of both source and target domains and push the unknown samples away from common classes. For instance, Saito et al. [17] proposed a prototype-based method to move each target sample either to a prototype of a source class or to its target neighbors. Li et al. [14] solved this problem by replacing the classifier-based framework with a clustering-based one which exploited the intrinsic structure of samples and thus increased the inter-sample affinity in each cluster. Chen et al. [18] proposed a geometric anchor-guided adversarial and contrastive learning framework with uncertainty modeling and achieved the state-of-the-art (SOTA) by making samples from each domain closer to their neighbors in both source and target domains.
However, without any prior knowledge about unknown samples and source private classes, approaches [14], [17], [18] of completing the alignment between two domains are dangerous which can even magnify the misalignment. Compared to the inter-sample affinity in a known object class, that in the unknown class can be semantically much larger as the unknown class can contain samples that semantically belong to different object classes especially when the unknown set is large. This means that the inter-sample affinity between two samples in the unknown class could be even lower than that between a sample in the unknown class and a sample in a known object class. Moreover, due to the less-discriminative embedding, the inter-sample affinity between a known sample and unknown samples can be greater than that between it and samples in the same source class. As a result, some unknown samples could be easily pushed closer to one of the source classes incorrectly and some known samples can be clustered with the unknown samples which can aggravate the domain misalignment. As illustrated in Fig. 1, the distribution of some unknown samples (e.g. 'Pan' and 'Bed' images) can be too close to samples in source classes (e.g. 'Pencil' and 'Eraser' images) with high similarity on semantic. Thus, it is dangerous to complete the domain alignment without any prior knowledge about the distribution of unknown samples.
Another popular solution [13], [15], [16], [19] for UniDA is to employ a classifier which produces a confidence of each target sample or using the entropy of the prediction output by the classifier to determine whether it belongs to a particular known class seen in the source domain or the unknown class. They usually train their classifier on the source domain to generate confident predictions for target samples from common classes. However, the supervised objective in source domain can lead the whole model to be biased towards the common classes in the target domain, which can make the predictions of many unknown samples overconfident leading to the wrong classification and as mentioned by Chen et al. [18], the class competition nature may also cause the neural network to generate overconfident predictions for unknown instances. To deal with that, some recent approaches applied extra parameters to help classify the unknown samples, like Fu et al. [15] employed multiple classifiers to detect the target "unknown" samples by a mixture of uncertainties, Saito et al. [13] proposed to use an One-vs-All classifier to distinguish the unknown samples and Chen et al. [18] extended the softmax-based classifier to produce an energy-based uncertainty to determine the unknown samples.
To deal with the above two issues, we propose a novel UniDA framework to reduce the influence of the domain misalignment and balance the confidences of known and unknown samples to deliver a better classification performance. First, without relying on the predictions output by the classifier, we introduce a novel empirical estimation of the posterior probability of a target sample being 'unknown' through its the neighborhood searched in the source domain. And we prove that the proposed estimation is reliable theoretically. Based on the estimation of the posterior probability, it reveals that the consistency of the labels of neighbors searched from source domain and the distance between the target and its k-nearest neighbor are two keys to distinguish the known and unknown samples. Then, based on these two factors, we propose an uncertainty estimation scheme to discover unknown samples in the linear subspace with a δ-filter. In specific, the uncertainty estimation is employed to distinguish the known and unknown samples based on the consistency on labels of neighbors for a target sample. Projecting features in the original representational space into the linear subspace can both reduce the correlation of every two samples, which can make the unknown samples away from the edge of a source cluster. Then, in the subspace, the reliability of the neighbors has been improved. It further improves the accuracy of distinguishing the unknown and known sample through . Moreover, since the distance between a known sample and the centroid of a source class would not be significantly different from that between an unknown sample with the centroid, it is hard to find an optimal threshold to filter the discovered known samples through the k-nearest neighbor distance. Therefore, we propose to estimate the difference of the dispersion of two vector set respectively. One set contains the target sample and its most neighbors belonging to the same class and another set consists of there neighbors and a randomly selected sample from the same source class. The δ-filter can well estimate that if a target sample is compact enough with its most neighbors with the same label.
The classifier learning on supervised source samples can be biased to the source classes which can lead to an imbalance problem between intra-class variances of source domain and known/unknown target samples. Then, it leads to the overconfident predictions for unknown samples. To deal with that issue, we propose a novel uncertainty-guided margin loss (UAM) to encourage a similar intra-class variances of source domain to the mean of intra-class variances of discovered known samples and unknown samples for the current step by enforcing an uncertainty-guided margin to source samples. The margin is defined based on the confidence level of both known and unknown samples currently. A uniform loss is employed to generate an uniform class posterior distribution for unknown samples found by the unknown samples discovering to increase the entropy of the prediction. Notably, we do not introduce extra parameters to help the classification on unknown samples like the proposed methods usually do [7], [9], [13].
• We introduce an empirical estimation of the posterior probability of a target sample belonging to the unknown class which exploits the distribution of target samples in the latent representational space and theoretically prove the reliability of the proposed empirical estimation. • Based on the estimation of the posterior probability, we propose a novel neighbors searching method in the linear subspace where projecting features into the linear subspace can reduce the misalignment between source samples and unknown samples. • We further propose a δ-filter which can adaptively estimate the dispersion of a discovered known sample and its most neighbors belonging to the same class. • We propose a novel uncertainty-guided margin loss to balance the intra-class variances between source and target domains which can avoid the imbalance problem between the prediction of known samples and that of unknown samples.

RELATED WORK
We briefly review recent unsupervised DA methods in this section. According to the assumption made about the relationship between the label sets of different domains, we group these methods into three categories, namely PDA, ODA and UDA. We also briefly review a related problem named Out-of-Distribution detection to illustrate the relationship with our work.

Partial-set Domain Adaptation
PDA requires that the source label set is larger than and contains the target label set. Many methods for PDA have been developed [6], [7], [8], [9], [20]. For example, Cao et al. [20] presented the selective adversarial network (SAN), which simultaneously circumvented negative transfer and promoted positive transfer to align the distributions of samples in a fine-grained manner. Zhang et al. [8] [8] proposed to identify common samples associated with domain similarities from the domain discriminator, and conducted a weighting operation based on such similarities for adversarial training. Cao et al. [7] proposed a progressive weighting scheme to estimate the transferability of source samples. Liang et al. [9] introduced balanced adversarial alignment and adaptive uncertainty suppression to avoid negative transfer and uncertainty propagation.

Open-set Domain Adaptation
ODA, first introduced by Busto et al. [10], assumes that there are private and common classes in both source and target domains, and common class labels are known as prior knowledge. They introduced the Assign-and-Transform-Iteratively (ATI) algorithm to address this challenging problem. Recently, one of the most popular strategies [12], [21] for ODA is to draw the knowledge from the domain discriminator to identify common samples across domains. Saito et al. [11] proposed an adversarial learning framework to obtain a boundary between source and target samples whereas the feature generator was trained to make the target samples far from the boundary. Bucci et al. [16] employed self-supervised learning technique to achieve the known/unknown separation and domain alignment.

Universal Domain Adaptation
UniDA, first introduced by You et al. [19] is subject to the most general setting of unsupervised DA, which involves no prior knowledge about the difference on object classes between the two domains. You et al. also presented an universal adaptation network (UAN) to evaluate the transferability of samples based on uncertainty and domain similarity for solving the UDA problem. However, the uncertainty and domain similarity measurements are sometimes not robust and sufficiently discriminative. Thus, Fu et al. [15] proposed another transferability measure, known as Calibrated Multiple Uncertainties (CMU), estimated by a mixture of uncertainties which accurately quantified the inclination of a target sample to the common classes. Li et al. [14] introduced Domain Consensus Clustering (DCC) to exploit the domain consensus knowledge for discovering discriminative clusters on the samples, which differed the unknown classes from the common ones. OVANet [13], proposed by Saito et al., trained a one-vs-all classifier for each class using labeled source samples and adapted the open-set classifier to the target domain. Recently, Chen et al. [18] proposed a geometric anchor-guided adversarial and contrastive learning framework with uncertainty modeling and achieve the state-of-the-art (SOTA) by exploring a new neighbors clustering method to complete the domain alignment and extend the traditional softmax-based classifier to the energy-based classifier. However, all recent method ignore that adapting the domain misalignment between two domains are dangerous since we do not have any knowledge about the source private classes and the unknown target samples. Especially, they could not perform well in the scenario of the unknown set being large.

Out-of-Distribution Detection
Out-of-Distribution (OOD) detection aims to detect OOD samples during the inference process which is enlightening to the UniDA problem of detecting unknown samples. A baseline method by Hendrycks et al. [22] was proposed for detecting OOD samples with the output confidence. Later, some methods [23], [24], [25], [26] built the advanced detectors in a post-hoc manner. For example, Lee et al. [24] utilized the Mahalanobis distance between the test samples feature representations and the train samples. However, these methods require many labeled ID samples for training. Thus, there were some methods that focused on how to exploit unlabeled data for OOD detection. Hendrycks et al. [27] enforced the model to produce the low confidence output on the pure unlabeled OOD data. Some other works [28], [29], [30], [31], [32] employed self-supervised learning on the pure unlabeled ID data which could improve the detection performance. For instance, Sehwag et al. [32] combined contrastive learning and Mahalanobis distance for OOD detection. There was also a line of works [33], [34], [35] which employed deep generative models on the pure unlabeled ID data. However, all these methods require that the unlabeled data must be pure ID or OOD, which is hardly met in realistic applications. Recently, some methods [36], [37], [38] considered the class distribution mismatch between labeled and unlabeled data. The mismatched samples in the unlabeled data can be regarded as OOD samples.
Chen et al. [36] filtered out OOD samples in the unlabeled data with a confidence threshold and trained the model on the remaining data only. Yu et al. [37] proposed a joint optimization framework to classify ID samples and filter out OOD samples concurrently. Guo et al. [38] employed the bilevel optimization to weaken the weights of OOD samples. But these methods were developed for ID classification and there was no OOD sample during the inference process. Another work by Yu et al. [39] tried to utilize mixed unlabeled data for OOD detection. It encouraged two classifiers to maximally disagree on the mixed unlabeled data. However, each unlabeled sample was treated equally, hence the model still needed many labeled samples to distinguish between ID and OOD samples. We can obverse that many methods in OOD are similar with some recent UniDA methods like the self-supervised learning method [13] and the MixUp [40] method [18]. Moreover, the classifier-cased OOD method also needs to balance the confidences of ID and OOD samples which is similar to the UniDA problem.

METHOD
In this section, we first introduce the preliminaries of UniDA. Then we introduce an empirical estimation of the probability of a target sample belonging to the unknown class and the unknown samples discovering scheme in linear subspace. Finally, we elaborate the major components of in the training process which sufficiently avoids the influence of the domain misalignment and balances the confidences of known and unknown samples.

Preliminaries
We first establish preliminaries related to our method. Assume that we have the labeled set of source samples defined with the known space of the source label set Y s and the unlabeled set of target samples where N s and N t indicate the numbers of the source and the target samples, respectively. Since the label spaces of the two domains are not aligned, we have the space of the source label set Y s containing C classes and the target label set Y t = Y com ∪ Y unk . Y com and Y unk denote the spaces for the common label set and the unknown label set respectively and we denote the unknown class as C + 1 class. With the training on both domains and testing on target domain, our goal is to learn an optimal classifier D : Z t → Y s to categorize a target sample into an source class belonging to Y s and distinguish the unknown samples with the entropy of the prediction. Thus, it is important to identify the unknown samples in target domain.

Empirical Estimation of Unknown Samples
Unlike most existing methods [13], [15], [17], [19] relying on the posterior probability of a softmax-based classifier, we focus on the how target samples distribute in the latent representational space which is shared with source samples. And pre-classifying unknown samples is helpful to train a robust classifier. By leveraging the neighborhood information of target data, we are able to distinguish most of the unknown samples with a high accuracy. Theoretically we prove that our empirical estimation of the posterior probability p(y = C +1|z) is reliable.

Proposition 1.
With the feature set of samples from two domains Z s and Z t and a target features z ∈ Z t . Ifp C+1 (z; k) = c 1 l{max i=0,...,Cpi (z; k, k i | y = i) ≤ β} where k and k i are the number of neighbors and the number of neighbors belonging to class i, respectively. We have: If, Then, and c 0,1 , are non-zero constants. All samples in the feature space are normalized. Proof 1. We provide the proof sketch to show our key ideas which revolves around performing the empirical estimation of p(y = C +1|z).
First, since we have no idea which known class is the source private class, we denote: we estimate the posterior distribution of z belonging to one of source classes which is easier. By the Bayesian rule, the probability of z belonging to one of the source classes can be found as: : Then, the estimation of the p(y ∈ Y s | z) can boil down to deriving the estimations of probability density functions p 0 (z), . . . , p C+1 (z) Lemma 2. With k, k i and r k defined in Proposition 1, we can estimate the probability density function p i (z) as: Proof 2. Then, since z ∈ R m and all features are normalized where ||z|| = 1, all data points locate on the surface of a m-dimensional unit sphere. We set U r (z) = {||z − z|| 2 ≤ r} ∩ {z ∈ Z s }, which is a set of data points from source domain on the unit hyper-sphere centered in the z with a radius r. Assuming the density probability functions satisfy Lebesgue's differentiation theorem, the probability density function can be attained by: Then, we denote r k as the k-nearest neighbor distance which means the r k Euclidean distance away from center z and its k − th nearest neighbor. Then we get: With the denoting that B i is the smallest sphere contain- where Z s i is the set of all source sample belong to class i, we assume that: Then, we have: We assume the number of neighbors are big enough. Then we have the estimation |U r k (z) ∩ B i | = c 0 ki k where c 0 is a constant. Then the approximation ofp i (z; k) can be attained by:p where k i is the number of samples belonging to U r k and B i .
Then, another challenge of estimating p(y ∈ Y s |z) is computing p C+1 since we do not have a litter prior knowledge about unknown samples. The only knowledge we have is that samples not belonging to all the source classes belong to unknown class. Thus, we can attain: where β is a constant chosen to satisfy the equation. Then, Plus, when c 0 kmax k(r k ) m−1 > β, we have: Then, from the Proposition 1, when k max satisfies Eq. (1), upper boundary of the probability p(y = C + 1 | z) is positive correlation with the k-nearest neighbor distance r k , i.e., when k max and r k are big enough, the bigger r k means the bigger probability of a target sample being unknown.

Corollary 4.
A target sample z which can be identified as an unknown sample should satisfy the follow issues: • The neighbors of z should mostly belong to the same class.
• z should be close enough to its neighbors.
Notably, in ODA problem where the source label set is contained in the target label set, we can get the equation: Then, based on Eqs. (4) and (5), we can estimate the probability of a target sample belonging to one of the common classes reliably but in OPDA, Eq. (15) would not work any more because of the private source classes existing.

Discovering Unknown Samples in Linear Subspace with δ-Filter
Based on the two items mentioned in the Corollary 4, we propose an unknown samples discovering in the linear subspace method and a δ-filter to deal with two issues respectively which are named as Discovering unknown samples in the Linear Subspace and δ-Filter (DLSF) totally. Since some unknown samples can distribute in the edge of clusters of source classes and the domain discrepancy may lead to some known samples far away from the centers of source classes, clustering target samples with their nearest neighbors or nearest prototypes is dangerous in the original feature space. Therefore, we propose to find a reliable linear subspace to deal with the above problems and improve the accuracy of the unknown samples discovering based on the neighborhood information searched from source domain for each target sample. In specific, given Z s ∈ R Ns×m , Z s = [z 0 , z 1 , · · · , z Ns ] T and where m means the dimension of z i , are sets of all source samples and target samples in a mini-batch respectively, we denote the original feature set Z ∈ R n×m , Z = [z 0 , z 1 , · · · , z n , z t 0 , z t 1 , · · · , z t b ] where n = N s + m and .
Then, we have where P is a transformation matrix mapping the features with m dimensions to reduced features with p dimensions.
To get the subspace, we propose to analyze the covariance matrix of Z which is defined as: Notably, Z has been centralized. Inspired by Wang et al. [41], the covariance matrix captures the feature distribution of the training data, and contains rich information of potential semantic difference. We propose to decompose the covariance matrix Σ to find the dimensions which can mostly represent the difference on semantic information of each source class and cut off the other dimensions. Since the unknown target samples do not share the common features with share common features with known source classes. After the reduction of dimensions, the distances from an unknown sample to each source classes can be averaged which can lower k max in Eq. (1). Specifically, we leverage the singular value decomposition (SVD) method to decompose the covariance matrix A and get the transformation matrix P : To estimate the posterior distribution p(y = C + 1|z) by Theorem. 1, we first employ a memory bank M to store all features of source samples: we update the memory with a momentum scheme: By projecting the original features to the linear subspace, we propose to search neighbors of each target sample in the subspace. Particularly, with N for a target sample z ∈ R m , we propose an uncertainty score of z i according to Eq.(10): where k is the number of searched neighbors. Then, the discovered unknown samples are denoted as: where τ is set manually. Similarly, the known samples are denoted as: and z i ∈Ẑ k has pseudo labelŷ i .

δ-filter
As mentioned in the second item in Corollary 4, the target sample should be close enough to its neighbors. However, the 'nearest' neighbor is not equivalent to 'most compact' neighbor. For instance, for an unknown sample, which is far away from from all source classes, its 'nearest' neighbors can also mostly belong to the same class. It means that there are some noisy data inẐ k . Moreover, since known ones might also distribute on the edge of clusters of source classes, the distance from a centroid of a source class to a known sample might not be significantly different from the distance between the centroid and an unknown sample. Thus, it is hard to filter discredited known samples fromẐ k through the k-nearest neighbor distance with. Therefore we introduce a dynamical δ-filter scheme to remove the noisy data.
To be specific, as shown in Fig. 4, compared to the compaction of theŷ i class, a credible known sample z i ∈Ẑ k should be compact enough with its neighbors which belong toŷ i class. To estimate the compaction of z i and its neighbors, we apply the spectral decomposition on the covariance matrices of these vectors ( i.e., z i and its neighbors belonging toŷ i class) to get the max eigenvalue of the covariance matrices which can represent the dispersion of the vectors. Moreover, to get a comparable estimation of the dispersion of vectors in theŷ i class, we random select a sample from the sourceŷ i class which is not the neighbor of z i and compute the max eigenvalue of their covariance matrices (i.e., the selected vector and the neighbors belonging toŷ i class). We leverage the difference of the two eigenvalues to determine if z i is creditable.
In detail, for z i ∈Ẑ k we denote N i = {l 0 , l 1 , . . . , l n } as the neighbors of z i where samples in N i belong toŷ i class and n = |N i | > τ . And l n +1 means the selected source sample. Next, we can denote two zero-mean matrices defined as: X i = centralize([l 0 , l 1 , . . . , l n , l n +1 ]), Then, we can get the covariance matrices of both sets: We leverage spectral decomposition on both covariance matrices to get max eigenvalues, which can best represent the dispersion of each vector sets. We denote λ i andλ i as the max eigenvalues of Σ i andΣ i respectively. Finally, we define the difference value δ as: When δ is big, it means that joining z i has significant bad influence on the description of the vector set and z i should be filtered out ofẐ k . We assume that a credible known target sample should satisfy δ i ≤ 0.2λ i .

Learning
Since the classifier is trained to categorize a target sample into one of the source classes with highly confidence and distinguish target samples belonging to unknown class via the entropy of the outputs. Thus, the training of classifier D involves a trade-off: maximizing classification performance on Z com and preventing overconfident predictions on Z unk . With denoting W = [W T 0 , W T 1 , . . . , W T Y s ] as the weights of linear classifier, a traditional method [7], [13], [14] to improve the classification performance by training the classifier in the source domain and most of them employ a cross-entropy loss: where W T yi But this method can usually lead to the overconfident predictions on unknown samples [9]. To deal with the problem, Cao et al. [7] aggregated multiple complementary uncertainty measures, OVANet [13] employ an one-vs-all classifier for unknown samples discovering and GATE [9] proposed an energy-based classifier by extending the traditional softmax-based classifier to improve the classification performance on distinguishing the unknown samples. In this work, without applying extra parameters, we propose a more efficient method to train only one classifier via three losses.

Uncertainty adapted margin loss (UAM)
Since using the traditional CE loss training on source domain creates an imbalance problem between the known and unknown classes for target samples. Learning on source classes Y s is much faster than that on the unknown class Y unk due to the supervised objective which leads the whole model to be biased towards the common classes Y s in target Append z t i intoẐ k Apply δ-filter onẐ k Compute L sup based on Eq. (30) Compute the margin µ based on Eq.(28) Compute L margin based on Eq. (27) Compute L t based on Eq. (29) Compute the overall loss L all Update the model domain. In result, the intra-class variance of source domain can be much smaller than that of known samples or that of unknown samples. The predictions of many unknown samples can be overconfident. Therefore, it is important to balance the intra-class variances of both domains. We propose a new uncertainty adapted margin loss (UAM) to achieve that. At the beginning of the training, we enforce a larger margin to encourage a larger intra-class variance which is similar to the intra-class variance of discovered unknown samples while the margin goes down to zero close to the end of the training.
where µ is the intra-class variance ofẐ unk which is defined as: where | · | means the number of elements in a set. Notably, we normalize the weights and inputs, i.e.,

Unknown loss
Since we use the entropy of the classifier output to distinguish the unknown samples, to lower the confidence of unknown samples belonging toẐ unk , we employ the loss to a uniform class posterior distribution for unknown inputs to increase the entropy: where the inputs of Eq. (29) belong to the discovered unknown samples setẐ unk .

Supervised contrastive loss on source domain
Moreover, to reduce the influence of the domain misalignment, it is necessary to make each source class more compact and discriminative to enlarge the gap between two source classes which can improve the consistency of neighbors' labels for a target sample when it searches the nearest neighbors from source domain. Thus, we employ a supervised contrastive learning loss [39] L sup to make data points from source domain more compact by pushing the samples from different classes away while pulling the samples from the same class closer. L sup is given by: where A + i and A − i represent the positive samples in M with the same label as z i and the negative samples searched from M . t is a temperature parameter.

Total loss and algorithm
The total training loss of our method can be computed as where λ is a weighting parameter. Moreover, the full algorithm of our method is provided in Algorithm 1.

EXPERIMENTAL RESULTS
In this section, we first introduce our experimental setups, including datasets, evaluation protocols and training details. Then, we compare our method with the SOTA UDA methods. We also conduct extensive ablation studies to demonstrate the effectiveness of each component of the proposed method. All experiments were implemented on one RTX2080Ti 11GB GPU with PyTorch 1.7.1 [43].

Datasets and evaluation protocols.
We conduct experiments on four datasets. Office-31 [44] consists of 4, 652 images from three domains: DSLR (D), Amazon (A), and Webcam (W). OfficeHome [45] is a more challenging dataset, which consists of 15, 500 images from 65 categories. It is made up of 4 domains: Artistic images (Ar), Clip-Art images (CI), Product images (Pr), and Real-World images (Rw). VisDA [46] is a large-scale dataset, where the source domain contains 15, 000 synthetic images and the target domain consists of 5, 000 images from the real world.
In this paper, we use the H-score in line with recent UDA methods [13], [14], [15]. H-score, proposed by Fu et al. [15], is the harmonic mean of the accuracy on the common classes a com and the accuracy on the unknown class a unk :

Training details.
We employ the ResNet-50 [47] backbone pretrained on ImageNet [48] and optimize the model using Nesterov momentum SGD with momentum of 0.9 and weight decay of 5×10 −4 . The batch size is set to 36 through all datasets. The initial learning rate is set as 0.01 for the new layers and 0.001 for the backbone layers. The learning rate is decayed with the inverse learning rate decay scheduling. The number of neighbors retrieved is set to be dependent on the sizes of the dataset. For Office-31 (4, 652 images in 31 categories) and OfficeHome (15, 500 images in 65 categories), the number of retrieved neighbors |N i | is set to 10. For VisDA (20, 000 images in total), we set |N i | to 100 , respectively. We set λ to 0.1 and t to 0.05 which are constant through all the datasets. In the test phase, the threshold of distinguishing the unknown samples is set to log C 2 following DANCE [17] which used the entropy of the classifier output to determine the unknown samples.

Baselines.
We aim to show that our method can better balance the confidences of known and unknown samples for UniDA by comparing our method with the current SOTA methods, such as UAN [19] and DANCE [17], which employed a softmax-based classifier to produce the confidence of each sample to determine whether it belongs to the unknown class or not. Also, we compare our method with DANCE [17], DCC [13] and GATE [18] to show that it is more effect to adapt the domain misalignment through the dimensional reduction rather than completing it in the original feature space.

Results in main datasets.
Tables 1 and 2 list the results on Office-31 with OPDA setting and ODA setting respectively. Tables 3 and 4 list the results on OfficeHome and Visda both with OPDA setting and ODA setting, respectively. On Office-31, our method outperforms the SOTA methods by 1.2% in terms of the H-score on average with OPDA setting and made a significant improvement of 2.0% in terms of the H-score on average with ODA setting. For the more challenging dataset OfficeHome which contains much more private classes than common classes, our method also made a significant improvement of 1.0% in terms of the H-score. Our method consistently performs better than other methods. VisDA is a much larger dataset than Office-31 and OfficeHome which contains about 10000 images in each domain.

Summary.
According to the results of quantitative comparisons, our method achieves the SOTA performance in every dataset and most subtasks, which demonstrates the main idea of our method that adapt the domain misalignment through dimensional reduction and balance the confidences of known and unknown samples by controlling the gradient updating of learning on the source domain.

A closer look at the unknown samples discovering
How to choose the confidence for unknown samples discovering By Theorem 1, the posterior probability of a target sample belonging to the unknown class depends on the biggest number of neighbors belonging to the same  class. Thus, we compare the proposed unknown samples discovering scheme with the discovering based on the knearest neighbor distance in this part. First, we collect the k-nearest neighbor distances of all target samples in an early epoch in Office-31 which is be more influential for the whole training. As shown in the first row in Fig. 5, the distributions of known samples are not distinguishable enough especially in A2W, D2A and W2A. It is obvious that the k-nearest neighbor distance is not reliable enough to discover the unknown samples. Moreover, the optimal thresholds for each subtasks are different and hard to choose. Notably, mapping samples into the linear subspace has the significant influence in uniforming the distribution of data points and make them more sparse as shown in the second row in Fig. 5. However, it is helpless to improve the discrimination of unknown samples based on the k-nearest neighbor distance. By contrast, the distributions of confidences defined by the biggest number of neighbors belonging to the same class illustrated in the first row of Fig. 8 are much more distinguishable.

Original feature space VS Linear subspace
The purpose of extracting a linear subspace is to make the distribution of data points more sparse and uniform to avoid the influence of the domain misalignment. Comparing the charts in the first row and the second row in Fig. 5, it is obviously that the data points in the subspace are similar in the distribution of the k-nearest neighbor distances. In Fig. 8, we conduct experiments on Office-31 to compare the distributions of the confidences produced by the proposed unknown samples discovering method in the original feature space (First row) and the linear subspace (Second row). Apparently, the distributions of confidences in the subspace are much more distinguishable than that in the original feature space where the overlaps between unknown and known samples are much fewer in the subspace which is benefited by reducing the misalignment between target samples and source samples.

Accuracy of the proposed unknown samples discovering
We also conduct experiments on the accuracy of the unknown samples discovering on the original feature space and the subspaces with different dimensions on some subtasks of Office-31 and OfficeHome where we plot the histograms of the accuracy of the unknown samples discovering in Fig. 6. The accuracy unknown samples discovering is consistently detected with high accuracy which far surpasses 80% on average and the performance of accuracy of unknown samples discovering in the subspace is much better than that in the original feature space. Thus, through the proposed unknown samples discovering scheme, our approach finds the unknown samples in the target domain reliably.

Uncertainty-guided margin loss VS CE-loss
To show the effect of the uncertainty-guided margin loss on balancing the predictions of known and unknown samples, we track the entropy level of unknown samples and the confidence level of known samples following the training process on Office-31. We recorded the mean value of entropies of predictions for unknown samples and the mean value of maximum prediction confidences output by the classifier after softmax of each known samples in every steps. For comparison, we first plot records where the classifier was only trained on source domain with a traditional CE-lass like Eq. 26 in the first row of Fig. 9. We can observe that although the known samples have high confidence consistently, the unknown samples are significantly overconfident during the training. In the second row of Fig. 8, we plot the records using the CE-loss and proposed KL divergence loss as Eq. 29. The entropy level has been improved but the overconfidence of unknown samples is still serious. In the third row of Fig. 9, we plot the records using the proposed uncertainty-guided loss which can perfectly distinguish the unknown samples with entropy while keeping the known samples with highly confident he predictions. Notably, to better show the effect of the proposed losses, we only compute the mean entropy of the detected unknown samples updated by the unknown loss in the second row charts. We also employ t-SNE [50] pictures to visualize the distributions of target samples in Fig. 7. We can obverse that the distribution of data points in ours (right) is much more discrimative than that of DANCE [17](mid) and the model training with the source dataset only (left).

Setting of uncertainty-guided margin
To show the effect of the uncertainty-guided margin selection scheme, we compare it with the human-picked thresholds on Office-31(A2D, D2A) and OfficeHome(R2C). From Fig. 10(a), we can observe that it is difficult to choose a consistently optimal threshold for all datasets and subtasks as the model is sensitive to the thresholds. [49]. Table 5 shows the quantitative comparison with the ODA setting on Office-31 using VGGNet [49] instead of ResNet50 as the backbone for feature extraction. According to the results, we demonstrate that our method is also effective with another backbone without changing any hypeparameters.

Hyper-parameters
There are only one hyper-parameter λ in our model. To show the sensitivity of λ in the total loss, we conducted experiments on Office-31 with the UDA setting. Fig. 10(b) shows that our method has a highly stable performance over different values of λ.

CONCLUSION
In this paper, we propose a new framework to reduce the influence of the domain misalignment and balance the predictions of known and unknown target samples. Its core idea is to estimate the probabilities of target samples belonging to the unknown class by the biggest number of neighbors with the same label searched from the source domain and detect the unknown samples via mapping the features in the original feature space into a linear subspace to make the data points more sparse and discriminative which can reduce the influence of domain misalignment. Also, our method well balance the confidences of known target samples and unknown target samples via an uncertainty-guided margin loss. As demonstrated by extensive experiments, our method sets the new SOTA performance in various subtasks on four public datasets.