Jawher Dridi
email: j_dridi@live.concordia.ca

Manar Amayri

Nizar Bouguila

Transfer Learning for Estimating Occupancy and Recognizing Activities in Smart Buildings

Keywords:

Activities Recognition (AR) and Occupancy Estimation (OE) are vital to many smart systems that work on providing good services in smart buildings. Many applications, such as energy management need information like activities and occupancy to provide good assistance. Most of the previous research about AR and OE focused on applying supervised machine learning methods. Researchers train a model and evaluate it using data collected from the same environment (Domain). A model trained in a specific domain will not generalize well in other domains. Creating a trained model to every environment is not feasible due to the lack of data. Collecting sufficient data can be time consuming and infeasible in some cases. Computational power can be a challenge for researchers by increasing the training time due to the lack of the required computing resources. Using traditional machine learning methods, the obtained performance may be unsatisfactory, and can not lead to optimal solutions. For all these reasons, we need a solution that helps us overcome the stated problem and obtain models with acceptable results. In this work, we present and discuss different transfer learning methods that help us transfer knowledge from a source domain to a target domain. The goal is to reuse as much as possible information from the source domain to enhance the performance of the model at the target domain. This type of approaches will solve the problems mentioned before such as the lack of data and will provide us with good results due to the use of knowledge from multiple source domains. We tested five Transfer learning (TL) approaches: a principal component analysis (PCA)-like method that creates a transformation like the PCA transformation and apply it to the data to create new common domain, a PCA based method that creates common domain using PCA, a PCA-SMOTE method that balances the data and creates common domain, a basic method based on a simple matching between similar features from source and target domain, and a sparse coding-based method that creates a common domain where the data representation will be as sparse as possible. The impressive results that we obtained in both tasks prove that the presented methods can be applied to transfer knowledge across different domains.

Introduction

Nowadays, more than 55% of the population are living in urban areas, and it is estimated that 13% more will move to cities in the upcoming 30 years [START_REF] Tîrziu | Urbanization and cities of the future[END_REF]. With the emergence of the sensor technology and with the goal of providing cities with great services, the idea of smart buildings was introduced in the last two decades. Recently, researchers have started focusing on Activities Recognition (AR) [START_REF] Zhou | Device-free occupant activity recognition in smart offices using intrinsic wi-fi components[END_REF][START_REF] Chen | A framework for group activity detection and recognition using smartphone sensors and beacons[END_REF][START_REF] Cha | Towards a well-planned, activity-based work environment: Automated recognition of office activities using accelerometers[END_REF] and Occupancy Estimation (OE) [START_REF] Chen | Building occupancy estimation and detection: A review[END_REF][START_REF] Zhou | A novel model based on multi-grained cascade forests with wavelet denoising for indoor occupancy estimation[END_REF][START_REF] Ryu | Development of an occupancy prediction model using indoor environmental data based on machine learning techniques[END_REF]. Indeed, AR and OE can be very helpful in many applications such as energy management [START_REF] Amayri | Decision tree and parametrized classifier for estimating occupancy in energy management[END_REF]. They can reduce the energy consumption and find the optimal energy distribution. Most of previous works on AR and OE tasks have focused on supervised machine learning approaches [START_REF] Amayri | Estimating occupancy in heterogeneous sensor environment[END_REF]. Indeed, a model is trained in a specific environment and evaluated using data from the same domain. The collection of data is required for each environment. However, the task of collecting data is time consuming and can affect the behavior of the collector with time. Also, most of the previous research assumed that the distributions of data from a specific environment is the same in any new smart building environment. But, this assumption is not valid in most of the cases. So, we need to reduce dependency on data by reusing as much as possible knowledge from the source environment in the new target environment. Transfer learning can be helpful to avoid some problems such as computational power. Indeed, the advancement of the research can be blocked due to the lack of the required computing resources. Also, transferring knowledge across domains is a solution to the models where it is difficult to further improve their performances. Most of the recent research on transfer learning have focused on deep learning methods. In this paper, we introduce five basic methods of transfer learning that do not apply deep learning methods. Indeed, deep learning methods require a lot of training data to give good performance. Unfortunately collecting training data is a very complex process in the case of AR and OE tasks. Four of the introduced methods assume that a little number of instances from the target domain added to the training data can significantly improve the performance of the target model [START_REF] Chen | Activity recognition using transfer learning[END_REF]. In this paper, we made several contributions. Firstly, we adapted a PCA-like method for OE. Secondly, we implemented a PCA-based method and we tested it on AR and OE. Thirdly, we created a PCA-SMOTE method that balances the data and creates common domain. Fourthly, we implemented a method called simple feature matching to compare it with other methods that do not consider the nature of features. Finally, we adapted a method based on sparse coding to the task of AR.

The rest of the paper is organized in 4 sections. In section 2 and 3, we present the literature review and the theoretical background. In section 4, we introduce the proposed approaches. In the section 5, we present and discuss the experimental results.

Literature review 2.1. Activities recognition

Previous research for the AR task has developed multiple machine learning methods. Indeed, AR task has involved supervised, semi-supervised, and unsupervised machine learning methods as well as deep learning and transfer learning approaches.

For the supervised machine learning methods, [START_REF] Cha | Towards a well-planned, activity-based work environment: Automated recognition of office activities using accelerometers[END_REF] has used data collected from accelerometers to test 5 machine learning classifiers (k-Nearest Neighbor, Discriminant Analysis, Support Vector Machine, Decision Tree, and Ensemble Classifier) on recognizing 7 office activities. The goal is to understand worker's activity patterns, and the considered approaches gave accuracies reaching 96%. [START_REF] Chen | A framework for group activity detection and recognition using smartphone sensors and beacons[END_REF] has developed a framework focusing on group activities such as working together and taking classes to develop a building management system. The framework is called GADAR (Group Activity Detection And Recognition), and it uses data collected from smartphone sensors (acceleration, gyroscope, compass, Bluetooth, microphone) and Bluetooth beacons data. The decision tree has been tested as a classifier and it has given accuracy greater than 89% for the activities recognition task. [START_REF] Sigg | Leveraging rf-channel fluctuation for activity recognition: Active and passive systems, continuous and rssi-based signal features[END_REF] has developed a framework to recognize activities such as walking and standing using Radiofrequency signals. The method evaluation was made using supervised classifiers such as Naive Bayes and K-nearest neighbor. [START_REF] Palipana | Falldefi: Ubiquitous fall detection using commodity wi-fi devices[END_REF] has developed a system to recognize activities for elderly people in order to monitor a public health worry which is fall. The system uses non-wearable devices data which is information generated by WIFI devices. The features information is extracted using a Short-Time Fourier Transform (STFT), and the evaluation system is made using an SVM classifier.

For the semi-supervised machine learning methods, [START_REF] Fahmi | Semi-supervised fall detection algorithm using fall indicators in smartphone[END_REF] has also considered the recognition of falls for the elderly people using data collected from smartphone sensors ( accelerometer and orientation sensor) and evaluated using a semi-supervised approach. [START_REF] Longstaff | Improving activity classification for health applications on mobile devices using active and semi-supervised learning[END_REF] developed 3 semisupervised approaches to monitor activities patterns in health and fitness applications. The proposed methods use mobile phone sensing data such as GPS and accelerometer. The first method is self-learning which uses one classifier to classify unlabeled data, and the last two semi-supervised methods are co-learning methods that use multiple classifiers called En-Co-Training and Democratic co-learning.

For the unsupervised machine learning methods, [START_REF] Trabelsi | An unsupervised approach for automatic activity recognition based on hidden markov model regression[END_REF] has considered the case where there is a lack of labeled data and developed an unsupervised approach to recognize activities based on Hidden Markov Model (HMM) and evaluated using acceleration data collected from wearable sensors. [START_REF] Kwon | Unsupervised learning for human activity recognition using smartphone sensors[END_REF] has developed an unsupervised approach to recognize five activities (walking, running, sitting, standing, and lying down) using smartphone sensors data. For a known activities number, DBSCAN (Density-based spatial clustering of applications with noise) has achieved an accuracy of 90%.

