Human Activity Tracking by Mobile Phones Through Hebbian Learning

A method for human activity recognition using mobile phones is introduced. Using the accelerometer and gyroscope typically found in modern smartphones, a system that uses the proposed method is able to recognize low level activities, including athletic exercises, with high accuracy. A Hebbian learning preprocessing stage is used to render accelerometer and gyroscope signals independent to the orientation of the smartphone inside the user’s pocket. After preprocessing, a selected set of features are obtained and used for classification by a k-nearest neighbor or a multilayer perceptron. The trained algorithm achieves an accuracy of 95.3 percent when using the multilayer perceptron and tested on unknown users who are asked to perform the exercises after placing the mobile device in their pocket without any constraints on the orientation. Comparison of performance with respect to other popular methods is provided.

video games at home on a Tuesday morning may actually be very similar to those of middle aged man working at the office. Thus high level activity recognition seems to be out of the scope of algorithms that only make use of accelerometer and gyroscope signals from smartphones. This also applies to many other high level activities such as going-on-a-vacation. The authors believe that positioning signals, time signals, and user provided data can be used by smartphones to identify high level activities. But this proposition is under the assumption that high level activities are sequences of low level activities that are somewhat similar as long as they are performed by the same individual, at the same location, and in the same seasonal timeframe. Still, most HAR research is at the current time focused on processing the signals coming out of available sensors in order to achieve better low level activity recognition. Researchers usually attempt to identify at least the most basic activities such as walking and not moving [4], [5], [6], [10], [11], [12], [13]. Some researchers push their algorithms further by making them identify a larger set of activities that includes walking, travelling the stairs up or down, or not moving [4], [5], [12]. Sports-related activities, such as remaining still, running, walking, and bicycling, have also been detected with accelerometers and gyroscopes [4], [12]. Some algorithms have been designed to distinguish amongst stationary activities such as sitting or remaining upright [4], [6], [10] [11]. In general, the contribution to low level activity recognition done by the algorithms in discussion is usually in the preprocessing, feature extraction, and classification stages they propose. In terms of accuracy, 90% levels are already achieved most of the time. The problem is not in the detection accuracy, but on the small number of activities that have been explored and on the usability of these algorithms outside of the laboratory.
Most wearable sensor based HAR algorithms, supervised, or unsupervised, are far from performing low level activity HAR with the level of accuracy that humans can achieve through a visual inspection. The ideal wearable sensor HAR algorithm would be able to recognize all of the low level activities performed by any user during an entire day. This is a task extremely easy for human beings by visual inspection, but currently impossible for smartphones. In general, human beings can perform a large number of activities throughout the day and this may be too much to ask for any contemporary machine.
There is an interrelationship between the activity set and the learning methods that can be used to identify each activity. One method that is good for detecting one set of activites (i.e., using kNN to classify walking, running, and other exercise activities) may not necessarily be the best choice for detecting another activity set (i.e., fall detection).Another issue with some studies is that outside of a lab setting, users position the smartphone with different orientations and on different on-body locations. Studies that have addressed this problem include [11] [14] [15] [16].
The placement architecture of the sensor array varies in reported research. Sensor arrays differ in the type of sensors, number of sensors, and location of sensors. In most cases, a single three-axial accelerometer is attached to the body, although in some cases more than one accelerometer have been used [4]. Up to 5 bi-axial accelerometers attached at locations in ankle, wrist, hip, arm, and thigh in [4] but it was determined that there was not much improvement in accuracy to using only hip and wrist or thigh and wrist locations. The waist location has already been studied in [4], [6], [11] and the pelvic region was studied in [5].
The way the data is captured is different for every researcher. The sampling rate is usually between 20 Hz [10], [13] and 50 Hz [5], [11]. Most researchers do not specify why they use a particular sample rate. The size of the window to be processed ranges from one second [6], [11], [12] up to ten seconds [10]. Windows that overlap at 50% were used in [4], [5] but no explanation is given about the benefit of using overlapping windows and whether this benefit depends on the period of the activity that is being monitored and the size of the window. Overlapping windows of 50% may be better for online recognition in the sense that they can provide the user with a classification result in intervals of time that are half the size of those of non-overlapping window Electronic copy available at: https://ssrn.com/abstract=3645111 systems. But they can also increase computational expense by mobile phones and increase the load on the battery as the calculations are performed online by the device.
Motion signals are usually preprocessed before performing classification. For example, spikes in the three axes of inertial sensors can be removed by using an FIR filter of fifth order with a cutoff close to .5 radians/sec or a similar filter, as done in [13]. A median filter can also be used, as done in [6]. Gravity can then be subtracted by additional preprocessing [6], [11]. Gravity was eliminated in [6] with a .25Hz cutoff elliptic low pass IIR filter of third-order. In [11] the signal is normalized by subtracting mean and dividing by standard deviation.
Currently, researchers obtain accuracies usually between 90 and 95% [6], [10], [11], [12] for HAR using wearable motion sensors. Accuracy greater than 99% has been reported in [13] for distinguishing between the states of walking and remaining idle. There are two popular ways of testing the accuracy of human activity recognition algorithms based on wearable sensor signals. When doing the personalized validation, the algorithm is trained and tested on each individual separately by using all frames of the individual in question but one. The algorithm is then tested on the remaining frame of that individual [4], [5], [12]. When performing the leave-one-subjectout type of validation the method in question is first trained on all subjects but one. The method is then tested on the remaining subject. Accuracy is typically higher in the personalized validation but the leave-one-user-out type of validation is also important because it is an indicator of potential for deployment to the masses. In some cases all frames from all users and all activities are mixed together into a pool and the system is tested by performing a folded cross-validation on a percentage of frames that are randomly chosen from the pool [5], [10], [12]. Most of the methods in question can classify the commonly practiced cyclic activities of jogging, walking, bicycling, going up or going down the stairs. For this type of activities, simple features such as the location and height of a peak in the frequency domain, the angle with respect to gravity, or a measurable period are not enough information to classify the activities. In such cases testing by cross-validation is possible because a data can also be used for training.
Not all algorithms of interest can be tested using cross-validation. In some cases, accuracy is calculated as the portion of frames in the dataset which are correctly classified [6], [10]. This is the case of algorithms that make decisions based on a small set of equations that are parameterized by just a few features, rather than by using classifiers trained on previous examples. The benefit of this type of algorithms is that they do not need to be trained and therefore are not overfitted to the dataset of the researcher. Also, these algorithms are not complex and processing intensive. However, they can only be used to distinguish simple activities, such as certain stationary positions, transitional activities, and being active or inactive. For example, setting a threshold for the angle between a horizontal axis (alternatively, an axis in the direction of gravity) and an axis that goes through the device from top to bottom can be used to distinguish between sitting and standing up. The method proposed in [6] can be used to identify the activities of falling, sitting, standing, being active while standing up, being active while lying, and lying on back, front, left, or right side of the body. The algorithm uses a decision thee that makes decisions based on thresholding of signal magnitude area, acceleration peaks, and an angle with respect to gravity. Validation based on the percentage of frames that are classified correctly without performing data partitioning for training and testing also applies to the algorithm proposed in [13]. In this case, the algorithm can discriminate between resting and walking by calculating an Average Magnitude Difference Function (AMDF) at a given delay and finding the location of peaks. In general, the performance of wearable inertial sensor-based HAR algorithms is usually shown in accuracy percentages and confusion tables.
There are some similarities between attachable motion sensor and smartphone based methods for HAR. First of all, the type of signals are typically accelerometer and gyroscope signals. Parameters for signal capture, such as the frame size and the rate of sampling can also be expected to be similar. Calculated features and methods of classification may also be similar between smartphone based methods and attachable motion sensor methods, even though sensor may be worn differently. Using a mobile phone typically means that the sensors will be attached to the arm or to the waist or inside a pocket. Already explored pockets include front pant pockets [10], [11], [12], shirt pockets [11], and jacket pockets [13]. When the inertial sensors or the smartphone device are attached to a body part, the orientation of the signals in the training and testing stages will be the same. In this case, high accuracy results can be expected. This situation is mostly seen in users who do not want the device jumping around through the empty space in their pockets while they exercise and at the same time do not want to hold it in their hands. Outside of these particular scenarios, the user can be expected to have the device in his hand(s), pockets, purse, or laying on a table or other flat surface. The algorithm proposed in this paper is tested in front pant pockets, but the authors expect decent performance on fixed scenarios as well, due to pocket signals being more unpredictable than fixed device signals. Pocket signals require more processing than fixed device signals in order to account for many additional factors. First, the device can be oriented on different ways as it is placed by the user on his/her pocket. Pocket signals are also different because the device bounces around in the free space of the pocket. Finally, the pocket deforms and moves on the surface of the body depending on the location of the pocket, clothing, and shape of the body. None of these effects are present in fixed orientation signals, where effects on variability are only due to the angle at which the device is attached around the limb, how far it is attached from the joint, and the size of the individual. Section 2 of this paper proposes a window-based as well as an adaptive method for obtaining orientation-invariant accelerometer and gyroscope signals. The features used by a proposed HAR algorithm that uses orientation-invariant signals and the method used to generate this list of features are described in Section 3. The classification stage of the HAR algorithm is described in Section 4 in a brief manner. Section 5 of the paper focuses on testing and performance of the HAR algorithm. Finally, Section 6 presents conclusions on the overall performance of the algorithm.

