<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Human Movement | Sina Mehdizadeh, PhD</title><link>https://sinamehdiz.com/tag/human-movement/</link><atom:link href="https://sinamehdiz.com/tag/human-movement/index.xml" rel="self" type="application/rss+xml"/><description>Human Movement</description><generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><lastBuildDate>Thu, 02 Oct 2025 00:00:00 +0000</lastBuildDate><image><url>https://sinamehdiz.com/images/icon_hu0b7a4cb9992c9ac0e91bd28ffd38dd00_9727_512x512_fill_lanczos_center_3.png</url><title>Human Movement</title><link>https://sinamehdiz.com/tag/human-movement/</link></image><item><title>Pretraining a vanilla transformer for Human Movement activity classification from Wearable IMU Signals</title><link>https://sinamehdiz.com/project/imu-vanilla-transformer/</link><pubDate>Thu, 02 Oct 2025 00:00:00 +0000</pubDate><guid>https://sinamehdiz.com/project/imu-vanilla-transformer/</guid><description>&lt;h2 id="introduction">Introduction&lt;/h2>
&lt;p>Recognizing movement from wearable sensors can support human movement research and context-aware applications, but useful models must interpret noisy, multichannel time series and distinguish activities with similar postures. This project investigates whether transformer representations learned from inertial measurement unit (IMU) signals can be transferred to six-class human activity recognition (HAR). Using the UCI Human Activity Recognition dataset, I compared accelerometer (ACC), gyroscope (GYR), and combined ACC+GYR inputs, and evaluated both frozen-feature transfer and encoder fine-tuning.&lt;/p>
&lt;h2 id="methods">Methods&lt;/h2>
&lt;p>The forecasting model learns next-step sensor prediction from fixed-length UCI HAR windows. Each 128-sample window is shifted by one step to form inputs and targets; causal attention masks prevent access to future samples. The documented transformer uses a learned input projection, a six-layer encoder-decoder, eight attention heads, and mean squared error for prediction; it does not add explicit positional encodings.&lt;/p>
&lt;p>For movement classification, I transferred the pretrained encoder, retained causal attention, mean-pooled its time-step representations, and attached a linear six-class head. The three modality configurations used matching subject-level train/validation partitions and the official test set. I compared a frozen encoder with a fine-tuned encoder; runs used seed 0, batch size 32, and up to 50 epochs. Macro-F1 was the primary comparison metric to give each activity equal weight.&lt;/p>
&lt;h2 id="results">Results&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Sensor input&lt;/th>
&lt;th style="text-align:right">Frozen encoder macro-F1&lt;/th>
&lt;th style="text-align:right">Fine-tuned encoder macro-F1&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>ACC&lt;/td>
&lt;td style="text-align:right">0.5984&lt;/td>
&lt;td style="text-align:right">0.8374&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>GYR&lt;/td>
&lt;td style="text-align:right">0.5090&lt;/td>
&lt;td style="text-align:right">0.6617&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>ACC + GYR&lt;/td>
&lt;td style="text-align:right">0.6361&lt;/td>
&lt;td style="text-align:right">&lt;strong>0.8775&lt;/strong>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Fine-tuning improved macro-F1 across all three input configurations in this run. The combined accelerometer and gyroscope model achieved the strongest result, while the gyroscope-only model was lowest. The best run reached 0.8741 accuracy and 0.8775 macro-F1 across 2,947 test windows. These results demonstrate a working, controlled modality comparison and an end-to-end transfer-learning pipeline; without a matched model trained from scratch, they do not establish that pretraining caused the improvement.&lt;/p>
&lt;p>The selected run&amp;rsquo;s learning curves are shown in Figure 1. Figure 2 shows the test confusion matrix, with most remaining errors among sitting, standing, and laying.&lt;/p>
&lt;p>&lt;img src="./accgyr_finetune_history.png" alt="Training and validation cross-entropy loss and macro-F1 for the fine-tuned ACC+GYR model.">
&lt;em>Figure 1. Training and validation cross-entropy loss and macro-F1 over 50 epochs for the fine-tuned ACC+GYR model.&lt;/em>&lt;/p>
&lt;p>&lt;img src="./accgyr_finetune_confusion.png" alt="Test confusion matrix for the fine-tuned ACC+GYR model.">
&lt;em>Figure 2. Test confusion matrix for the fine-tuned ACC+GYR model.&lt;/em>&lt;/p>
&lt;p>For comparison, Figures 3 and 4 show the corresponding frozen-encoder linear-probe run.&lt;/p>
&lt;p>&lt;img src="./accgyr_probe_history.png" alt="Training and validation curves for the ACC+GYR linear probe with a frozen encoder.">
&lt;em>Figure 3. Training and validation cross-entropy loss and macro-F1 over 50 epochs for the ACC+GYR linear probe with a frozen encoder.&lt;/em>&lt;/p>
&lt;p>&lt;img src="./accgyr_probe_confusion.png" alt="Test confusion matrix for the ACC+GYR linear probe with a frozen encoder.">
&lt;em>Figure 4. Test confusion matrix for the ACC+GYR linear probe with a frozen encoder.&lt;/em>&lt;/p>
&lt;p>Figures 5-12 show the ACC-only and GYR-only plots for both transfer modes.&lt;/p>
&lt;p>&lt;img src="./acc_probe_history.png" alt="Training curves for the ACC-only linear probe with a frozen encoder.">
&lt;em>Figure 5. Training history for the ACC-only linear probe with a frozen encoder.&lt;/em>&lt;/p>
&lt;p>&lt;img src="./acc_probe_confusion.png" alt="Test confusion matrix for the ACC-only linear probe with a frozen encoder.">
&lt;em>Figure 6. Test confusion matrix for the ACC-only linear probe with a frozen encoder.&lt;/em>&lt;/p>
&lt;p>&lt;img src="./acc_finetune_history.png" alt="Training curves for the fine-tuned ACC-only model.">
&lt;em>Figure 7. Training history for the fine-tuned ACC-only model.&lt;/em>&lt;/p>
&lt;p>&lt;img src="./acc_finetune_confusion.png" alt="Test confusion matrix for the fine-tuned ACC-only model.">
&lt;em>Figure 8. Test confusion matrix for the fine-tuned ACC-only model.&lt;/em>&lt;/p>
&lt;p>&lt;img src="./gyr_probe_history.png" alt="Training curves for the GYR-only linear probe with a frozen encoder.">
&lt;em>Figure 9. Training history for the GYR-only linear probe with a frozen encoder.&lt;/em>&lt;/p>
&lt;p>&lt;img src="./gyr_probe_confusion.png" alt="Test confusion matrix for the GYR-only linear probe with a frozen encoder.">
&lt;em>Figure 10. Test confusion matrix for the GYR-only linear probe with a frozen encoder.&lt;/em>&lt;/p>
&lt;p>&lt;img src="./gyr_finetune_history.png" alt="Training curves for the fine-tuned GYR-only model.">
&lt;em>Figure 11. Training history for the fine-tuned GYR-only model.&lt;/em>&lt;/p>
&lt;p>&lt;img src="./gyr_finetune_confusion.png" alt="Test confusion matrix for the fine-tuned GYR-only model.">
&lt;em>Figure 12. Test confusion matrix for the fine-tuned GYR-only model.&lt;/em>&lt;/p>
&lt;h2 id="conclusions">Conclusions&lt;/h2>
&lt;p>On this UCI HAR experiment, combining acceleration and rotation signals and fine-tuning the pretrained encoder produced the strongest activity-classification result. The work applies sequence modeling, sensor-fusion comparisons, subject-aware evaluation, and transfer learning to a human movement problem. It also shows why aggregate accuracy alone is insufficient: macro-F1 helps expose uneven performance across locomotor and static activities.&lt;/p>
&lt;h2 id="limitations-and-future-directions">Limitations and Future Directions&lt;/h2>
&lt;p>These are single-seed results on one dataset, not evidence of generalization to new devices, populations, or movement settings. The pretrained models were evaluated on the official test split during pretraining; if those evaluations influenced model or checkpoint choices, the reported test scores are not an untouched final benchmark. Validation subjects' unlabeled sensor signals may also have appeared during pretraining. Most importantly, no matched from-scratch baseline is included, so the contribution of pretraining cannot be isolated.&lt;/p>
&lt;p>Next steps are to add a from-scratch baseline under identical splits and optimization settings, repeat runs across seeds, and reserve an untouched test set for final evaluation. Further experiments could compare positional encoding choices, causal versus bidirectional attention for whole-window classification, and performance across independent datasets or participant groups.&lt;/p>
&lt;h2 id="references">References&lt;/h2>
&lt;ol>
&lt;li>Anguita, D., Ghio, A., Oneto, L., Parra, X., and Reyes-Ortiz, J. L. (2013). “A Public Domain Dataset for Human Activity Recognition Using Smartphones.” &lt;em>ESANN 2013&lt;/em>.&lt;/li>
&lt;li>Vaswani, A., et al. (2017). “Attention Is All You Need.” &lt;em>Advances in Neural Information Processing Systems&lt;/em>.&lt;/li>
&lt;/ol></description></item><item><title>Causal Temporal Convolutions for Human Activity Classification</title><link>https://sinamehdiz.com/project/imu-tcn/</link><pubDate>Sat, 13 Sep 2025 00:00:00 +0000</pubDate><guid>https://sinamehdiz.com/project/imu-tcn/</guid><description>&lt;h2 id="introduction">Introduction&lt;/h2>
&lt;p>Wearable inertial sensors provide continuous signals that can distinguish movement, but robust activity recognition requires models to capture temporal structure across multiple channels. This study explores a two-stage transfer-learning pipeline: first learn from unlabeled sensor sequences through next-sample prediction, then reuse the temporal representation to classify human activities. The experiments compare a frozen-feature linear probe with end-to-end fine-tuning on the UCI Human Activity Recognition (HAR) dataset.&lt;/p>
&lt;h2 id="methods">Methods&lt;/h2>
&lt;p>The data contain six channels: three body-gyroscope axes and three body-acceleration axes. Each UCI HAR window has 128 readings sampled at 50 Hz, spans 2.56 seconds, and overlaps adjacent windows by 50%. Channels are standardized using training-set statistics. For pretraining, each window is shifted by one sample: the first 127 readings predict the following 127 targets. The causal temporal convolutional network (TCN) uses two residual blocks with kernel size 3, dilations 1 and 2, eight hidden channels, and dropout. Its encoder has a 13-sample receptive field; a pointwise prediction head maps features back to the six sensor channels. The predictor is trained with mean squared error and Adam.&lt;/p>
&lt;p>For classification, the pretrained encoder processes the first 127 readings. Mean pooling aggregates its temporal features, and a linear head predicts one of six activities: walking, walking upstairs, walking downstairs, sitting, standing, or laying. In probe mode, encoder weights are frozen; in fine-tuning mode, the encoder and head are optimized with separate learning rates. Both reported runs used 20 epochs, with a head learning rate of 0.01 and, for fine-tuning, an encoder learning rate of 0.001. Evaluation uses subject-separated training and validation partitions and the official test set. Macro-F1 is reported alongside accuracy.&lt;/p>
&lt;h2 id="results">Results&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Transfer mode&lt;/th>
&lt;th style="text-align:right">Test accuracy&lt;/th>
&lt;th style="text-align:right">Test macro-F1&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Frozen encoder + linear probe&lt;/td>
&lt;td style="text-align:right">46.1%&lt;/td>
&lt;td style="text-align:right">0.3968&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Fine-tuned encoder + linear head&lt;/td>
&lt;td style="text-align:right">&lt;strong>77.5%&lt;/strong>&lt;/td>
&lt;td style="text-align:right">&lt;strong>0.7801&lt;/strong>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>The fine-tuned run scored higher than the frozen probe on both metrics in this comparison. Its strongest class F1 scores were for walking (0.981), walking downstairs (0.949), and walking upstairs (0.943); sitting remained more difficult (0.457). Scores are from the final epoch on 2,947 test windows. With one recorded run per mode and no matched randomly initialized baseline, these outcomes are preliminary and do not isolate the benefit of pretraining.&lt;/p>
&lt;p>Figures 1 and 2 show the frozen-probe training curves and test confusion matrix. Figures 3 and 4 show the corresponding fine-tuned results.&lt;/p>
&lt;p>&lt;img src="./tcn_probe_history.png" alt="Training and validation cross-entropy loss and macro-F1 for the frozen-encoder TCN probe.">
&lt;em>Figure 1. Training and validation cross-entropy loss and macro-F1 over 20 epochs for the frozen-encoder probe.&lt;/em>&lt;/p>
&lt;p>&lt;img src="./tcn_probe_confusion.png" alt="Test confusion matrix for the frozen-encoder TCN probe.">
&lt;em>Figure 2. Test confusion matrix for the frozen-encoder probe.&lt;/em>&lt;/p>
&lt;p>&lt;img src="./tcn_finetune_history.png" alt="Training and validation cross-entropy loss and macro-F1 for the fine-tuned TCN.">
&lt;em>Figure 3. Training and validation cross-entropy loss and macro-F1 over 20 epochs for the fine-tuned model.&lt;/em>&lt;/p>
&lt;p>&lt;img src="./tcn_finetune_confusion.png" alt="Test confusion matrix for the fine-tuned TCN.">
&lt;em>Figure 4. Test confusion matrix for the fine-tuned model.&lt;/em>&lt;/p>
&lt;h2 id="conclusions">Conclusions&lt;/h2>
&lt;p>This TCN pipeline demonstrates how causal convolutions can learn local temporal features from multichannel inertial data and how those features can be transferred to activity classification. In the two recorded runs, fine-tuning substantially outperformed using the pretrained encoder as a frozen feature extractor. The per-class results also show that strong recognition of locomotor activities does not guarantee equally strong recognition of static postures.&lt;/p>
&lt;h2 id="limitations-and-future-directions">Limitations and Future Directions&lt;/h2>
&lt;p>The comparison contains one run per transfer mode, reports the final epoch rather than a validation-selected checkpoint, and has no fully supervised from-scratch baseline. The encoder&amp;rsquo;s 13-sample receptive field is short relative to a full activity window, and mean pooling does not explicitly preserve global temporal order. In addition, validation subjects' unlabeled signals contributed to pretraining and scaler fitting. The predictor was evaluated on the official test split during pretraining; if those scores influenced model choices, the test set is not an untouched benchmark.&lt;/p>
&lt;p>Next steps are to repeat experiments across controlled random seeds, select checkpoints using validation data, compare against a matched model trained from random initialization, and hold validation subjects out before pretraining and normalization. Expanding the receptive field and comparing pooling strategies could test how longer-term temporal context affects static and transitional activities. Final claims should use a test set that has not informed model or hyperparameter decisions.&lt;/p>
&lt;h2 id="references">References&lt;/h2>
&lt;ol>
&lt;li>Anguita, D., Ghio, A., Oneto, L., Parra, X., and Reyes-Ortiz, J. L. (2013). “A Public Domain Dataset for Human Activity Recognition Using Smartphones.” &lt;em>ESANN 2013&lt;/em>.&lt;/li>
&lt;li>Bai, S., Kolter, J. Z., and Koltun, V. (2018). “An Empirical Evaluation of Generic Convolutional and Recurrent Networks for Sequence Modeling.”&lt;/li>
&lt;li>Project materials: &lt;a href="tcn_imu_classification_description.md">TCN study description&lt;/a>, &lt;a href="TCN_IMU.py">TCN implementation&lt;/a>, &lt;a href="tcn_classification.py">classification implementation&lt;/a>, and &lt;a href="../tcn_classification_results/comparison.md">recorded classification results&lt;/a>.&lt;/li>
&lt;/ol></description></item><item><title>Deep Reinforcement Learning To Improve Gait Adaptation</title><link>https://sinamehdiz.com/project/locomotion-deep-rl/</link><pubDate>Sat, 01 Mar 2025 00:00:00 +0000</pubDate><guid>https://sinamehdiz.com/project/locomotion-deep-rl/</guid><description>&lt;h2 id="introduction">Introduction&lt;/h2>
&lt;p>People learn new optimal gaits when adapting to new conditions. In these adaptations, they rapidly transition between a wide range of speeds or step lengths without falling. In this study, we aimed to determine whether reinforcement learning (RL) can enhance the performance of a pre-trained neural network control policy in adapting a walking model to a wide range of gaits.&lt;/p>
&lt;h2 id="we-used-a-physics-based-model-of-walking">We used a physics-based model of walking&lt;/h2>
&lt;p>This model can walk with different step lengths and speeds [1,2]. It is actuated by a push off (P) and a two hip springs (k1 and k2), each active in one half of the swing. We discretized the space of possible step lengths and frequencies into a grid of step lengths and frequencies. We used optimization (Matlab’s fmincon) to find limit-cycle gaits at each grid point&lt;/p>
&lt;p>&lt;img src="./biped_model.png" alt="This model can walk with different step lengths and speeds [1,2]">&lt;/p>
&lt;h2 id="results">Results&lt;/h2>
&lt;h3 id="a-wide-range-of-gaits-exist">A wide range of gaits exist&lt;/h3>
&lt;p>The walker can have a limit-cycle walks in a wide range of step lengths and speeds that goes beyond human walking.&lt;/p>
&lt;p>&lt;img src="./state_space.png" alt="A wide range of gaits exist">&lt;/p>
&lt;h3 id="adaptation-is-possible-with-feedback-control">Adaptation is possible with feedback control&lt;/h3>
&lt;p>But some of the walks are passively unstable and and therefore unable to adapt to target gaits without active control. Thus active feedback control of the walker is needed. We used pole placement to determine controller gains. The feedback controller increased basin of attraction for all gaits&lt;/p>
&lt;p>&lt;img src="./state_space_stability.png" alt="The feedback controller increased basin of attraction for all gaits">&lt;/p>
&lt;p>The general control policy can track sine paths in different regions of the gait space demonstrating successful adaptation&lt;/p>
&lt;p>&lt;img src="./traj_preRL.png" alt="The general control policy can track sine paths in different regions of the gait space demonstrating successful adaptation">&lt;/p>
&lt;h3 id="reinforcement-learning-improved-adaptation">Reinforcement learning improved adaptation&lt;/h3>
&lt;p>We used RL to further enhance the performance of the pre-trained neural network controller. We used deep deterministic policy gradient [3] with the actor being the pre-trained neural network and the critic being an untrained neural network with two hidden layers of size 256. We added noise to the actions for local exploration. The average reward improved by 4.88±3.01% for all paths.&lt;/p>
&lt;p>&lt;img src="./rl_training_plot.png" alt="The average reward improved by 4.88±3.01% for all paths.">&lt;/p>
&lt;p>RL improved the pre-trained policy by tracking the target paths more closely. The RL training improved adaptation rate by reducing the minimum number of steps required to complete the paths. The RL training in one task generalized to another&lt;/p>
&lt;p>&lt;img src="./traj_RL.png" alt="RL improved the pre-trained policy by tracking the target paths more closely">&lt;/p>
&lt;h3 id="a-neural-network-control-policy-for-adaptation">A neural network control policy for adaptation&lt;/h3>
&lt;p>We used the algorithmic general control policy to train a compact neural network controller. We trained the neural network on a sample of 500,000 input/output pairs to serve as the baseline. The neural network control policy archives identical performance in adaptation compared to the algorithmic control policy&lt;/p>
&lt;p>&lt;img src="./nn.png" alt="A neural network control policy for adaptation">&lt;/p>
&lt;p>&lt;img src="./traj_nn.png" alt="the neural network control policy archives identical performance in adaptation compared to the algorithmic control policy">&lt;/p>
&lt;h2 id="discussion-and-conclusions">Discussion and Conclusions&lt;/h2>
&lt;p>Achieving better performance in regions with long step length and slow step frequency (top left). Adaptation in gaits with long step length and slow step frequency remains a challenge&lt;/p>
&lt;h2 id="future-directions">Future Directions&lt;/h2>
&lt;ul>
&lt;li>Using RL in a hierarchical design to explore energy-optimal walking&lt;/li>
&lt;li>Understanding principles of energy optimal adaptations&lt;/li>
&lt;li>Accelerate energy-optimal gait adaptation&lt;/li>
&lt;/ul>
&lt;h2 id="references-and-funders">References and Funders&lt;/h2>
&lt;ol>
&lt;li>Garcia et al. J Biomech Eng 120, 281-88, 1998&lt;/li>
&lt;li>Kuo. J Biomech Eng 123, 264-69, 2001&lt;/li>
&lt;li>Lillicrap et al. ICLR, Puerto Rico, 2016&lt;/li>
&lt;/ol></description></item></channel></rss>