For the deep learning methods, [START_REF] Wang | Deep learning for sensor-based activity recognition: A survey[END_REF] has presented many techniques that use data collected from wearable and nonwearable sensors. The dataset can be generated using smartphone sensors, watch sensors, door sensors, sound, WiFi, etc. A deep neural network (DNN) has been presented as a model containing more hidden layers than an artificial neural network (ANN). Indeed, DNN works as a classifier that recognizes the activities of processed data. Convolutional Neural Network (CNN) has been presented for the task of AR as it performs features extraction from sensing data, then it makes decisions over the obtained data. Recurrent neural network (RNN) has been considered in [START_REF] Wang | Deep learning for sensor-based activity recognition: A survey[END_REF] as it takes into consideration the temporal pattern of the sensing data while recognizing activities. In most cases, LSTM (longshort term memory), which serves as a memory unit, is employed with RNN.

For the transfer learning methods, [START_REF] Cook | Transfer learning for activity recognition: A survey[END_REF] has given information about several knowledge transfer techniques. The presented methods have used several data sources such as video cameras, wearable sensors (accelerometers, gyroscopes, radio frequency identification sensors, etc), and ambient sensors (temperature and pressure sensors, motion detectors, object and door sensors). Instance transfer techniques transfer knowledge gained from a source domain to a target domain to enhance the prediction function of the AR task. It is usually done by re-weighting instances from the source domain to fit the target domain [START_REF] Cook | Transfer learning for activity recognition: A survey[END_REF]. Feature representation transfer has been employed by creating a transformation to map source domains to a target domain to allow knowledge transfer across several domains. Thus, the target domain prediction function gets enhanced with knowledge of several source domains [START_REF] Cook | Transfer learning for activity recognition: A survey[END_REF]. Parameter sharing methods have been presented for the AR task as they learn a target model using pre-trained models of source domains [START_REF] Cook | Transfer learning for activity recognition: A survey[END_REF].

In summary, recognizing activities using sensors data has been done using several machine learning techniques such as supervised and transfer learning methods that solve different problems such as the limited amount of labeled data.

Occupancy estimation

Prior research for OE task has also developed multiple machine learning methods as AR task. Supervised, semisupervised, and unsupervised machine learning approaches as well as deep and transfer learning methods have been tested on the task of occupancy prediction.

For the supervised machine learning methods, [START_REF] Amayri | Towards interactive learning for occupancy estimation[END_REF] has developed a supervised learning approach based on interactive learning to predict the number of occupants in a smart building room. The method has been evaluated using a decision tree classifier on ambient sensors data such as CO2 concentration and power consumption avoiding the use of cameras for privacy purposes. [START_REF] Longo | Accurate occupancy estimation with wifi and bluetooth/ble packet capture[END_REF] has presented an occupancy estimation system based on two supervised machine learning methods and uses WiFi and Bluetooth sensors as data sources instead of ambient and cameras sensors. Indeed, they believe that ambient sensors do not provide good accuracies and cameras sensors require high setup costs. [START_REF] Azam | Occupancy estimation using wifi motion detection via supervised machine learning algorithms[END_REF] has developed several supervised learning methods to estimate occupancy levels that are trained using WiFi data collected in a smart building office. Among the tested methods, decision tree and random forest have given the highest scores with 95% of accuracy. [START_REF] Chiţu | Building occupancy estimation using supervised learning techniques[END_REF] has developed two supervised learning techniques based on random forest and KNN algorithms to estimate the number of occupants in smart building rooms using several types of sensors data such as CO2 data and airflow. The goal of the considered methods is to create energy efficient Heating, Ventilation, and Air-Conditioning (HVAC) systems. [START_REF] Amayri | Estimating occupancy in heterogeneous sensor environment[END_REF] has developed a supervised machine learning approach to improve energy management in smart building rooms using ambient sensors data such as CO2 concentration and acoustic pressure. The technique proposed in the research determines at first the most significant features for the occupancy prediction, then it uses a supervised model such as a decision tree and random forest to estimate the occupancy levels in a given office.

For semi-supervised learning approaches, [START_REF] Arief-Ang | Da-hoc: semisupervised domain adaptation for room occupancy prediction using co2 sensor data[END_REF] has developed a method called DA-HOC (domain adaptation human occupancy counter) that uses CO2 data to make domain adaptation based on a semi-supervised learning method. DA-HOC is able to predict the number of occupant in a large room using a small number of labeled training data and based on the knowledge gained from a model trained in a small room. [START_REF] Ashouri | Day-ahead prediction of building occupancy using wifi signals[END_REF] has proposed a semi-supervised machine learning method that uses limited ground truth data to estimate the number of occupants in smart buildings. The methodology uses WiFi data for training and evaluation, and its main goal is to provide efficient energy management. The considered method has been evaluated using a combination of artificial neural networks and linear regression, and it has given accuracies around 90%.

For the unsupervised machine learning approaches, [START_REF] Amayri | Bayesian network and hidden markov model for estimating occupancy from measurements and knowledge[END_REF] has developed a method based on the Hidden Markov Model and Bayesian Network algorithms to estimate the number of occupants in an office. The considered method has achieved accuracies between 89% and 91%, and it works using probabilistic cause effects relations and states. [START_REF] Nguyen | A statistical approach for unsupervised occupancy detection and estimation in smart buildings[END_REF] has considered energy consumption planning in a smart building by developing an unsupervised approach to estimate occupants number. The method is based on finite scaled Dirichlet mixture models that use non-wearable sensors data such as door/window position and acoustic pressure. [START_REF] Habib | Automatic occupancy prediction using unsupervised learning in buildings data[END_REF] has proposed an unsupervised method that detects occupants in rooms using air quality data. The considered method is based on a k-means clustering algorithm, and its main goal is to manage energy in buildings.

For deep and transfer learning methods, [START_REF] Stjelja | Scalable room occupancy prediction with deep transfer learning using indoor climate sensor[END_REF] has proposed a deep transfer learning method that uses IoT (Internet of Things) sensors data such as temperature and CO2 data collected from offices in a smart building. In this research, a pre-trained model from the source domain called Convolutional Deep Long Short-Term Memory (CDLSTM) has been used to transfer knowledge to the target domain by sharing model weights. [START_REF] Leeraksakiat | Occupancy forecasting using lstm neural network and transfer learning[END_REF] has also a deep transfer learning method based on LSTM using data collected from IoT sensors such as thermometer, PIR, and CO2 sensors. The considered approach, which aims to reduce energy consumption, transfers knowledge by sharing the source model weights to the target model and by retraining the target classifier with a small amount of target data.

In summary, as the AR task, researchers have developed various machine learning methods to estimate the number of occupants in smart buildings for several purposes but mainly for energy management.

For AR and OE tasks, transfer learning has not received much attention as compared to other approaches such as supervised learning methods. Most of the existing approaches of knowledge transfer for AR and OE tasks are focusing on deep learning. Deep learning methods require a huge amount of labeled data which can be difficult to obtain especially for smart buildings tasks due to problems of privacy. In this paper, we present 5 basic transfer learning methods that transfer knowledge from a source domain to a target domain, that are not based on deep learning, to enhance the target prediction function.

Theoretical background

Transfer learning fundamentals

Definition of TL

Before giving the definition of transfer learning, let us start by defining some terms related to TL.

Domain:

A domain is an environment usually denoted .

It is composed of a feature space and a marginal distribution. We denote the feature space with  and the marginal distribution with ( ), where is an instance of the feature space , = | ∈ , = 1, … , .

Task: A task is a prediction that is usually denoted  . It is composed of a label space  and a decision function ,  = {, }. The decision function is learned from the input data.

Transfer learning: Given a source domain   and a target domain   , a source task   and a target task   that correspond to the source and the target domains, respectively. The goal of transfer learning is to improve and enhance the performance of the decision function of the target task by using the knowledge gained from the source domain   [START_REF] Zhuang | A comprehensive survey on transfer learning[END_REF].

Figure 1 gives an intuitive example about transfer learning. Indeed, a person who knows how to play a violin or ride a bike will easily learn how to play a piano or ride a motorbike, respectively. However, we cannot use the knowledge gained form playing a violin to learn how to ride a motorbike. We call this negative transfer, and this is an interesting topic that researchers take into consideration when applying TL. Transfer learning should be applied between two domains or more that have some similarities.