ORIENTATION-INVARIANT ACCELEROMETER AND GYROSCOPE SIGNALS
Currently most methods for HAR are based on wearable inertial sensors calculate features directly from the acceleration in the X, Y, and Z directions of the device's coordinate system. This means that, for those methods to give maximum accuracy, the device must be oriented the same way during the training and testing phases. In scenarios outside of the laboratory, however, the orientation of a smartphone with respect to the user's frame is less predictable. One way to eliminate the effect of random orientations is to process the signal in such a way that a particular activity always generates the same processed signal, but still different signals are obtained for different activities. This can be done by transforming the signal to a different coordinate system. This coordinate system may or may not be the same for all activities. A separate coordinate system can be used for each activity, as long as the resulting acceleration signatures are not the same. Principal component analysis (PCA) was used for preprocessing the motion signals in Electronic copy available at: https://ssrn.com/abstract=3645111 [11], [14], [15], [16]. Performance is to be evaluated differently from smartphone based methods to attachable accelerometer based methods. If the algorithm is to work regardless of the orientation of the accelerometers, performance must be evaluated by testing on several orientations. In such case, it can be evaluated by training on a single orientation and testing on several orientations as done in [11], or simply by training and testing on randomly chosen orientations, as done in [16].
A PCA was used in [11] to classify activities recorded with a mobile phone with a set of different orientations. Gravity was first eliminated by subtracting mean. This results in a signal that contains only linear acceleration, that is, the acceleration due to motion. The acceleration along the direction of the subtracted gravity signal is then used as an orientation-invariant component. An additional orientation-invariant component is then obtained by finding the principal component of acceleration on the plane orthogonal to the gravity vector. The third orientationinvariant signal is then found by taking the acceleration orthogonal to the other two components. A different approach to orientation-invariance was taken in [14], [15], where the PCA transform of acceleration was calculated in three-dimensions, and not only on the two dimensions orthogonal to gravity. Only the principal component of acceleration was used to extract features from in [14] [15]. Three PCA components of accelerometer and three PCA components of gyroscope where used in [16] to distinguish human activities by using a smartphone.
One of the disadvantages of using the method described above to obtain orientation-invariant signals is that the transform operation must be performed in an entire window in the vicinity of the sample of interest, so that transformation of the signal is typically performed in chunks that may or may not overlap, in order to reduce computational complexity. This introduces a minimum delay due to the spacing between the last sample of one window and the next one. Also, because the PCA transform is very signal dependent there may be "blind spots" in which part of the window corresponds to one activity and another part of the window corresponds to a different activity. In such cases, even though the PCA transform has provided a fully recoverable orientation-invariant signal, the transformed signal does not correspond to any of the stored activities, making it impossible to target the activity at the sample of interest.
Using the generalized Hebbian algorithm, orientation-invariant components for a motion sample can be calculated as soon as the 3-dimensional motion sample is received, without having to perform a PCA on an entire window of data around the sample of interest. This eliminates the lower boundary on the delay due to spacing between windows and delegates it to the feature extraction algorithm. Additionally, blind spots can be detected as changes in the transform operator. Once a blind spot has been spotted, the results of classification can be ignored in order to avoid delivering faulty results, or a different classification algorithm may be used to target the blind spot.

