{'fraction_non_alphanumeric': 0.03472482717967955, 'fraction_numerical': 0.011628530089491452, 'mean_word_length': 4.966906474820144, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Semantic-Discriminative Mixup for Generalizable Sensor-based Cross-domain Activity Recognition

It is expensive and time-consuming to collect sufficient labeled data to build human activity recognition (HAR) models. Training on existing data often makes the model biased towards the distribution of the training data, thus the model might perform terribly on test data with different distributions. Although existing efforts on transfer learning and domain adaptation try to solve the above problem, they still need access to unlabeled data on the target domain, which may not be possible in real scenarios. Few works pay attention to training a model that can generalize well to unseen target domains for HAR. In this paper, we propose a novel method called Semantic-Discriminative Mixup (SDMix) for generalizable cross-domain HAR. Firstly, we introduce semantic-aware Mixup that considers the activity semantic ranges to overcome the semantic inconsistency brought by domain differences. Secondly, we introduce the large margin loss to enhance the discrimination of Mixup to prevent misclassification brought by noisy virtual labels. Comprehensive generalization experiments on five public datasets demonstrate that our SDMix substantially outperforms the state-of-the-art approaches with 6% average accuracy improvement on cross-person, cross-dataset, and cross-position HAR.


INTRODUCTION
Sensor-based human activity recognition (HAR) aims to train machine learning models to recognize human activities based on different sensor data such as accelerometer and gyroscope. HAR has wide applications in many areas including senior care, rehabilitation, and personal fitness [10,31]. Machine learning HAR models, especially deep learning-based models, often need large amounts of well-labeled data for training. However, it is expensive and time-consuming to collect or annotate massive labeled data in real applications. Even if there exist sufficient data for training, the performance of models may still deteriorate when applied to a new environment with different data distributions. For instance, a model trained on the activity data collected from the elderly cannot be directly used for adults because of the difference in their body size, activity patterns, and other characteristics.  As shown in Figure 1, the sensor data collected during walking follow different distributions. From Figure 1(a), we can see data of the adult is more stable than data of the elderly when walking. And Figure 1(b) demonstrates that there exist differences between data collected from two positions of one person at the same time. Therefore, directly applying a model trained from existing data to a new environment may suffer from dramatic deterioration caused by distribution shifts.
Domain adaptation (DA) [19,36] is a popular technique to transfer the knowledge from a well-labeled source domain to a target domain while reducing their distribution discrepancies. Over the years, DA has been successfully applied to HAR by either aligning feature distributions via different distances [34] or adversarial training [5]. Nevertheless, DA needs access to the target data in training. This may be less realistic in modern applications where we often expect a trained HAR model to perform well in different situations such as different environments, people, and datasets. Recently, domain generalization (DG) [33] is gaining increasing attention. In contrast to DA, the goal of DG is to learn a model from one or several different but related domains that will generalize well on unseen target domains. For example, we expect a DG algorithm that trains on activity data from diverse ages to be able to generalize well to new persons of different ages. Existing literature on DG is mainly based on data augmentation [35], domain-invariant learning [8], or meta-learning [2]. Since HAR applications often require computation-restricted devices, we are interested in data augmentation-based DG methods for their simplicity and effectiveness.
Mixup [42] is a popular data augmentation method and has been applied to DG [35,40]. Mixup enlarges the diversity of training data by interpolating between different domains. However, the generalization performance of Mixup-based DG can be undermined because of two challenges: semantic inconsistency and discriminative slackness. Firstly, the distributions of different activities are lying on different semantic spaces while direct Mixup will overlook their different semantic characteristics, resulting in semantic inconsistency between classes. Secondly, the interpolation of mixup can easily generate noisy data, which will decrease discriminations of the activity classifier.
In this paper, we propose SDMix, a Semantic-Discriminative Mixup approach for generalizable sensor-based HAR. To prevent semantic inconsistency, SDMix utilizes a semantic-aware Mixup technique to prevent classification boundaries from approaching the activity categories with large distribution shifts. We introduce activity semantic range for HAR that corresponds to the statistical values of activity shifts in the original space or feature space. Therefore, this technique can eliminate negative effects brought by different semantic ranges of different activities. Then, to handle discriminative slackness, SDMix introduces the large margin loss to replace the original cross-entropy loss. Through the large margin loss, each class is far away from each other, which means most virtual data points will locate between classes and induce less noise.
To sum up, our contributions are as follows: (1) We explore Mixup for generalizable human activity recognition and empirically observe two limitations of Mixup: the semantic inconsistency and discriminative slackness, which undermine the performance of Mixup for domain generalization. (2) We propose SDMix to handle the semantic inconsistency and discriminative slackness challenges in generalizable HAR by introducing semantic-aware Mixup and enhancing its discrimination using large margin loss. SDMix is conceptually simple and easy to implement. (3) Extensive experiments demonstrate that our proposed SDMix significantly outperforms the state-of-theart approaches (6% average accuracy improvement on cross-person, cross-dataset, and cross-position scenarios).
The remainder of this paper is organized as follows. Section 2 provides a brief review of the related work. Section 3 presents problem formulation and background. Then, Section 4 proposes SDMix. In Section 5, experimental evaluation and analysis on five public HAR datasets in three settings. Finally, we present the conclusions and the future work in Section 6.

RELATED WORK 2.1 Human Activity Recognition
Sensor-based HAR is receiving increasing attention over the years [31]. To alleviate the cost for data collection, there is growing interest in applying transfer learning and domain adaptation for HAR [5,6,34]. All existing domain adaptation and transfer learning-based HAR are assuming the availability of target domain data during training. Very little attention is paid to generalizable HAR, i.e., when the test distribution is unavailable for training. To our best knowledge, GILE [22] is the first work for generalizable HAR that disentangled domain-agnostic and domain-specific features in the latent feature space. However, GILE is based on a variational auto-encoder which is more complicated in real applications. Our method does not use generative models and it can perform well on simple CNNs based on Mixup data augmentation.

Domain Adaptation
Domain adaptation has developed for many years and detailed surveys can be found in [19,36]. There is much prior work focusing on HAR with domain adaptation and a detailed survey can be found in [6]. For cross-domain activity recognition, Wang et al. [32] proposed a stratified transfer learning (STL) algorithm that learns the class-wise feature transformation. Wang et al. [34] designed a unified framework for source domain selection and activity transfer. Later, to select the most similar source domain to the target domain and perform accurately transfer activity, Qin et al. [24] proposed an adaptive spatial-temporal transfer learning (ASTTL) approach. Most recently, Lu et al. [15] tried to make full use of data structures and matched substructures of data via optimal transport. Although the above work can relieve distribution shifts, it cannot cope with situations when targets data is inaccessible.

Domain Generalization
Domain generalization (DG) tries to learn a model from one or several different but related domains that will generalize well on unseen testing domains. DG is different from leave-one-out-cross-validation (LOOCV) [37] since LOOCV is a model selection technique which selects models via parts of training data while DG is to enhance generalization on unseen targets. Existing domain generalization methods can be grouped into three categories [33]: data manipulation, representation learning, and learning strategy. Data manipulation contains two kinds of popular techniques: data augmentation [9,18] which is mainly based on augmentation, randomization, transformation of input data, and data generation [14,23] which generates diverse samples to help generalization. Representation learning also includes two kinds of representative techniques: domain-invariant representation learning [13,25] which performs kernel, adversarial training, explicitly feature alignment between domains, or invariant risk minimization to learn domain-invariant representations and feature disentanglement [12,41] which tries to disentangle the features into domain-shared or domain-specific parts for better generalization. Learning strategy mainly has three kinds of methods: ensemble learning [16] which relies on the power of ensemble to learn a unified and generalized predictive function, meta-learning [2,30] which is based on the learning-to-learn mechanism to learn general knowledge by constructing meta-learning tasks to simulate domain shift, and gradient operation [11,28] which tries to learn generalized representations by directly operating on gradients. For more details, please refer to [33]. Despite the popularity of DG in recent years, most of the methods are proposed for computer vision tasks that do not consider the application of HAR.

Mixup
Mixup [42] is a simple but effective technique for data augmentation. It extends the training distribution by incorporating the prior knowledge that linear interpolations of feature vectors should lead to linear interpolations of the associated targets. Although vanilla Mixup has shown its ability for domain generalization, many adapted versions are proposed for better performances. Recent work [38,39] used the vanilla Mixup for domain adaptation without modifications. Wang et al. [35] mixed up samples across multiple source domains with two different sampling strategies to improve the generalization performance across different tasks. They perform well on computer vision while there is no Mixup method designed specifically for HAR.

PROBLEM FORMULATION AND PRELIMINARIES
We are given training data from several source domains. Our goal is to train a model that can perform well on an unseen target domain with these available source domain data. Since the target data have different distributions compared to the source domains, we expect that the trained model is generalizable. A common technique to enhance generalization capability is data augmentation and Mixup is a common way. Mixup may encounter two challenges: semantic inconsistency and discriminative slackness. To cope with these two challenges, SDMix is proposed which utilizes a semantic-aware Mixup technique to eliminate negative effects brought by different semantic ranges of different activities and introduces the large margin loss to reduce virtual noisy data.

Problem Formulation
Following the definition of generalizable cross-domain activity recognition from existing work [22], we are given labeled source domains as the training dataset: D = {D } =1 . We use (x, ) on X × Y to denote the joint distribution of one domain, where x ∈ X ⊂ R denotes the input and ∈ Y = {1, · · · , } corresponds to output. and denote the input dimension and number of classes. Our goal is to learn a generalized model from D to predict well on an unlabeled target domain, D , which is unseen in training. In our problem, the training and test domains have the same input and output spaces but different distributions, i.e., (x, ) ≠ (x, ), ∀ , ∈ {1, 2, · · · , , }. We aim to train a model ℎ from D to minimize the risk on D :

Background
Mixup [42] is a popular approach for data augmentation. Given two random samples (x 1 , 1 ), (x 2 , 2 ), Mixup extends the training distribution by incorporating the prior knowledge: linear interpolations of feature vectors should lead to linear interpolations of the associated targets, formulated as 1 : x where ∼ ( , ) and ∈ (0, ∞) is a hyperparameter. As a powerful data augmentation technique, Mixup plays a vital role to enlarge the distribution diversity in existing domain generalization research [35,40].
We are specifically interested in applying Mixup to generalizable HAR because of its simplicity. Unfortunately in HAR, Mixup faces the semantic inconsistency and discriminative slackness challenges that will dramatically undermine its performance.

SDMIX
In this paper, we propose SDMix (Semantic-Discriminative Mixup) to solve these two challenges in generalizable HAR. In the following, we will introduce the key components of SDMix.

Semantic-aware Mixup
In generalizable HAR, the distributions of sensor reading from two domains are different due to different lifestyles, habits, body shapes, and device positions. While Mixup tries to increase the diversity of distributions, we argue that the activity semantic range will largely impede Mixup.
Definition 1 (Activity semantic range). The activity semantic range of a domain D refers to the maximum shift towards the activity center, denoted as: denotes the activity semantic center for class and (·, ·) is a certain distance function.
Definition 2 (Semantic inconsistency). If data of two classes have different activity semantic ranges, i.e., 1 ≠ 2 , then we say that there exists a semantic inconsistency between these two classes.
Different activities or even the same activity performed by different persons (domains) tend to have different activity semantic ranges. For instance, a person that walks in a parking lot may have larger activity semantic range than another person that walks on a treadmill with a similar speed in flat since walking in a parking lot is more unstable and contains more degree of freedom. Another example is that two persons both playing basketball may have different activity semantic ranges due to different habits and positions. The existing Mixup cannot consider the influence of activity semantic range from two different domains, resulting in semantic inconsistency. Activity semantic range varies between any two classes from any different domains. This situation cannot be avoided in both the feature space ( Figure 7) and the original space. As shown in Figure 2(a), when the above situation occurs that two classes have different activity semantic ranges, the vanilla Mixup generates wrong classifications near the decision boundary. Note that vanilla Mixup utilizes the same for data and categories, which neglects the influence of activity semantic ranges.
In this paper, we propose semantic-aware Mixup to reduce the influence of different activity semantic ranges from different domains. The samples generated by semantic-aware Mixup can be formulated as: where (x 1 , 1 ), (x 2 , 2 ) denote samples from domain and . And is the activity semantic factor, computed as: where 1 and 2 are the activity semantic ranges for the class 1 and 2 of domains D and D , respectively. Note that 1 and 2 may or may not be the same, indicating that this works for both the same or different classes. We only apply for , which is equivalent to calibrating mixed˜with semantic range for a mixedx.
What does Eq. (4) do? We illustrate its effects in Figure 2, where the larger makes the corresponding play a more important role. In Figure 2(a), vanilla Mixup pays no attention to the activity semantic range and treats x equally. Therefore, its decision boundary is biased towards the class with larger activity semantic range. While in Figure 2(c), the boundary is balanced by considering the effects of different activity semantic ranges. In Figure 2(b) and Figure 2(d), a toy example where simple models learned from simulation data following Gaussian distributions is to demonstrate that SDMix can learn better decision boundaries.
We present two alternatives to compute the value of activity semantic range by either using the largest distance from samples to centroid, or the mean of all distances: where D represents the samples associated with class from domain D and |·| is the cardinality. For computation, (·, ·) can be ℓ 1 , ℓ 2 -distances or cosine distance. We choose different computing functions to achieve better performance. denotes the -th class center of domain D : ( 1 , 1 ) Classification boundary Classification boundary Classification boundary Classification boundary

Enhancing Discrimination of Mixup
Other than activity semantic range that describes the activity shift in HAR, we also notice another limitation of Mixup: the virtual noisy activity instance will influence the discrimination of Mixup.
Definition 3 (Virtual noisy activity instance). The interpolation (x,˜) generated by the Mixup of (x 1 , 1 ) and (x 2 , 2 ) is a virtual noisy activity instance, if where ℎ denotes the classification function and > 0 is a threshold.

Definition 4 (Discriminative slackness). When trained the model with virtual noisy activity instances via
Vanilla Mixup, the model may fail to discriminate different classes. We say that the model meets the discriminative slackness problem.
Specially speaking, when x 1 is close to the ideal decision boundary of class 2 (or x 2 to 1 ),x could be extremely close to the decision boundary of 1 or 2 instead of their interpolation˜. And from the point of location,x may belong toˆwhich is different from . For instance, due to different lifestyles, the running data of one person may have distributions similar to the walking data of another person. Thus, his data is easily misclassified. This causes discriminative slackness of Mixup, as shown in Figure 3  In this paper, we introduce large margin loss to enhance the discrimination of Mixup, which is formulated as: where ℓ is the large margin loss, is an aggregation operator for multi-class setting, and sign(·) adjusts the polarity of the distance. ℎ : X → R or ℎ is a function that generates a prediction score for classifying the input vector x ∈ X to class or . is the distance to the boundary which we expect. ℎ,x,{ 1 , 2 } is the distance of a point x to the decision boundary of class 1 and 2 , which is computed as: where || · || is norm. As shown in [7], define = −1 , then Eq. (8) can be computed as: We illustrate the effect of large margin in Figure 3. In Figure 3(a), two classes with shape circle are far away from each other, but yellow circle data points are close to blue plus points. Direct adoption of the vanilla Mixup with the blue star and the yellow star will generate the red star, which is a virtual noisy data point (according to the location of data points). This means that a small class margin may induce terrible virtual labels when performing Mixup. In Figure 3(b), we can see large margin can alleviate this issue.

SDMix for HAR
Similar to the vanilla Mixup, our proposed SDMix remains conceptually simple and can be easily trained in an end-to-end manner. More importantly, our SDMix considers the semantics for different domains and also reduces noisy data when performing Mixup. Therefore, it makes the model perform better on unseen target data. Figure 4 shows the network architecture of the proposed method. Mixed data goes through two blocks and each block contains one convolution layer and one pooling layer acting as feature extractor . We view 1D time series as 2D data with the height being 1, following Fig. 2. in [31]. Then, it goes through one fully-connected layer which serves as the classification layer . Semantics are fused via weighted label Mixup. In Figure 4, we only show conducting Mixup in the original space. We also can perform Mixup on the outputs of the feature extractor which can bring better results in some circumstances. In addition, we do not show BN layers in Figure 4. The loss of SDMix can be expressed as: where Mix (·, ·) represents the semantic-aware mix operation computed by Eq. (3). is the outputs of the feature extractor. ℓ is the large margin loss. Therefore, our learning objective is formulated as: where D is the distribution of domains and 1 , 2 are distributions of data in selected domains. Note that such an objective is optimized in a mini-batch style in deep networks and the details will be introduced in experiments. Specifically, we choose two source domains randomly each time and choose two samples from these two selected source domains respectively to perform semantic-aware Mixup. Semantic factors are updated every several iterations. For fairness (the same number of optimization iterations), the model only utilizes interpolated examples and does not utilize the original training examples. We believe that our method can achieve better performance with both original data and virtual data generated via mixing.

EXPERIMENTS
We evaluate the proposed method by constructing different generalization scenarios on five public datasets.

Datasets
The statistical information of the five public datasets is shown in Table 1, which includes sensor types, sampling frequency, and activity classes. Now, we briefly introduce them in the following. The UniMib SHAR dataset (SHAR) [17] records 9 types of activities of daily living and 8 types of falls. 30 subjects (aged from 18 to 60) conduct the 17 fine-grained activities with data collected by an acceleration sensor embedded in an Android phone. 17 activities include 9 types of activities of daily living (StandingUpFL, LyingDownFS, StandingUpFS, Running, SittingDown, GoingDownS, GoingUpS, Walking, Null) and 8 types of falls (FallingBackSC, FallingBack, FallingWithPS, FallingForw, FallingLeft, FallingRight, HittingObstacle, Syncope).
UCI daily and sports dataset (DSADS) [3] consists of 19 activities collected from 8 subjects wearing body-worn sensors on 5 body parts. 19 activities include sitting, standing, lying on back and on right side, ascending and descending stairs, standing in an elevator still, moving around in an elevator, walking in a parking lot, walking on a treadmill with a speed of 4 km/h, running on a treadmill with a speed of 8 km/h, exercising on a stepper, exercising on a cross trainer, cycling on an exercise bike in horizontal and vertical positions, rowing, jumping, and playing basketball. Each subject wears three sensors: accelerometer, gyroscope, and magnetometer.
PAMAP2 physical activity monitoring dataset (PAMAP2) [26] contains data of 18 different physical activities, performed by 9 subjects wearing 3 sensors. 18 activities include lying, sitting, standing, walking, running, cycling, Nordic walking, watching TV, computer work, car driving, ascending stairs, descending stairs, vacuum cleaning, ironing, folding laundry, house cleaning, playing soccer, rope jumping, and other (transient activities). The sampling frequency is 100Hz and the data dimension is 27 (3 inertial measurement units).
USC-SIPI human activity dataset (USC-HAD) [43] is composed of 14 subjects (7 male, 7 female, aged from 21 to 49) executing 12 activities with a sensor tied on the front right hip. The data dimension is 6 and the sample rate is 100Hz. 12 activities include Walking Forward, Walking Left, Walking Right, Walking Upstairs, Walking Downstairs, Running Forward, Jumping Up, Sitting, Standing, Sleeping, Elevator Up, and Elevator Down.
Human activity recognition using smartphones dataset (UCI-HAR) [1] is collected by 30 subjects performing 6 daily living activities with a waist-mounted smartphone. 6 activities include walking, sitting, lying, standing, walking upstairs, walking downstairs. The data dimension is 6 and the sample rate is 50Hz.

Experimental Setup
We construct three types of experiments to thoroughly evaluate all methods for generalizable HAR: (1) Crossperson HAR similar to existing research [22], (2) Cross-dataset HAR, which is our construction that is more challenging than cross-person HAR since cross-dataset setting implies that not only the persons are different, but also the sensor types and positions, and (3) Cross-position HAR, which utilizes data from different positions with same persons. In all three settings, we adopt the sliding window technique [4] with 50% overlap to construct training samples following common practice in HAR [31]. The inputs should be cut into individual inputs according to the sampling rate and each new input serve as one instance. We give a more detailed introduction of three settings in the following. We do not split domains; instead, each dataset can be treated as one domain and we take the common classes from all datasets. To perform the Cross-Dataset setting, we first need to unify X and Y. For X, two sensors that belong to the almost same position are selected and each sample contains six dimensions. Then, data is down-sampled and the sampling rate is 25Hz. For Y, six common classes are selected, including walking, walking upstairs, walking downstairs, sitting, standing, and lying. • Cross-Position: We conduct experiments on DSADS for this setting. 3 sensors are located in five parts of a body in DSADS. Each body part corresponds to a different domain. Each sample contains three sensors with nine dimensions. (1,140,000)*5 5,700,000 Table 2 shows the information on cross-person, cross-dataset and cross-position scenarios. It is worth noting that since SHAR dataset contains much fewer samples than others, we replace it with UCI-HAR dataset [1] for cross-dataset experiments. The reason we did not run cross-person experiments on UCI-HAR is that the results on this dataset are all near 100%. In total, we constructed 16, 4, and 5 tasks for cross-person, cross-dataset, and cross-position HAR, respectively. We use 0, 1, 2, 3 to denote the four divided domains for cross-person experiments. We use 0, 1, 2, 3, 4 to denote the five divided domains for cross-position experiments.
Baselines. The latest method for generalizable HAR is GILE (Generalizable Independent Latent Excitation) [22]. Since there are no other methods designed for HAR except GILE, we turn to comparing with several popular domain generalization methods. DeepAll combines all source data together and trains a model according to ERM. DANN [8] and Coral [29] are two traditional DG methods, and we extend them to fit the domain generalization setting. Mixup [42], GroupDRO [27], RSC [11], and ANDMask [20] are four state-of-the-art universal domain generalization methods which can be directly used for HAR. Except GILE, we reproduced all other methods with the same network architecture in Pytorch [21] for fairness. GILE is based on VAE, and we directly use their released code. Table 3 shows information on the input size and kernel size of the models in all settings and the final dimension of input size represents the window size. We do not compare other Mixup-based DG methods since they are built for computer vision tasks that are not applicable to HAR problems.
To obtain the final model, we split data of the source domains into the training splits and validation splits. The training splits are utilized for training the model while the validation splits are utilized to guide the selection of the model. For all benchmarks, we select the best model via validation accuracy. In practice, we leave 80% of source domain data as training splits while the rest data are for validation. For testing, we evaluate the selected models on all data of the target domain. For our architecture, the model contains two blocks, and each has one convolution layer, one pool layer, and one batch normalization layer. A single fully-connected layer serves as

Experimental Results
The results of cross-person, cross-dataset, and cross-position HAR are shown in Table 4, 5, and 6 respectively. On average, our proposed SDMix substantially outperforms the second-best methods: 6.0% for cross-person, 10.33% for cross-dataset HAR, and 2.34% for cross-position HAR. Moreover, from Figure 5, we can see that our method also achieves the best F1 score compared with other state-of-the-art methods whether in a balanced or unbalanced situation. These indicate that our method is effective for generalizable cross-domain HAR applications.  We observe more insightful conclusions. (1) When are Mixup-based methods most effective? When the dataset volume is rather small with more classes, i.e., on difficult tasks. This can be verified on SHAR and DSADS datasets that have fewer samples but more classes. In these datasets, Mixup-based methods dramatically increase the Table 4. Classification accuracy (± std. error) for cross-person HAR. The bold and underline items denote the best and second-best results, respectively.

Src
Tar diversity of data distributions that benefits generalization. On the larger PAMAP2 and USC-HAD datasets that involve more diversity, the vanilla Mixup only slightly surpasses DeepAll or even worse. (2) When is SDMix less effective? When the training domains are much larger than the test domains, i.e., the training domains are already containing diverse 3 data, where SDMix may bring smaller improvements. In our statistics, source domains 1 ∼ 3 in PAMAP2 have more samples that make it enough to learn models directly using DeepAll. The same goes for cross-dataset HAR when UCIHAR is the target. In addition, when activity semantic range is hard to compute, SDMix only slightly surpasses other methods or even worse. For example, there exist little information and many categories in the cross-position setting, which makes it hard to estimate activity semantic range. SDMix only has a slight improvement compared with other methods and even performs worse on the first task. (3) What influences stability in HAR generalization? Algorithms, random states, data splits, and so on. Whichever algorithm is used, there exist fluctuations among the results of three trials. Even with DeepAll, results are also different. From Table 4, we can see that our method achieves the smallest STD compared to other state-of-the-art methods except GILE 4 . The results demonstrate that our method is still reliable and stable with three trials compared to other state-of-the-art methods. (4) What influences generalization in HAR? Dataset quantity, diversity, and the cross-domain distribution discrepancy. There is no doubt that the generalization ability of a model will increase when the dataset becomes larger and diverse (rf. Table 4). More importantly, we see a significant performance drop from cross-person to cross-position HAR, indicating the importance of cross-domain discrepancies [5]. The cross-dataset and position scenario is more challenging than cross-person since the sensor devices, positions, subjects are all different. In this scenario, our SDMix achieves the best performance by harnessing their diversity. Note that there is still room for improvement in this setting.

Analysis
Why is SDMix effective? Do semantic inconsistency and discriminative slackness really exist? To analyze the rationale behind the effectiveness of SDMix, we plot the confusion matrices for the vanilla Mixup and ours for target 0 on DSADS dataset in Figure 6. While most classes are correctly classified, we are more interested in the misclassified classes: class 8 (walking in a parking lot) and class 9 (walking on a treadmill with a speed of 4km/h in flat); class 1 (standing) and class 6 (standing in an elevator still). Firstly, as shown in Figure 6(a), some samples in class 8 are misclassified as class 9 (Please see the row labeled 8). It is caused by different activity semantic ranges since walking in a parking lot has more variance than walking on a treadmill. Our method can correctly classify them. Secondly, some samples in class 6 are misclassified as class 1 (Please see the row labeled 6) since standing and standing in an elevator still are two similar activities with small differences that weaken the discrimination of Mixup. Again, our method can mitigate these two issues to achieve the best results as shown in Figure 6(b). As shown in Figure 6(c), class 8 in color 8 with shape circle has a larger semantic range than class 9 while class 1 almost compasses class 6 which illustrates they are close to each other. Figure 6(c) describes the phenomena while confusion matrices are the results brought by the phenomena, indicating the claim mentioned above.
In Figure 7(a), different classes (points with different colors) have different semantic ranges, which demonstrates that semantic inconsistency exists in reality and we should use semantic-aware Mixup. From Figure 7(b), we can see that data points in color 17 with shape + are close to data points in color 9, which proves the existence of the second issue. And from the right figure, we can see our method mitigates this issue. Figure 7 describes  the phenomena and the improvements on the fourth task of DSADS in Cross-person setting also suggests that paying attention to semantic range and discrimination can bring better performance. 5

Ablation Study
We perform ablation study in Figure 8. Figure 8(a) shows Mixup has a better performance than DeepAll while our Semantic-aware Mixup further improves accuracy on SHAR in the Cross-Person setting. Moreover, with large margin loss to enhance discrimination, there exists another improvement compared with semantic-aware Mixup, which demonstrates that our method achieves the best average accuracy and the two components of our SDMix are both effective. Results of ablation study on DSADS, PAMAP2, and USC-HAD in the Cross-Person setting and results in the Cross-Position setting (Figure 8

Parameter Sensitivity Analysis
We evaluate the parameter sensitivity of SDMix in Figure 9. There are mainly four hyperparameters in our method: the Beta distribution in Mixup ( ), the aggregation class number in Eq. (10) (top ), the required distance to boundaries in Eq. (10) ( ), and alternatives for computing activity semantic range in Eq. (5a) or Eq. (5b). From Figure 9(a)-9(c), we can see that the results with parameters around the highest points are all better than DeepAll. Figure 9(d) demonstrates that different approaches of computing activity semantic ranges obtain different results and we should choose the right one for better results through validation. Please note that our method achieves the best performance no matter which approach of computing is selected. In a nutshell, It demonstrates that SDMix is effective and robust that can be easily applied to real applications.

Extensibility
To demonstrate that our method is still a remark method in the common setting where training data and testing data share the same distribution, we conduct experiments on DSADS. We split DSADS into two parts, 20% for testing and the rest for training. When utilizing all rest data for training, the baseline accuracy is almost 100%. To better show performance differences between our method and other state-of-the-art methods, we utilize 10%, 25%, 50%, 100% of rest data for training. To select the best model during training, 20% of data serve as validation data while the rest data serve as the real training data. Therefore, when utilizing 10% of rest data for training, only 6.4% of all data are for training. The results are shown in Figure 10 where we can see that our method achieves the best performance compared to ERM and Mixup. Our method has improvements with 4.88%, 2.36%, 1.7%, 0.17% compared to ERM while it has improvements with 3.17%, 0.66%, 0.72%, 0.22% compared to Mixup using 10%, 25%, 50%, 100% training data respectively. As we can see, all methods achieve better performance with more training data used and our method achieves the best performance no matter how many training data are used. The results demonstrate that our method is still a remark method in a common setting.
In this paper, we proposed SDMix for generalizable sensor-based human activity recognition. SDMix solves two critical challenges: semantic inconsistency and discriminative slackness. Specifically, SDMix took the activity semantic range into consideration to learn more flexible interpolations. Moreover, SDMix introduced the large margin loss to Mixup that enhances the discrimination. Extensive experiments on cross-person, cross-dataset, and cross-position scenarios demonstrated the effectiveness of our method. In the future, we plan to extend SDMix to more challenging HAR settings including cross-category and incremental learning.