Categories of transfer learning

Transfer learning can be categorized in different ways. If we take the problem categorization view, we can divide TL into three categories based on the availability of data labels: Transductive TL, Inductive TL, and Unsupervised TL. The scenario can be categorized into Transductive TL if only the source domains have labeled data. In this scenario, the tasks from both source and target domains are similar, but the domains can be different. We speak about Inductive TL when the labeled data exist in the target domain no matter if it exits or not in the source domain. In this case, the tasks from both domains are different. The case where we do not have label information from both domains is called Unsupervised TL [START_REF] Niu | A decade survey of transfer learning (2010-2020)[END_REF][START_REF] Pan | A survey on transfer learning[END_REF]. Transfer learning can be divided into two categories based on the feature and the label spaces of the source and the target domains. If we have the same feature space and label space between the source and the target, the scenario is called Homogenous TL. Otherwise, if one of the spaces is different between the source and the target, the scenario is called Heterogenous TL [START_REF] Zhuang | A comprehensive survey on transfer learning[END_REF]. If we take the solution categorization view, Transfer learning can be divided into four categories: Instance-based approach, Feature-based approach, Parameter-based approach, and Relational-based approach. The Instance-based approach corresponds to the case when we use data from a source domain to train a target model. This is done mainly by re-weighting the instances from the source to fit the target. The Feature-based approach is mainly based on creating a transformation that will take whether the source features to fit the target feature space (Asymmetric transformation) or will take both source and target features to a new common feature space (Symmetric transformation) [START_REF] Zhuang | A comprehensive survey on transfer learning[END_REF]. The parameter-based approach focuses on the target model by transferring the knowledge at the parameter level. This kind of approaches is mainly used in deep learning when a well-trained model in the source can share a part of its weights to a target model, assuming that both of tasks in the source and the target are related [START_REF] Niu | A decade survey of transfer learning (2010-2020)[END_REF]. The Relationalbased approach is the newest and the less used method in transfer learning compared to the previous methods. It does not assume that the datum from the source and the target domains are independent and identically distributed ( . . ). It works by assuming that similar relations and dependence exists between data from different domains [START_REF] Niu | A decade survey of transfer learning (2010-2020)[END_REF]. Figure 2 illustrates all the transfer learning categories mentioned above.

Data-based interpretation

Transfer learning is based on the knowledge transformation and adjustment for the data-based approaches. First, we will speak about the two strategies that adjust and transform the knowledge: Instance weighting and Feature transformation. Then, we will tackle the goals of data-based transfer learning approaches. Figure 3 illustrates our plan. where is an instance set, is a label set corresponding to the instance set and is a probability [START_REF] Zhuang | A comprehensive survey on transfer learning[END_REF]. In this case, if we want to apply TL, we need to adapt the different marginal distributions between the source and the target. We have to re-weight the instances from the source by assigning them some weights in the loss function.

Feature transformation:

The second strategy called Feature transformation is widely used with feature-based approaches. It creates a transformation to transform the data into a new feature space. The transformation is created using the source and the target data or using only the source data, depending on the case. The goal of this transformation is to reduce the marginal and conditional distributions divergence. In the new created feature space, we can easily find a matching between the source and the target features by calculating the features divergence [START_REF] Zhuang | A comprehensive survey on transfer learning[END_REF]. There are multiple metrics to measure the divergence or the similarity between source and target domains such as Jensen Shannon divergence, Euclidian distance, etc. However, Maximum Mean Discrepancy (

) has been proved to be the most effective metric used in transfer learning:

( , ) = ‖ ‖ ‖ ‖ 1 ∑ =1 Ξ( ) -1 ∑ =1 Ξ( ) ‖ ‖ ‖ ‖ 2  ( 1
)
where is the source domain, is the target domain, is an instance set, is a feature vector, is the number of instances, Ξ is a nonlinear mapping that maps original features into a space  called a reproducing kernel Hilbert space.

Objectives: The goal of the strategies mentioned above is to achieve distribution adaption, and space adaptation. These strategies will try to reduce the distribution divergence between features. This will lead to a relatedness between the source and target feature spaces, and that is how we obtain space adaptation.

Principal component analysis (PCA)

PCA is highly used in the machine learning field. It is a dimensionality reduction tool. It transfers a given data to a new basis where the newly created principal components are independent, and the dimensions that capture more variances are ranked first. To calculate the PCA, we follow these steps:

1. Calculating the covariance matrix of the original data instances. 2. Calculating the eigen vectors and eigen values of the covariance matrix. 3. Sorting the eigen vectors by their eigen values in descending order. 4. Selecting the first k eigen vectors that have the biggest eigen values (k is the new feature space dimension). 5. Building the projection matrix. 6. Transforming the original data using the projection matrix to the new basis.

The proposed approaches

PCA-like method

In this section, we will introduce a supervised TL method called PCA-like method inspired from [START_REF] Chiang | A feature-based knowledge transfer framework for cross-environment activity recognition toward smart home applications[END_REF][START_REF] Lu | An instantiation of the multiple-transfer framework to reduce efforts in context model learning for new users in smart homes[END_REF][START_REF] Chen | Activity recognition using transfer learning[END_REF]. Indeed, the researchers in these papers applied their methods on AR, but we extended it to the OE task. The method is based on feature transformation, feature similarity calculation, feature mapping and model training. The method maps the source and target feature spaces into a common feature space. Figure 4 gives an illustration of the general architecture.

Feature transformation

Feature transformation in some scenarios is a mandatory step. Otherwise, information will be lost like shown in Figure 5. The figure shows features from different domains but they are dependent. The best that we can do without reformulation is to match the feature 2 with the feature ℎ 3 . It is very clear that the features 1 , ℎ 1 and ℎ 2 share some information that is not visible to the model. After knowledge transfer, the information inside the features 1 , ℎ 1 and ℎ 2 will be lost. That is why a reformulation step before applying transfer learning in this scenario is required. The reformulation will allow the one-to-one mapping between features. Without transformation, the matching may not be one-toone because features from a space can be a combination of multiple features from other spaces. In our scenario, labeled data from the source and target domains are available. Our method can use the data from both domains to create transformation matrices for both domains. Let us consider  a transformation with a transformation matrix , a variable of the labels, 1 , 2 , … , random variables of a dataset. In this scenario, corresponds to the random variable of the feature . The vector of random variables of the features is called = ( 1 , 2 , … , ) . This method works by creating a linear transformation. Our transformation  should satisfy the two following criteria. Firstly, ( ) = ( ) where is the Shannon entropy, and is the linear transformation that we are looking for. This first criterion will preserve the amount of information before and after the transformation without encountering information loss. Secondly, after applying the transformation, the mutual information between any two features from a specific domain given the labels is null: (( ); ( )| ) = 0, is the mutual information. This second criterion assumes that reformulated features are independent, and each reformulated feature provides new information. It is difficult to create a transformation that agrees with the second criterion. Indeed, given the different labels, the joint distribution of the features may not remain unchanged. For that reason, we relax this property and introduce a new property as follows:

[ (( ); ( )| )] = 0, where is the covariance function and is the expected value. This criterion provides us with features expectedly uncorrelated and that may still be dependent [START_REF] Chiang | A feature-based knowledge transfer framework for cross-environment activity recognition toward smart home applications[END_REF]. To satisfy all these properties, we introduced a PCA-like transformation. First, we have calculated the expected covariance matrix of the random variables given the labels. The expected value is introduced because the covariance matrix is not constant, but it is a function of the labels . Indeed, using the labeled features, the system tries to find a new base that is constructed by eigenvectors of the calculated covariance matrix.

( ( | )) = ( ( | ) ) = Γ = Σ (2)
where Γ = ( ( | )) and Σ is a diagonal matrix.

In case the Σ matrix is not diagonal, we need to normalize the obtained eigenvectors. This procedure gives eigenvectors with Euclidian norm equals to one. We take a percentage (10% for the AR task and 40% for the OE task) of the eigenvectors, and the rest are ignored. The transformation matrix is computed by letting the selected eigenvectors being its rows vectors [START_REF] Chiang | A feature-based knowledge transfer framework for cross-environment activity recognition toward smart home applications[END_REF].

Feature similarity