ORIENTATION-INVARIANT WINDOWS BY PRINCIPAL COMPONENT ANALYSIS
One way of obtaining a set of orientation-invariant motion signals is by applying principal component analysis (PCA) to the original accelerometer and gyroscope signals. The resulting six motion signal components can then be used for human activity recognition, as done in [16] and explained only for the sake of completeness in this paper. When using PCA transform signals, the orientation of the PCA coordinates with respect to the smartphone and the user willdepend on how variance in the 3-dimensional motion signals is distributed with respect to the smartphone and how the smartphone is positioned with respect to the user, making the coordinate system extremely case dependent. It is unlikely that two different activities of interest from a small set of activities will generate similar motion signatures. In this section, application of PCA to wearable inertial sensor 3-dimensional signals is described in detail. For a more in-depth discussion of PCA analysis on signals of even higher dimensionality the reader is referred to [17].
Electronic copy available at: https://ssrn.com/abstract=3645111 A sample of an acceleration frame is represented by where j i a is the jth acceleration sample in the ith coordinate. A window of acceleration samples can then be aggregated into a matrix where each row contains the samples for acceleration along one axis while each column is an acceleration vector sample. The PCA transform is applied on a centralized matrix that is calculated by subtracting the average acceleration vector from each column An orthonormal transform can be used to decorrelate the dimensions of A through the linear transformation where A P is the transform operator for the window A . This transform is found by performing a diagonalization of the covariance matrix of A .The covariance matrix of A is calculated as where Λ is a diagonal matrix with eigenvalues for A , and Φ is the orthonormal eigenvector matrix of A Ω . The PCA transform is then Once the signal has been preprocessed for orientation invariance, HAR can be done by using the pattern recognition techniques described before, so long as the motion detecting device (i.e., smartphone) is placed in the same location during training and testing.Similar preprocessing can also used to obtain orientation-invariant angular velocity signals. Three-axis gyroscopes output three signals. Each signal is the angular speed in rad/sec about an orthogonal axis. A typical coordinate system for smartphone motion signals is portrayed in Figure 1. In smartphones, the axes for accelerometers and gyroscopes are oriented the same way.
Angular frequency can be represented with a vector is a unit vector pointing in the direction of the axis of rotation and where i w is the angular frequency or speed about the i axis, and w is the angular speed around the axis of rotation of the angular velocity vector.Angular velocity vectors can also be made orientation-invariant by a linear transformation. In this case, the three signals obtained from the three-axial gyroscope are PCA transformed.
Many activities have distinguishing patterns in more than one of the six components that can be obtained through the transformations above. This can easily be understood by picturing a user jogging at a constant speed with the smartphone in his front right pocket. In this activity, the mobile phone moves back and forth in the direction the user is running, but also up and down as each foot jumps and falls back on the floor. The smartphone does not move along a single axis, so that more than one axis is needed to represent it. Therefore, using only the principal component from the PCA coordinate system may not be enough to discriminate between different activities in some cases. Similarly, angular velocity signals coming from gyroscopes are not necessarily well represented using only the principal component. When a user is jogging with a mobile phone in one of his/her front pant or short pockets, clothes can force the device to orbit around the user's leg, always facing the outside of the leg. This means the device will rotate about an axis that goes through it and that is parallel to the leg of the user. At the same time, due to the typical way humans move their legs when they run, the device will also orbit around a line going through the user's waist, perpendicular to gravity and the direction of running. Therefore, the principal component may not represent the rotations of the smartphone well enough to allow for accurate classification when there are several activities to be classified. Example PCA-transformed signals for the jogging activity are shown in Figure 2. In some activities, patterns can also be detected visually in the third component of the PCA transformation.

ORIENTATION-INVARIANT SAMPLES BY GENERALIZED HEBBIAN ALGORITHM
The generalized Hebbian algorithm is an unsupervised learning method based on Hebb's learning rule about the way synaptic strengths in the brain are adjusted. According to Hebb's learning rule, strengths of the synapses in the brain are adjusted through changes that are proportional to the pre-synaptic input and the output in the post-synaptic neuron, which means that the rate of adjustment is proportional to the correlation between the input and the output signals. This idea is used in the generalized Hebbian algorithm in order to decorrelate the components in a multidimensional signal.
The simplified neuron model is given by where w is a synaptic weight. Hebbs learning rule for neurons can be written as follows where i w ∆ is the change in the weight for i x . The weight update for every iteration can be written as Normalizing to ensure that the length of the weight vector is one so that the vector does not grow infinitely large, ( ) where 2 r = for Euclidean distance. Using a Taylor expansion, the expression for (t 1) i w + can be simplified Electronic copy available at: https://ssrn.com/abstract=3645111 Electronic copy available at: https://ssrn.com/abstract=3645111 The update for the weight can then be rewritten as This result is Oja's rule and is typically written in vector form as Oja's rule is related to the principal components. Substituting Upon convergence, w is approximately constant and 0 ∆ ≈ w so that the above equation can be rewritten as For the average T xx , the above equation can be written as which is the eigenvector, eigenvalue equation for x Ω , which is the covariance matrix for x . In general, the eigenvectors with the largest eigenvalues point in the direction of highest variance.
For a network with a single output neuron, only one eigenvector is defined by w . This eigenvector w points in the direction of the principal component. Therefore, for a single output neuron that learns via Oja's rule (18), it can be said that upon convergence, T w is the PCA Electronic copy available at: https://ssrn.com/abstract=3645111 transform operator and T w x is the principal component [18]. Multiple component extraction methods are explored in [19].
In this paper, the proposed method for HAR makes use of orientation-invariant signals obtained through the generalized Hebbian algorithm. Figure 2 shows the motion signals generated by a user as he is jogging. Figure 3 shows the difference between the total acceleration signal 2 2 2 x y z a a a + + and the signal recovered by inverting the transformation. Such curve, and the similarity between Hebbian components and PCA components can be used to verify convergence of the Hebbian algorithm