After feature reformulation, it is easy to make a one-toone mapping, if the features are the same. However, it is not the case in most of the time. That is why, we need to use a tool to match the features based on their relatedness. There are multiple tools to calculate the relatedness between features distributions that have been widely used in research such as KL (Kullback-Leibler) divergence, correlation coefficient, Euclidian distance, mutual information [START_REF] Chen | Activity recognition using transfer learning[END_REF]. The method used in this paper is Jenson-Shannon divergence (JSD). The KL divergence, also known as the relative entropy, is asymmetric and unbounded method, its formula is as follows:

( ∥ ) = ∑ ( ) ( ( ) ( ) ) (3)
where and are two probability distributions. The JSD is a version that satisfies the symmetry and the bounding properties (within [0, 1]), and its formula is as follows:

( ∥ ) = ( ∥ ) + ( ∥ ) 2 ) (4)
where

= ( + ) 2
Given two reformulated features spaces  and  and a label vector , the system can compute the JSD between two distributions and of the features ∈  and ∈ , respectively given the labels. The general formula is as follows:

( ( ( | ) ∥ ( | ))) = ∑ ( ) ( ( | = ) ∥ ( | = )) (5)
where is a probability distribution function of the labels .

Feature mapping

Algorithm: After getting the relatedness between all pairs of features from the source domain and the target domain, it is easy to make a one-to-one matching between features based on the values of their divergence by different matching algorithms. To make the mapping between features, we implemented the Gale-Shapley algorithm [START_REF] Gale | College admissions and the stability of marriage[END_REF].

Negative transfer: When transferring knowledge from a domain to another one, the two domains should be dependent. This is required to find useful knowledge, otherwise all the knowledge gained from the first domain will not be helpful. Gained knowledge which decreases the performance of a target model instead of improving it, is called negative transfer. Negative transfer has been taken into consideration in the transfer learning research because of its bad effects. To avoid this problem, we have set a threshold for the mapping step: any two pairs that have a divergence greater than the threshold will not be considered. The threshold is not static and depends on the task. To get the best threshold, we make a grid search for each task.

Model training

After transforming the original features from both domains into a new common domain and matching the different features from the source and the target, we can easily use data from the source domain to help improving the training in the target domain. It has been proven in previous works that small amount of labeled data from the target added to the training improves significantly the performance of the target model [START_REF] Chen | Activity recognition using transfer learning[END_REF]. To evaluate the performance of the knowledge transfer, we used a decision tree classifier that has been proven to be effective in the case of AR and OE by previous research.

PCA-based method

In this section, we introduce the PCA-based method that we tested on both tasks AR and OE. It is an unsupervised domain adaptation method. In this method, we do not have a transformation like the previous one. The method consists of reformulating the features by PCA, calculating the relatedness between new reformulated features, mapping the features, and training the model using the new reformulated features from the source and the target domains. Figure 6 illustrates the different steps that the method will undertake.

Feature reformulation

As we mentioned before, the reformulation step is very important because hidden information can not be exploited without revealing it. Considering the propriety of the principal component analysis: The PCA outputs uncorrelated principal components, we reformulated the random variables of the features from the source and the target by applying a simple PCA to each dataset. Then, we took a percentage (10% for AR task and 40% for the OE task) of the principal components and consider them as our new reformulated features. In this reformulation method, we did not create a transformation matrix to transform the data into a new domain like we did in the previous method. But, by simply applying the PCA we transformed the original data into a new common feature space.

The following steps

After getting the reformulated features, we followed the same path as the previous method by calculating the divergence between the different variables using the Jensen-Shannon Divergence method. Then, we made a one-to-one mapping using the Gale-Shapley algorithm. We take into consideration the negative transfer by defining a threshold for the mapped pairs of features. Finally, we trained the target model using data from both domains. It has been proven in previous works that small amount of labeled data from the target added to the training improves significantly the performance of the target model [START_REF] Chen | Activity recognition using transfer learning[END_REF]. We tested this method for both tasks : AR and OE.

PCA-SMOTE method

The PCA-SMOTE method is an improved version of the the PCA-based method. It is an unsupervised domain adaptation method. It introduces the SMOTE (Synthetic Minority Over-sampling Technique) resampling [START_REF] Chawla | Smote: synthetic minority over-sampling technique[END_REF] to balance data. We followed the same steps of the PCA-based method and we introduced the data resampling in the general architecture as shown in Figure 7.

Simple feature matching method

This method is so basic compared to the previous ones. It is an unsupervised TL method that consists of a manual matching between similar features from different domains. In other words, we made a one-to-one mapping between identical features from different feature spaces. After this step, we obtained a huge amount of data from the source domain that can help the training of the target model. Figure 8 explains how the manual matching has been done. We looked for similar features from the source and the target domains and we matched them together such as ( 2 ,

3 ). The features that do not exist in both domain such as 1 and 1 , were ignored. This method has been tested for only the OE task because the datasets that we worked on contain similar features as well as a few numbers of features. When the number of features grows, the manual mapping becomes difficult to do. The goal of this method is to make a comparison between the performance of the methods that do not take into consideration the nature of features such as the 1 , 2 and 3 methods, and the methods that take into consideration the type of features such as the current method.

Supervised transfer sparse coding method (STSC)

In this section, we introduce the algorithm called Supervised Transfer Sparse Coding (STSC). This method takes into consideration the difference of probability between labeled data from the source domain and target domain. It tries to reduce the distributions divergence by creating new feature representations. To discuss the proposed method, we split it into two parts: sparse coding and domain transfer. The algorithm was inspired from [START_REF] Al-Shedivat | Supervised transfer sparse coding[END_REF].

Problem Definition

Let us consider = ( 1 , … , ) ∈ ℝ × a dataset where is theℎ feature vector of theℎ instance. The dataset contains instances with number of features. Let us consider the labels space  = ( 1 , … , ) ∈ ℝ as well, where is theℎ label of theℎ instance. For this problem, the training dataset is a combination of a huge number of instances from the source domain and few instances from the target domain. Indeed, it has been proven by [START_REF] Al-Shedivat | Supervised transfer sparse coding[END_REF] that a small number of samples from the target domain added to the training can improve significantly the generalization of the created model. For the evaluation, the testing dataset is a combination of source and target instances as shown in Figure 9. The main goal of this method is to create a robust model that is able to transfer knowledge from a source domain that contains a lot of data to a target domain where we have a lack of labeled data. To do this, we need to create a new representation for the data.

Sparse coding

Sparse coding is a technique that aims of finding a new representation of an input dataset using a transformation. The new representation is sparse, and it satisfies the assumption that each input vector is a linear combination of the basis vectors of the created transformation. Figure 10 illustrates the principal objective of sparse coding.

Let us consider an instance ∈ ℝ and a dictionary matrix = ( 1 , … , ) ∈ ℝ × , where is the number of features in the data, and is the number of codewords in the matrix . Sparse coding works by creating a dictionary where ̃ = ( 1 , … , ) is the sparse code that represents the sample .

The optimization problem that sparse coding method uses to calculate the dictionary matrix as well as the sparse code matrix = ( ̃ 1 , … , ̃ ) is the following:

min , ‖ - ‖ 2 s.t. ‖ ‖ ̃ ‖ ‖ 0 ≤ , = 1, … , ( 7
)
where C is constant, ‖ ‖ is the squared Frobenius norm which is calculated by summing the squares of the absolute elements of a given matrix, ‖ ‖ 0 is the 0 -norm which is calculated by counting the number of elements of a given vector that are not null.

The development of research has proven that the minimal 1 solution is the sparsest solution [START_REF] Donoho | For most large underdetermined systems of linear equations the minimal ��1-norm solution is also the sparsest solution[END_REF]. So, the problem will be updated to the following system:

min , ‖ - ‖ 2 + ∑ =1 ‖ ‖ ‖ ̃ ‖ ‖ ‖ 1 s.t. ‖ ‖ ‖ ‖ 2 2 ≤ 1, = 1, … , (8)
In this scenario, the goal of the constraint is to prevent the dictionary matrix from exploding. The variable is used as a regularization parameter, and the squared 2 norm is defined as the sum of the squared elements of a given codeword. We can define the first term of our problem as a reconstruction term that will give us a great representation of the provided input data . The second term can be interpreted as a sparsity penalty that will give us a sparse representation of the input samples. This type of optimization problem can be efficiently solved by an iterative algorithm like the one proposed by [START_REF] Lee | Efficient sparse coding algorithms[END_REF].

Domain transfer

In this section, we will introduce the additional terms that should be added to the optimization problem to create unified sparse codes that can be considered from the same domain.

Maximum Mean Discrepancy (MMD) regularization:

The has been used in previous research as a regularization term [START_REF] Long | Transfer sparse coding for robust image representation[END_REF]. It calculates the distance between the instances mean of the sparse code representations from both domains (  ,   ). Sparse codes with close distributions will have close to zero. The has the following formula:

= ‖ ‖ ‖ ‖ ‖ ‖ ‖ ⎛ ⎜ ⎜ ⎝ 1 ∑ ∶ ̃ - 1 ∑ ∶ ̃ ⎞ ⎟ ⎟ ⎠ ‖ ‖ ‖ ‖ ‖ ‖ ‖ 2 2 = ( ) (9)
The matrix is defined as follows:

= ⎧ ⎪ ⎨ ⎪ ⎩ 1∕( ) 2 ̃ , ̃ ∈   1∕( ) 2 ̃ , ̃ ∈   -1∕( ) ℎ (10)
Graph-Laplacian regularization: This method has been developed by [START_REF] Zheng | Graph regularized sparse coding for image representation[END_REF]. It aims to conserve the essential geometrical properties of the data distribution from both domains. In other words, if two samples have close intrinsic geometry of data distribution, then after calculating their codewords, they will remain close. This method has been added as a regularization term to the main optimization system (8). To define the regularization term, let us first define a matrix and a diagonal matrix that represent the k-nearest neighbor graph of the data, and the sum of the rows of the matrix , respectively.

∀ , ∈ [1, ] = ⎧ ⎪ ⎨ ⎪ ⎩ 1 ̃ ℎ - ℎ ̃ 0 ℎ (11) = ( 1 , … , ) (12)
where = ∑ =1 Now, we can define the Graph-Laplacian matrix as well as the Graph-Laplacian regularization term as follows :

= - (13) = ( ) (14)
Using the two regularization terms and , we can create a general regularization term ̃ that consists of their combination using two tuning parameters and .

( ̃ ) = ( ( + ) ) (15)
After defining this general regularization term, we add it to the main optimization system (8) and obtain the following optimization problem that corresponds to a work called transfer sparse coding [START_REF] Long | Transfer sparse coding for robust image representation[END_REF].

min , ‖ - ‖ 2 + ∑ =1 ‖ ‖ ‖ ̃ ‖ ‖ ‖ 1 + ( ̃ ) s.t. ‖ ‖ ‖ ‖ 2 2 ≤ 1, = 1, … , (16)

SVM-Based transfer correction:

The STSC has added a new term to the optimization problem ( 16) compared to the transfer sparse coding (TSC) algorithm. This term is a supervised transfer correction term that we will explain in this section. The goal of this regularization term is to better merge the classes from the source and the target domains. So, the resulting merged domain is easier to be classified than a domain obtained by TSC method [START_REF] Long | Transfer sparse coding for robust image representation[END_REF]. Figure 11 explains our objective in this section. Indeed, without SVM correction the merging of 4 classes may not be optimal and can be misleading. But, using the SVM transfer correction, the separability of classes after merging is better than before. The SVM term improves the performance of the model by using little amount of labeled data from the target space while training. To define this term, we introduce a matrix ∈ ℝ × that contains the hyperplane normal vectors of the different classes. We introduce a bias vector ∈ ℝ containing the intercepts of the hyperplane, and we define a matrix = ( , … , ) ∈ ℝ × that contains the biases of the different objects based on their original classes. We introduce another matrix Θ ∈ ℝ × that contains the margins of the instances with respect to all the available classes. At this step, we can define the new optimization problem:

min , , ‖ - ‖ 2 + ∑ =1 ‖ ‖ ‖ ̃ ‖ ‖ ‖ 1 + ( ̃ )+ ( 1 2 ‖ ‖ 2 + Θ ) s.t. ‖ ‖ ‖ ‖ 2 2 ≤ 1, = 1, … , -Θ ⪯ •( + ), Θ ⪰ 0 ( 17
)
where • is Hadamard product,⪯⪰ are element wise inequalities, and are hyperparameters, is a vector of ones and is a matrix of ones. This method can create sparse representations that contains classes worse or better separable than before. Indeed, it can sacrifice the separability of some classes to improve the performance of the model in general. We can monitor the way how the model treats the classes by the hyperparameter , and for better monitoring we can define a hyperparameter for each class .

Solving the optimization problem

To solve the Supervised Transfer Sparse Coding problem, we propose a method based on three iterative steps. Before defining the different steps, let us prepare the optimization problem. The LaGrange function of the optimization problem is the following :

( , , Θ, , , Γ, Λ, ) = ‖ - ‖ 2 + 2 ‖ ‖ 2 + ∑ =1 ‖ ‖ ‖ ̃ ‖ ‖ ‖ 1 + ( ̃ ) + ∑ =1 ( ‖ ‖ ‖ ‖ 2 2 -1) + [( + Λ)Θ +Γ•( -Θ -•( + ))] (18)
where Γ ∈ ℝ × , Λ ∈ ℝ × , and ∈ ℝ are the LaGrange multipliers.

Based on the duality theory we can solve this new optimization problem:

max Γ,Λ, min , ,Θ, , ( , , Θ, , , Γ, Λ, ) s.t. Γ ⪰ 0, Λ ⪰ 0, ⪰ 0 (19)
Applying the First-Order optimality condition over , and Θ gives us the following three conditions:

= (Γ• ) (Γ• ) = 0 Γ ⪯ (20)
Using these conditions, we obtain the final optimization problem:

max Γ, min ,   ( , , Γ, ) s.t. (Γ• ) = 0 ⪰ Γ ⪰ 0, ⪰ 0 (21)
where,

  ( , , Γ, ) = ‖ - ‖ 2 + ∑ =1 ‖ ‖ ‖ ̃ ‖ ‖ ‖ 1 + ∑ =1 ( ‖ ‖ ‖ ‖ 2 2 -1)+ ( ( ̃ - 1 2 Ψ) ) + Γ (22)
and,

Ψ = (Γ• ) (Γ• ) (23)
The previous problem can be solved in three steps. Firstly, using [START_REF] Lee | Efficient sparse coding algorithms[END_REF] algorithm, it is easy to solve the first optimization subproblem:

min ‖ - ‖ 2 + ∑ =1 ‖ ‖ ‖ ̃ ‖ ‖ ‖ 1 + ( ( ̃ - 1 2 Ψ) ) (24)
Secondly, by applying [START_REF] Lee | Efficient sparse coding algorithms[END_REF] algorithm, we can solve the second optimization subproblem:

max min ‖ - ‖ 2 + ∑ =1 ( ‖ ‖ ‖ ‖ 2 2 -1) s.t. ⪰ 0 (25)
Finally, using the interior-point method we can easily solve the following convex quadratic programming subproblem:

min Γ ( ( 1 2 Ψ) ) -Γ s.t. (Γ• ) = 0 ⪰ Γ ⪰ 0 (26)
The general algorithm of this problem is the following: Solving [START_REF] Nguyen | A statistical approach for unsupervised occupancy detection and estimation in smart buildings[END_REF] to get Γ and computing Ψ. 9 Output: Dictionary matrix , Sparse codes matrix .

The transfer correction that we discussed before can be clearly visible in this algorithm. Indeed, the Ψ learned from the SVM subproblem will be directly subtracted from ̃ which is the transfer and geometry matrix. So, this term will directly influence this matrix and will indirectly influence the dictionary matrix .

Modeling

After calculating the sparse representation of the testing data using the dictionary matrix, we can easily train a model using the reformulated data, and evaluate it using the testing data. In this method, we used the decision tree classifier as a model because it has been proven to be effective in AR and OE tasks [START_REF] Amayri | Estimating occupancy in heterogeneous sensor environment[END_REF] [START_REF] Amayri | Decision tree and parametrized classifier for estimating occupancy in energy management[END_REF]. Also, it will make it easy for us to compare the different methods used during this project.