FEATURE EXTRACTION AND CLASSIFICATION
The feature set used by the system was created by selecting from a pool of features from [5][10] and [16]. In order to improve accuracy and reduce computational expenses, a feature selection was performed. Selection was done with a correlation-based feature selection (CFS) method proposed in [20], in conjunction with a backwards greedy search. The backwards greedy search starts by using all features and removes one at each iteration step. At each iteration, the feature to be eliminated from the selection is the one for which a figure of merit is maximized when the features is not included in the subset. The purpose of the CFS feature selection algorithm is to find a subset of features that are lowly correlated with each other, but highly correlated with the class label.
Features are eliminated at each iteration until no more eliminations can be done without diminishing performance. A figure of merit from [21] is used, Electronic copy available at: https://ssrn.com/abstract=3645111 However, in order to include categorical features and classes, which are also categorical, all continuous features are discretized using a discretization algorithm in [22]. Symmetrical uncertainty is then calculated between each pair of features and used instead of Pearson's correlation in (11). Such quantity has a value in the range [0,1]. Symmetrical uncertainty is calculated as where H is information entropy and ( ) is the mutual information or expected information gain for a given feature pair (X,Y). Information gain is the decrement in the entropy of X when the value of feature Y is known, or viceversa. As opposed to information gain, symmetrical uncertainty is a normalized quantity that is not biased by the number of categories in a feature.
The feature selection can be performed by adding or eliminating features one at a time or by testing several subsets by feeding each into the classifier and checking accuracy of results. But such method is computationally expensive. In such case, the resulting feature subset would also depend on the classifier. Using a performance metric, such as the one in (11) to calculate for each subset without actually having to feed it into the classifier is less computationally expensive.
In general, the resulting feature subset will not be optimal but it will be a local minimum that produces a smaller set of features and results in better accuracy, found with a reasonable amount of computational expense. The original pool of features was made of features chosen from those described in Section I and additional features proposed by the authors. The final set of features obtained after performing feature selection in the proposed algorithm are shown in Table 1. All the features obtained during the training stage were converted to z-scores.
The authors have chosen to use kNN because there are many implementations readily available. In this case the authors have used the WEKA implementation [23]. A disadvantage of instancebased algorithms is that they are computationally expensive. However, one benefit of instancebased algorithms is their ability to adapt to new data. New instances can be added to the training data simply by calculating features vectors and storing them, as opposed to other algorithms that may require the entire classification model to be calculated again, such as decision trees. Old instances can be eliminated easily as well for adaptation. Algorithms with such ability may prove advantageous when deploying to the masses, given that each user has his or her own way of performing an activity (i.e., different users may have a different gait). A multilayer perceptron was also chosen in our implementation because of the ability of neural networks to approximate any continuous function within an input interval to any desired level of accuracy. The approximation that results for discontinuous functions can still be useful. A neural network with a single hidden layer can approximate any function by adding more neurons to the hidden layer in order to increase accuracy. Neural networks are popular for solving pattern recognitions problems and there are also many implementations readily available. In this case the authors have chosen to use the WEKA implementation. SVM was not chosen for this study because it is computationally expensive. Decision trees were not chosen either to avoid overfitting due to the high number of features in use.
Electronic copy available at: https://ssrn.com/abstract=3645111 Euclidean distance was used with kNN. The highest accuracy was obtained using only one neighbor. For the multilayer perceptron, nodes with a sigmoid activation function were used. A momentum of .2 and a learning rate of .3 were used for training by backpropagation. The learning rate controls the size of the adjustments to the weights in the neural network as it is being trained by backpropagation. The momentum is a number in the range [0,1] that controls the rate of change in the adjustments. If the momentum is set to zero, the adjustments depend only on the learning rate, the error in the output of the neuron, and the value of the input, but not on the size of previous adjustments. If the momentum is set to one, the size of the adjustments will be constant. The network was trained by backpropagation for 500 epochs. A single epoch is one pass through all patterns in the training set.