Experimental setup and results

Datasets

Activities recognition dataset

For the AR task, few public datasets are available to use on the Internet. Most researchers use their private datasets. For our case, we used the Massachusetts Institute of Technology (MIT) dataset [START_REF] Tapia | Activity recognition in the home using simple and ubiquitous sensors[END_REF], which is a public dataset that contains data of two single-person apartments. Datasets are available at this website [START_REF] Of | Activity recognition in the home setting using simple and ubiquitous sensors[END_REF]. Each apartment dataset contains 2 weeks of labeled data. The data has been collected using reed switch sensors. These sensors are proximity binary sensors that have been attached to different objects such as doors, windows, refrigerator, containers, and so on. Figure 12 shows some locations where the sensors have been installed. The first home contains 77 sensors and the second one contains 84 sensors. The apartments owners had been labeling the datasets for 14 days. They had been labeling different types of activities as shown in Table 1, but we have just focused on the five common activities between the two apartments. The common labels are washing dishes, toileting, preparing breakfast, lunch, and dinner.

Occupancy estimation dataset

For the task of OE, we have the same problem as for the task of AR which is the lack of data. In this project, we used our private datasets [START_REF] Amayri | Estimating occupancy in heterogeneous sensor environment[END_REF][START_REF] Amayri | Decision tree and parametrized classifier for estimating occupancy in energy management[END_REF]. The data has been collected from two similar offices (H355 and H358) that are located in Grenoble Institute of Technology. The H358 dataset contains 20 days of labeled data, and the H355 dataset contains 6 days of labeled data. Figure 13 and Figure 14 show the locations of the used sensors in the two offices.

The sensor network contains video cameras to record the number of occupants, a database to store the data coming from the sensors and the sensors including power consumption sensors, CO2 concentration sensors, humidity sensors, temperature sensors, door and window contact sensors and acoustic pressure sensors.

Data preparation and implementation

For the AR datasets, we divided the data into intervals of 30 seconds. For each interval, if a sensor is triggered then its value will be set to 1, otherwise its values will be set to 0. After obtaining the prepared data, we selected the labels that are in common between the two apartments (preparing breakfast, preparing lunch, preparing dinner, toileting, and washing dishes). For the OE datasets, we divided the data into intervals of 10 minutes. In each interval, we take the average of values of a given sensor. If the sensor is a motion detector sensor: passive infrared (PIR) sensor, then we take the counting of motions during each interval. Indeed, PIR is a binary sensor that gives the value 1 each time it detects a motion. The labels that exist in these datasets are: No occupant, One occupant, and Two occupants. We prepared two datasets for each office: one dataset for the 4th method, and one dataset for the other introduced methods. We prepared a dataset that contains all the variables from both domains and that will be fed to the models without taking into consideration the nature of the variables. For the 4th method (Simple feature-matching method), it works by the simple matching between similar features from both domains. That is why, we prepared a specific dataset for this method that contains similar features from both domains as well as some created features using the original variables. For the 4th method, we did not take all the similar features, but we selected only the most significant features based on the results of previous research [START_REF] Amayri | Estimating occupancy in heterogeneous sensor environment[END_REF]. The method [START_REF] Amayri | Estimating occupancy in heterogeneous sensor environment[END_REF] has been introduced to estimate the number of occupants in an office. It starts by determining the most interesting features of the dataset based on information gains. Then, it uses decision trees in a supervised way to estimate occupancy.

Previous research [START_REF] Amayri | Estimating occupancy in heterogeneous sensor environment[END_REF] created new features that has been proven to be helpful such as:

• Average of all Power Consumptions: ∑

• Derivative CO2 Concentration: Δ 2 = 2 - 2 -1
• Motion Counting: sum of the values of the motions • Sound RMS: The root mean square of the amplitude of a recorded sound

Metrics

One of the challenges in this research work is the unbalanced data in both tasks. We took this problem into consideration by using different tools such as models hyperparameters, metrics and cross-validation. One of the ways stated before is the use of the appropriate metrics for the evaluation. We evaluated the performance of the methods using the F1-measure as well as the Precision and the Recall scores. For the last method where we introduced SMOTE to balance the data, we used both metrics F1-score and Accuracy.

To calculate these metrics, we need to extract four parameters (TP, TN, FP, and FN) from the confusion matrix:

• True Positive (TP) : This is the case where the algorithm correctly predicts the positive label

• True Negative (TN) : This is the case where the algorithm correctly predicts the negative label

• False Positive (FP) : This is the case where the algorithm incorrectly predicts the positive label

• False Negative (FN) : This is the case where the algorithm incorrectly predicts the negative label Now, we can calculate the desired metrics:

Precision (Pr) = 1 ∑ =1 + (27)
Recall (Rc) = 1 ∑ =1 + (28)
F-Score (F1) = 2 × × + (29)
Accuracy = + + + + (30)

Experimental results

STSC method results

The STSC method transfers the knowledge from source domains to a target domain using an approach based on sparse coding. The approach takes as input labeled training dataset of AR (huge amount of source data and small amount of target data), and it applies the presented steps to determine the dictionary matrix and the sparse codes of the input data. The obtained dictionary matrix will be used to determine the sparse codes of the testing dataset (a mixture between source and target data). After calculating the sparse representation of the testing data using the dictionary matrix, we train a decision tree model using the reformulated data and evaluate it using the testing data to obtain the desired prediction. Figure 15 and Table 2 show the performance of the STSC method on the AR task. Transferring knowledge from the source gives acceptable idea about the target without the need of instances from the target. This method takes into consideration the assumption of the importance of a few target data in the training [START_REF] Chen | Activity recognition using transfer learning[END_REF][START_REF] Al-Shedivat | Supervised transfer sparse coding[END_REF]. The obtained result without adding target data in the training is 30%. Adding target data in the training increases the performance of the model to reach 47%. Training with target data can harm the performance of the model as in the case when we add 8 days of target data. In this case, adding 6 days gives better performance than adding 8 days of labeled data from the target. Indeed, this is due to negative transfer coming from instances that do not improve the prediction function of the target task. We considered the STSC as unsuitable for our problem. The obtained results are acceptable and give ideas about the target task, but they did not meet our objective which is obtaining better results. The main cause of these results is the insufficient data that we are using. Indeed, the algorithm is of high complexity and requires sufficient labeled data to create the dictionary matrix and the sparse codes. Also, the quality of data such as unbalanced data can impact the results. The datasets that we are using are unbalanced, and this can be the cause of the obtained results.

Researchers have used the STSC method in the computer vision field [START_REF] Al-Shedivat | Supervised transfer sparse coding[END_REF]. They have trained it on tens of thousands of labeled data [START_REF] Al-Shedivat | Supervised transfer sparse coding[END_REF], and they got accuracies between 35% and 60%. For the OE task, we did not mention the results because the model did not recognize one label. Indeed, the OE datasets are more unbalanced than the AR datasets, and some labels contain small number of instances. For this reason, the STSC method did not perform well with the OE task. Indeed, it is not suitable for our problem. In future work, we will try to test it with bigger datasets.

Simple feature matching method resutls

We built this method to see the difference in performance between a method that takes into consideration the nature of features like this method, and other methods that do not take into consideration the type of features. The proposed method takes as input source and target labeled data of OE, and it selects and matches only similar features between the two domains. Then, it trains a target model using the source data and evaluates it using the target data to obtain the scores for the OE task. Based on the results, we can notice that the performance with a classical supervised learning method (89.31%) is greater than the results obtained without TL in previous approaches. Indeed, in this method, we applied some feature engineering by creating a lot of new interesting features such as sound RMS, motion counting and derivative CO2 concentration. Also, we can notice that the performance of the model with TL (61.64%) is less than the target results without TL (89.31%). The obtained results are good and can help develop target models without the need for target data which is costly and can be difficult to collect due to problems such as privacy.

We assume that methods that do not consider the nature of features will perform better than this method that considers the nature of variables. Indeed, matching similar features from different domains is not so accurate. For instance, matching door sensors does not mean that both sensors give the same information. An apartment can contain a lot of doors that gives different information such as the main entrance door and the back door. Also, the location of the sensor in doors (Top, Middle, Bottom) can impact the distribution of the feature.

PCA-based method results

The PCA-based method applies PCA directly to the data without taking into consideration the labels. The approach takes as inputs source and target datasets (AR data or OE data), and it applies PCA directly to the data. The PCA transformation, created without labeled data, transfers data from both domains to a common domain. After selecting the desired principal components, it uses Jenson-Shannon divergence to calculate the divergence between different PCs of the source and target domains and, based on the obtained results it applies the Gale-Shapley algorithm to match features from the two environments. After this step, it trains a target model using decision trees with the source data and evaluates it with testing data for both tasks (AR and OE). Figures 18 and19 describe the performance of the AR model and the Presence/Absence of Occupancy model, respectively. We started training without target data, and we obtained 28% and 68% as 1 -score for the AR and Presence/Absence of Occupancy tasks, respectively. For a start, it is a good achievement for Presence/Absence of Occupancy, but there is still more work to be done for the AR. The obtained result gives good idea about the target for Presence/Absence of Occupancy and helps to avoid the task of collecting data which is very costly. The obtained results with classical supervised learning methods trained using target data are 81% for the AR and 83% for the Presence/Absence of Occupancy. To exceed these scores, we started adding target data in the training. The 1 -score increases with 8% and 2% for a model trained using 10 days of AR target data and 4 days of Presence/Absence of Occupancy target data, respectively. The obtained models are robust and can create smart buildings applications with high performance. Tables 3 and4 shows the scores of the different labels in both tasks and Figures 16 and17 present the confusion matrices.

For the OE task, we increased the complexity for more levels of occupants. Figures 20, Figure

PCA-like method resutls

PCA-like method transfers knowledge from source domains to a target domain using an approach based on a transformation like PCA. The considered method takes as inputs source and target datasets (AR data or OE data), and it applies a PCA-like transformation using labeled data, for each domain, that takes into consideration the distributions of features given the labels. The transformations transfer data from both domains to a common domain. After selecting the desired reformulated features, it uses Jenson-Shannon divergence to calculate the divergence between the reformulated features of the source and target domains and, based on the obtained results it applies the Gale-Shapley algorithm to match features from the two environments. After this step, it trains a target model using decision trees with the source data and evaluates it with testing data for both tasks (AR and OE) to get the scores. Figure 23 shows the performance of the AR model on testing data. Collecting the required data to create a good classifier using classical supervised learning methods is very costly in smart building applications. Based on [START_REF] Chen | Activity recognition using transfer learning[END_REF][START_REF] Al-Shedivat | Supervised transfer sparse coding[END_REF], training using few data from the target domain improves the performance of the target model. In the beginning, we did not add target data in the training, we obtained 35% as 1 -score which gives an idea about the target task without the need of target data. But, there is still more work to be done to improve the results. To exceed the target score without TL (82%), we started adding target data in the training. Adding 2 days of labeled data in training increase the 1 -score by 47%. It is clear that few labeled data from the target domain increase significantly the scores of the model. Adding 10 days of labeled data from the target space in training improves the 1 -score with 8% compared to a trained model using 10 days of labeled data with a classical supervised learning method, and this proves the robustness of the current method. Table 6 gives the comparison between scores of the different labels and Figure 22 presents the confusion matrix.

For the Presence/Absence of Occupancy task, Figure 25 shows an increase in the target model performance with the increase of target data in the training as assumed in [START_REF] Chen | Activity recognition using transfer learning[END_REF][START_REF] Al-Shedivat | Supervised transfer sparse coding[END_REF]. Training without target data gives 77% as 1 -score which is a good result. The 1 -score increases significantly after knowledge transfer (90%) for a model trained using 4 days of target data and it exceeds the performance of classical supervised learning methods (87%) with 3%. Table 7 shows the comparison between scores of the different labels and Figure 24 presents the confusion matrix.

For OE, we extended the testing to a high levels of occupants. As shown in Figure 27, training with only source data gives 73% as 1 -score which is good and can give an excellent idea about the target task. The obtained results for OE when training using only source data is slightly lower than Presence/Absence of Occupancy task, and this was expected due to the increase of occupants levels. Adding 4 days of target data in the training gives 86% as 1 -score which is greater with 6% than classical supervised learning methods (80%). The obtained results are excellent for the task of OE, and they are slightly lower than the results of Presence/Absence of Occupancy task which is expected. The obtained results in all tasks with TL are greater than the scores obtained using the PCA-based method. It was expected to obtain these results because the previous method do not take into consideration the labels while reformulating the features. Table 8 shows the comparison between scores of the different labels and Figure 26 presents the confusion matrix.

PCA-SMOTE method results

In the PCA-SMOTE, we introduced data resampling using the SMOTE to solve the problem of imbalanced data. The imbalanced data was a serious issue for us while dealing with previous methods, especially for the STSC method. The PCA-SMOTE method is a PCA-based method improved with SMOTE to balance the input datasets. Using this method, we expect that the results of all tasks will exceed the PCA-based method results. For AR, Table 9, Figure 28 and As we have balanced the datasets for the PCA-SMOTE method, it is reasonable to test using an accuracy score. Table 12 illustrates the obtained accuracies for all tasks. For OE and P/A of occupancy, we trained the target model with 4 days of target data and for AR, we trained the target model with 10 days of target data. The obtained accuracies are good but, it is slightly lower than the target model score with a supervised machine learning method.

Comparing methods

For the AR, Figure 34 compares the performance of all tested methods. The PCA-SMOTE method has the best performance compared to the rest of the methods. Indeed, this method solves one of the biggest problems that we are facing during this work which is the unbalanced data. The PCAbased method and the PCA-like method have close resutls. The performance of the PCA-like method is in general better than the the PCA-based method. This is expected because the PCA-like method takes into consideration the distribution of the label space while calculating the transformation matrix. The PCA-based method applies PCA without taking into consideration the labels distribution. The STSC method is not good compared to the previous three methods. Indeed, the quantity and the quality of the used data are the main cause of the obtained results. For Presence/Absence of Occupancy, Figure 35 shows the different tested methods. The PCA-SMOTE remains the best method compared to the rest of the methods as shown previously in other tasks. It exceeds the closest method (PCA-like method) with 2%. PCA-like method is better than PCA-based method because it takes into consideration the distribution of labels while calculating the transformation. It exceeds the PCA-based method with 5%. For the OE, Figure 36 compares the obtained results. As we have discussed before, the PCA-SMOTE method is performing better than the rest of the methods. It exceeds the PCA-like method and the PCA-based method with 6% and 9%, respectively, at 4 days of training data from the target domain. The feature matching method trained using only source data and tested on target data performs better than PCA-based method and PCA-SMOTE method. But, it performs poorly compared to the PCA-like method. The feature matching method performs poorly compared to a PCA-SMOTE method, a PCA-like method and a PCA-based method trained using small amount of data from the target. The obtained results for Presence/Absence of Occupancy are greater than OE results for all the tested methods and this was expected due to the increase of occupants levels.

Conclusion

As the development of research in smart buildings is blocked in some directions because of the lack of data, it is necessary to find new tools to overcome this problem. That is why, we considered transfer learning. In this paper, we presented and discussed 5 basic transfer learning methods. The PCA-SMOTE method, the PCA-like method and the PCA-based method performed pretty good compared to the other methods. Indeed, these three methods do not take into consideration the nature of features. The PCA-SMOTE method is the best of all methods because it solves the problem of imbalanced data. The PCA-like method is slightly better than the PCA-based method because it considers the distribution of features given the labels while calculating the transformation. The simple feature matching method performed poorly compared to the first three methods when they are trained using a small amount of data from the target domain. This proves the efficiency of methods that do not consider the nature of features. The STSC method did not perform well in our case because of the unbalanced and small datasets. The tasks of OE (2 levels and 3 levels) performed better than the task of AR thanks to the good results obtained when training without target data. In future work, we will take into consideration the temporal dependency between the instances. Indeed, in this work, we ignored the labels transition and focused only on the labels. Also, we classified the instances using decision trees which do not take into consideration the temporal dependency. In addition, we will try to combine methods using tools such as model ensembling. For the STSC method, we will try to add new supervised transfer correction terms to the main optimization problem of new classifiers such as logistic regression. For the OE task, we will increase the prediction level to more occupants. To ensure reproducibility of the results by the research community and a potential future improvement of our framework by other researchers the complete source code is provided in the following repository: GitHub repository.