TESTING
The proposed algorithm extracts the features in Table 1 from orientation-invariant signals obtained through the generalized Hebbian algorithmand classifies them either with a kNN classifier or a multilayer perceptron. The results for the multilayer perceptron are more accurate than those obtained when using kNN. Nevertheless, kNN results are also described here for completeness and because kNN is easier to implement than the multilayer perceptron. The algorithm was tested on exercise activities from university students. The athletic exercises in the database include resting, walking, jogging, squatting, and doing jumping jacks. Each user was asked to place the smartphone in the front right pocket. The users were not asked to place the smartphone with any particular orientation inside the pocket. Each exercise frame lasts for a total of 5 seconds. A total of 236 frames were captured.
The data was captured with a smartphone that houses an InvenSense MPU-6050 three-axial accelerometer and three-axial gyro sensor. The device also includes a Digital Motion Processor (DMP) which can be used to process the signals. The DMP can also be used to process signals coming from an external sensor, such as a magnetometer that can be interfaced through I2C. The MPU-6050 transfers the data to the host also via I2C. It outputs signals with a resolution of 16-bit and can be set to span four different ranges. The MPU-6050 has a printout of 4x4x.9mm. The smartphone used for this research does not take advantage of all the capabilities of the MPU-6050, but there are boards in the market that do Two different tests were performed: unknown-subject and single-subject. The unknown-subject test was done by training the system with all subjects except the unknown subject and then testing it on the frames from the subject on which the system was not trained. The overall accuracy of the unknown-subject was calculated by averaging accuracy across all subjects. The single-subject test, which evaluates performance when the algorithm is trained and tested in the same subject, was done by taking the samples from one subject and doing a 5-fold stratified cross-validation. The overall accuracy of the single-subject test was found by averaging accuracy across all folds and across all subjects.
A performance comparison was done with the methods in [5] and [10]. Both methods were simulated using the Weka toolkit in the classification stage. The algorithm in [5] has its own feature set and classifies instances with C4.5 and kNN. The method proposed in [10] also uses the Weka toolkit. This method was simulated by extracting the features in [10] from the acceleration window without applying orientation-invariant preprocessing, and then classifying with the multilayer perceptron and the C4.5 [24] classifiers in the Weka toolkit, using the settings that were also used for the proposed algorithm. No feature standardization procedure is mentioned in [10]. The results are shown in Table 2.
The proposed method outperforms the other two popular methods, which can easily be replicated in a lab setting and used as benchmarks. For the unknown-subject test, the proposed method performs much better than the other two methods, especially when using the multilayer perceptron. Performance improvement is expected given that different users position the smartphone in different orientations inside their pockets. A single user, however, may or may not be inclined to place the device in one particular orientation.
The high accuracy obtained with the proposed algorithm may also be due to feature standardization. For the unknown subject test the proposed algorithm obtained much higher results than the methods in [5] and [10]. For single subject activity recognition both classifiers yield accuracy higher than 95%. The authors propose using orientation-invariant preprocessing, the standardized features in Table 1, and a multilayer perceptron for classification. Yet, classification with kNN was also tested because it may be easier to implement for some of the readers. The confusion table for the test with unknown subjects with the proposed HAR algorithm is shown in Table 3.

CONCLUSION
The proposed method for human activity recognition using wearable motion sensors properly accounts for random orientations of the sensors. The method is particularly useful in the case of a smartphone inside a user's front pant pocket. The preprocessing stage of the proposed method renders the motion signals orientation-invariant. A small standardized feature set calculated from motion signals is then fed into a multilayer perceptron. The method introduced in this paper Electronic copy available at: https://ssrn.com/abstract=3645111 outperforms other modern methods when classifying several low level activities from unknown subjects, including exercises typically performed by athletes.