Figure 1 :

 1 Figure 1: TL example

Figure 2 :

 2 Figure 2: Transfer learning categories

Figure 3 :

 3 Figure 3: Transfer learning from data perspective

Figure 4 :

 4 Figure 4: The architecture of the PCA-like method

Figure 5 :

 5 Figure 5: Example of not visible information to models

Figure 6 :

 6 Figure 6: The architecture of the PCA-based method without transformation

Figure 7 :

 7 Figure 7: The architecture of the PCA-SMOTE method

Figure 8 :

 8 Figure 8: Manual matching

Figure 9 :

 9 Figure 9: Training and testing datasets

Figure 10 :

 10 Figure 10: Sparse vs dense

Figure 11 :

 11 Figure 11: TSC vs STSC

Algorithm 1 : 2 6 Solving ( 24 )

 12624 Supervised Transfer Sparse Coding 1 Input: Training dataset , Labels , Hyper-parameters ( , , , , ) , Iterations number -. Creating the MMD matrix and the GL matrix 3 Setting to a random matrix with zero mean columns 4 Γ← 0,Ψ ← 0 5 For loop( -) to get .

7 Solving ( 25 )

 725 to get .

8

 8

Figure 12 :

 12 Figure12: Sensors locations in the apartments[START_REF] Tapia | Activity recognition in the home using simple and ubiquitous sensors[END_REF]

Figure 13 :Figure 14 :

 1314 Figure 13: Sensors locations in H355

Figure 15 :

 15 Figure 15: STSC method : AR results

  [START_REF] Azam | Occupancy estimation using wifi motion detection via supervised machine learning algorithms[END_REF] and Table5

Figure 16 :

 16 Figure 16: PCA-based method : AR confusion matrix

Figure 17 :

 17 Figure 17: PCA-based method : Presence/Absence of Occupancy confusion matrix

Figure 19 :

 19 Figure 19: PCA-based method : Presence/Absence of Occupancy results

  performance. Compared to the Presence/Absence of Occupancy task, the performance of the model trained using only source data decreases slightly (9%). It was expected due to the increase of the occupants levels. Adding target data in the training increases significantly the performance of the target model. Training with 4 days of target data gives 82% as 1score which exceeds classical supervised learning methods (81%) with 1% which is a good achievement.

Figure 20 :

 20 Figure 20: PCA-based method : OE confusion matrix

Figure 21 :

 21 Figure 21: PCA-based method : OE results

Figure 22 :

 22 Figure 22: PCA-like Method : AR confusion matrix

Figure 23 :

 23 Figure 23: PCA-like Method : AR results

Figure 24 :Figure 25 :

 2425 Figure 24: PCA-like method : Presence/Absence of Occupancy confusion matrix

Figure 26 :Figure 27 :

 2627 Figure 26: PCA-like method : OE confusion matrix

Figure 29 show

 29 the obtained results. Training without target data gives 36% as 1 -score which gives an idea about the target without the need of target data. Adding target data in the training increases dramatically the performance of the target model till reaching 91% as 1 -score for 10 days of target data added in the training. The obtained results are excellent and expected. For the Presence/Absence of Occupancy and OE tasks, Tables 10 and 11 and Figures 30,31, 32 and 33 show the obtained results. Training using only source data gives 69%

Figure 28 :

 28 Figure 28: PCA-SMOTE method : AR confusion matrix

Figure 29 :

 29 Figure 29: PCA-SMOTE method : AR results

Figure 30 :Figure 31 :

 3031 Figure 30: PCA-SMOTE method : Presence/Absence of Occupancy confusion matrix

Figure 32 :Figure 33 :

 3233 Figure 32: PCA-SMOTE method : Presence/Absence of Occupancy results

Figure 34 :

 34 Figure 34: AR results

Figure 35 :

 35 Figure 35: Presence/Absence of Occupancy results

Figure 36 :

 36 Figure 36: OE results

Table 1

 1 MIT dataset description[START_REF] Tapia | Activity recognition in the home using simple and ubiquitous sensors[END_REF]

	Activities	S1 S2
	Preparing dinner	8	14
	Preparing lunch	17 20
	Listening to music	-	18
	Taking medication	-	14
	Toileting	85 40
	Preparing breakfast	14 18
	Washing dishes	7	21
	Preparing a snack	14 16
	Watching TV	-	15
	Bathing	18	-
	Going out to work	12	-
	Dressing	24	-
	Grooming	37	-
	Preparing a beverage 15	-
	Doing laundry	19	-
	Cleaning	8	-

Table 2

 2 STSC method : training with 10 days from AR target domain

	Scores	Without TL(%) With TL: 10 days(%)
	1	81.25	46.80
	1 -label1	86.71	53.78
	1 -label2	76.45	40.68
	1 -label3	83.05	31.01
	1 -label4	91.87	40.00
	1 -label5	39.77	74.03

Table 3

 3 PCA-based method : training using 10 days from AR target domain Scores Without TL(%) With TL: 10 days(%)

	1	81.25	89.09
	1 -label1	86.71	89.25
	1 -label2	76.45	81.54
	1 -label3	83.05	93.85
	1 -label4	91.87	85.71
	1 -label5	39.77	76.19

Table 4

 4 PCA-based method : training with 4 days from presence/absence of occupancy target domain

	Scores	Without TL(%) With TL: 4 days(%)
	1	83.42	85.39
	1 -label1	88.03	89.43
	1 -label2	73.04	76.36

Table 5

 5 PCA-based method : training using 4 days from OE target domain Scores Without TL(%) With TL: 4 days(%)

	1	80.74	82.02
	1 -label1	90.69	92.18
	1 -label2	58.33	51.51
	1 -label3	59.09	64.70

Table 6

 6 PCA-like method : training using 10 days from AR target domain Scores Without TL(%) With TL: 10 days(%)

	1	82.52	89.92
	1 -label1	87.80	90.28
	1 -label2	82.59	82.30
	1 -label3	82.41	93.59
	1 -label4	90.82	91.28
	1 -label5	44.13	75.00

Table 7

 7 PCA-like method : training with 4 days from Presence/Absence of Occupancy target domain Scores Without TL(%) With TL: 4 days(%)

	1	87.17	89.88
	1 -label1	91.30	93.28
	1 -label2	75.51	79.54

Table 8

 8 PCA-like method : training with 4 days from OE target domainScoresWithout TL(%) With TL: 4 days(%)

	1	79.68	85.96
	1 -label1	87.94	92.88
	1 -label2	51.61	61.01
	1 -label3	60.00	73.33

Table 9

 9 PCA-SMOTE method : training using 10 days from AR target domain Scores Without TL(%) With TL: 10 days(%)

	1	89.77	90.67
	1 -label1	86.19	88.25
	1 -label2	92.69	92.88
	1 -label3	85.13	87.54
	1 -label4	96.26	96.96
	1 -label5	88.61	88.09

Table 10

 10 PCA-SMOTE method : training with 4 days from Presence/Absence of Occupancy target domain Scores Without TL(%) With TL: 4 days(%)

	1	91.14	91.82
	1 -label1	90.55	91.21
	1 -label2	91.66	92.36

Table 11

 11 PCA-SMOTE method : training using 4 days from OE target domain Scores Without TL(%) With TL: 4 days(%)

	1	87.43	90.93
	1 -label1	90.63	90.83
	1 -label2	81.50	88.20
	1 -label3	90.03	93.23

Table 12

 12 Accuracies of AR, P/A of occupancy and OE tasks for PCA-

	SMOTE method
	Task	Without TL(%) With TL(%)
	Accuracy-AR	89.72	90.84
	Accuracy-P/A of occupancy	91.51	90.27
	Accuracy-OE	87.68	90.93

Acknowledgement

The completion of this research was made possible thanks to Natural Sciences and Engineering Research Council of Canada (NSERC) and the ANR-2021 Generic call of the French National Research Agency through the Learn-ingHome project. The authors would like to thank the associate editor and the reviewers for their helpful comments and suggestions.