PLF-Mamba: Analyzing Individual Milk Yield Dynamics Under Data Scarcity Using Selective State Space Models
Abstract
1. Introduction
- We propose an integrated RL–Mamba learning framework tailored to PLF data characterized by sparse daily labels, real-farm measurement distortions, and strong individual heterogeneity.
- We show that the proposed approach reduces cow-wise performance variability compared with Transformer and other baseline models, mitigating performance collapse on difficult, noise-affected cows.
- Through ablation studies, we demonstrate that dynamic feature gating is a key component for maintaining predictive stability when supervision is limited and sensor streams contain frequent distortions.
2. Materials and Methods
2.1. Dataset Description and Preprocessing
2.1.1. Sensor Modalities
- Behavioral Metrics (IMU and UWB):A neck-mounted sensor node records tri-axial acceleration and ultra-wideband (UWB) signals. Over 10-min intervals, we compute the standard deviation of the acceleration magnitude (Activity) and the variance of the UWB signal (Roaming). While these metrics represent movement intensity, they are prone to mechanical noise caused by non-locomotive behaviors, such as scratching against fences (grooming) or physical interactions with herd mates, which can produce high-variance artifacts unrelated to actual activity levels.
- Physiological Status (Bolus): An indwelling reticulorumen bolus measures core body temperature (CBT) and internal pressure. Although these reflect metabolic status, the raw signals are frequently distorted by transient biological events, most notably rapid water intake (which causes sharp temperature drops) or rumen contractions, creating temporary deviations from the true physiological state.
- Environmental Context (THI): A local weather station logs the temperature–humidity index (THI), a standard metric for assessing heat stress. While generally stable, micro-climate variations within the barn (e.g., proximity to fans or sprinklers) can introduce spatial discrepancies between the sensor reading and the cow’s actual thermal experience.
2.1.2. Data Preprocessing and Windowing
2.2. Proposed Framework: PLF-Mamba
2.3. Stage 1: Dynamic Feature Selection via Policy Gradient
2.3.1. Problem Formulation
2.3.2. Justification for Algorithm Selection
2.3.3. (i) Policy Network
2.3.4. (ii) Reward Function and Policy Optimization
2.3.5. (iii) Selective State Space Model (SSM)
2.3.6. (iv) Selective Scan Mechanism and Biological Interpretation
2.4. Implementation Details
2.5. Validation Strategy
- 1.
- Non-normality under small sample size: With a limited cohort ( heads), the normality assumption required for parametric paired tests (e.g., a paired t-test) is difficult to verify and may not hold.
- 2.
- Paired comparison with effect magnitude: Because all models are evaluated on the same set of heads (paired samples), the Wilcoxon signed-rank test is more appropriate than the Mann–Whitney U test, which assumes independent samples. Moreover, unlike the Sign Test, it accounts for the magnitude of within-head performance differences, providing a more informative comparison.
3. Results
3.1. Preliminary Analysis: Heterogeneity and Non-Stationarity
3.1.1. Individual Variability in Feature Prioritization
3.1.2. Limitations of Simple Correlation Analysis
3.2. Quantitative Performance Comparison
Stability and Robustness Analysis
3.3. Qualitative Analysis
4. Discussion
4.1. Why Mamba Outperforms Transformer in Livestock Monitoring
4.2. The Critical Role of Dynamic Feature Gating
4.3. Implications for Digital Livestock Farming
4.4. Limitations and Future Work
5. Conclusions
- 1.
- Accuracy and animal-level robustness. PLF-Mamba achieved the highest mean predictive performance () among the evaluated models and exhibited improved robustness relative to the Transformer baseline (). In particular, the Transformer showed markedly degraded performance on specific cows with highly volatile signals, whereas PLF-Mamba maintained more stable performance across individuals. These results suggest that selective state space dynamics can be advantageous in small, noisy biological time-series settings.
- 2.
- Contribution of dynamic gating (ablation evidence). In the ablation setting where the RL-based gating module was removed while keeping the temporal predictor unchanged, performance decreased substantially (average ). This observation indicates that, for the studied dataset, learning directly from raw multi-modal streams without adaptive feature selection is insufficient, and that dynamic gating is a key component of PLF-Mamba under data scarcity and noise.
- 3.
- Individual-specific modality prioritization. Analysis of the learned gating policy revealed that the prioritized sensor modalities differ across cows and over time. While this does not establish causality, it provides model-based evidence consistent with the premise that informative signals for milk yield forecasting are individual- and context-dependent. Such prioritization patterns may serve as a useful diagnostic for domain experts when interpreting model behavior and planning targeted sensing or management actions.
Author Contributions
Funding
Data Availability Statement
Acknowledgments
Conflicts of Interest
References
- Danev, V.; Atanasova, T.; Dineva, K. Multi-Sensor Platform in Precision Livestock Farming for Air Quality Measurement Based on Open-Source Tools. Appl. Sci. 2024, 14, 8113. [Google Scholar] [CrossRef]
- Lamanna, M.; Bovo, M.; Cavallini, D. Wearable Collar Technologies for Dairy Cows: A Systematized Review of the Current Applications and Future Innovations in Precision Livestock Farming. Animals 2025, 15, 458. [Google Scholar] [CrossRef] [PubMed]
- Paolino, R.; Trana, A.D.; Coppola, A.; Sabia, E.; Riviezzi, A.M.; Vignozzi, L.; Claps, S.; Caparra, P.; Pacelli, C.; Braghieri, A. May the Extensive Farming System of Small Ruminants Be Smart? Agriculture 2025, 15, 929. [Google Scholar] [CrossRef]
- Tangorra, F.M.; Buoio, E.; Calcante, A.; Bassi, A.; Costa, A. Internet of Things (IoT): Sensors Application in Dairy Cattle Farming. Animals 2024, 14, 3071. [Google Scholar] [CrossRef]
- Hashimoto, Y.; Zin, T.T.; Tin, P.; Kobayashi, I.; Hama, H. Generating Accurate Activity Patterns for Cattle Farm Management Using MCMC Simulation of Multiple-Sensor Data System. Sensors 2025, 25, 6781. [Google Scholar] [CrossRef]
- Fan, X.; Ma, J. A Spatial Econometric Analysis of Weather Effects on Milk Production. Earth 2024, 5, 477–490. [Google Scholar] [CrossRef]
- Pinto, D.; Santos, R.; Maia, C.; Bartolomé, E.; Niza-Ribeiro, J.; d’Anjo, M.C.; Batista, M.; Conceição, L.A. Digital Environmental Management of Heat Stress Effects on Milk Yield and Composition in a Portuguese Dairy Farm. AgriEngineering 2025, 7, 231. [Google Scholar] [CrossRef]
- Dittrich, I.; Gertz, M.; Krieter, J. Alterations in Sick Dairy Cows’ Daily Behavioural Patterns. Heliyon 2019, 5, e02902. [Google Scholar] [CrossRef]
- Fuentes, S.; Gonzalez Viejo, C.; Tongson, E.; Lipovetzky, N.; Dunshea, F.R. Biometric Physiological Responses from Dairy Cows Measured by Visible Remote Sensing Are Good Predictors of Milk Productivity and Quality through Artificial Intelligence. Sensors 2021, 21, 6844. [Google Scholar] [CrossRef]
- Dineva, K.; Atanasova, T. Health Status Classification for Cows Using Machine Learning and Data Management on AWS Cloud. Animals 2023, 13, 3254. [Google Scholar] [CrossRef]
- Cabrera, V.E.; Bewley, J.; Breunig, M.; Breunig, T.; Cooley, W.; De Vries, A.; Fourdraine, R.; Giordano, J.O.; Gong, Y.; Greenfield, R.; et al. Data Integration and Analytics in the Dairy Industry: Challenges and Pathways Forward. Animals 2025, 15, 329. [Google Scholar] [CrossRef]
- D’Urso, P.R.; Arcidiacono, C.; Pastell, M.; Cascone, G. Assessment of a UWB Real Time Location System for Dairy Cows’ Monitoring. Sensors 2023, 23, 4873. [Google Scholar] [CrossRef]
- Kurtuluş, Y.; Şahin, H.; Atalan, A. Statistical Optimization and Analysis of Factors Maximizing Milk Productivity. Animals 2025, 15, 1475. [Google Scholar] [CrossRef]
- Soumri, N.; Carabaño, M.J.; González-Recio, O.; Bedhiaf-Romdhani, S. Modelling heat stress effects on milk production traits in Tunisian Holsteins using a random regression approach. J. Anim. Breed. Genet. 2025, 142, 155–169. [Google Scholar] [CrossRef] [PubMed]
- Shao, R.; Bi, X.-J. Transformers Meet Small Datasets. IEEE Access 2022, 10, 118454–118464. [Google Scholar] [CrossRef]
- Lee, S.; Lee, S.; Song, B.C. Improving Vision Transformers to Learn Small-Size Dataset from Scratch. IEEE Access 2022, 10, 123212–123224. [Google Scholar] [CrossRef]
- Zeng, A.; Chen, M.; Zhang, L.; Xu, Q. Are Transformers Effective for Time Series Forecasting? Proc. AAAI Conf. Artif. Intell. 2023, 37, 11121–11128. [Google Scholar] [CrossRef]
- Zeyer, A.; Bahar, P.; Irie, K.; Schlüter, R.; Ney, H. A Comparison of Transformer and LSTM Encoder–Decoder Models for ASR. In Proceedings of the 2019 IEEE Automatic Speech Recognition and Understanding Workshop (ASRU), Singapore, 14–18 December 2019; IEEE: New York, NY, USA, 2019; pp. 8–15. [Google Scholar] [CrossRef]
- Vaswani, A.; Shazeer, N.; Parmar, N.; Uszkoreit, J.; Jones, L.; Gomez, A.N.; Kaiser, Ł.; Polosukhin, I. Attention Is All You Need. Adv. Neural Inf. Process. Syst. 2017, 30, 6000–6010. [Google Scholar]
- Babiloni, F.; Marras, I.; Deng, J.; Kokkinos, F.; Maggioni, M.; Chrysos, G.; Torr, P.; Zafeiriou, S. Linear Complexity Self-Attention with 3rd-Order Polynomials. IEEE Trans. Pattern Anal. Mach. Intell. 2023, 45, 12726–12737. [Google Scholar] [CrossRef]
- Guo, M.-H.; Liu, Z.-N.; Mu, T.-J.; Hu, S.-M. Beyond Self-Attention: External Attention Using Two Linear Layers for Visual Tasks. IEEE Trans. Pattern Anal. Mach. Intell. 2022, 45, 5436–5447. [Google Scholar] [CrossRef] [PubMed]
- Gu, A.; Dao, T. Mamba: Linear-Time Sequence Modeling with Selective State Spaces. In Proceedings of the First Conference on Language Modeling, Philadelphia, PA, USA, 7–9 October 2024. [Google Scholar]
- Liu, X.; Zhang, C.; Huang, F.; Xia, S.; Wang, G.; Zhang, L. Vision Mamba: A Comprehensive Survey and Taxonomy. IEEE Trans. Neural Netw. Learn. Syst. 2025, 37, 505–525. [Google Scholar] [CrossRef]
- Wang, Y.; Chen, Y.; Yan, J.; Lu, J.; Sun, X. MemMamba: Rethinking Memory Patterns in State Space Model. arXiv 2025, arXiv:2510.03279. [Google Scholar] [CrossRef]
- Patro, B.N.; Agneeswaran, V.S. Mamba-360: Survey of State Space Models as Transformer Alternative for Long Sequence Modelling: Methods, Applications, and Challenges. arXiv 2024, arXiv:2404.16112. [Google Scholar] [CrossRef]
- Vu, H.; Prabhune, O.C.; Raskar, U.; Panditharatne, D.; Chung, H.; Choi, C.; Kim, Y. MmCows: A Multimodal Dataset for Dairy Cattle Monitoring. Adv. Neural Inf. Process. Syst. 2024, 37, 59451–59467. [Google Scholar]
- Barto, A.G.; Sutton, R.S.; Anderson, C.W. Neuronlike Adaptive Elements That Can Solve Difficult Learning Control Problems. IEEE Trans. Syst. Man Cybern. 1983, SMC-13, 834–846. [Google Scholar] [CrossRef]
- Mnih, V.; Kavukcuoglu, K.; Silver, D.; Rusu, A.A.; Veness, J.; Bellemare, M.G.; Graves, A.; Riedmiller, M.; Fidjeland, A.K.; Ostrovski, G.; et al. Human-Level Control Through Deep Reinforcement Learning. Nature 2015, 518, 529–533. [Google Scholar] [CrossRef] [PubMed]
- van Hasselt, H.; Guez, A.; Silver, D. Deep Reinforcement Learning with Double Q-Learning. Proc. AAAI Conf. Artif. Intell. 2016, 30, 2094–2100. [Google Scholar] [CrossRef]
- Schulman, J.; Wolski, F.; Dhariwal, P.; Radford, A.; Klimov, O. Proximal Policy Optimization Algorithms. arXiv 2017, arXiv:1707.06347. [Google Scholar] [CrossRef]
- Schulman, J.; Levine, S.; Moritz, P.; Jordan, M.I.; Abbeel, P. Trust Region Policy Optimization. In Proceedings of the 32nd International Conference on Machine Learning (ICML), Lille, France, 6–11 July 2015; pp. 1889–1897. [Google Scholar]
- Paszke, A.; Gross, S.; Massa, F.; Lerer, A.; Bradbury, J.; Chanan, G.; Killeen, T.; Lin, Z.; Gimelshein, N.; Antiga, L.; et al. PyTorch: An Imperative Style, High-Performance Deep Learning Library. Adv. Neural Inf. Process. Syst. 2019, 32, 8026–8037. [Google Scholar]





| Module | Purpose | Core Formulation (Summary) | Role & Interpretation |
|---|---|---|---|
| (i) Policy Network | Select informative sensor channels dynamically based on input context. | Stochastic Gating: Suppresses irrelevant signals (noise) before temporal modeling. | |
| (ii) Optimization | Train the gate to balance accuracy and sparsity without explicit labels. | Update via REINFORCE | Efficiency: Penalizes redundant sensors; maximizes predictive reward. |
| (iii) Selective SSM | Model temporal dependencies efficiently on the gated sequence. | (Discretized via ZOH) | Linear Complexity: Captures long-term patterns without quadratic cost. |
| (iv) Selective Scan | Adapt time-scale and projections to the current input context. | Input-dependent | Multi-scale Modeling: Large for rapid events; small for trends. |
| Module | Component | Configuration/Parameters | Activation |
|---|---|---|---|
| RL Agent | Input state () | Dimension: (mean statistics) | – |
| Hidden layer 1 | Linear () | ReLU | |
| Hidden layer 2 | Linear () | ReLU | |
| Output layer () | Linear () | Sigmoid | |
| Action sampling | Stochastic | ||
| Mamba Predictor | Input embedding | Linear (), | – |
| SSM Backbone | Stacked layers: | SiLU | |
| State dim (): 16 | |||
| Conv kernel size: 4 | |||
| Pooling | Global average pooling | – | |
| Prediction head | Linear () | Linear | |
| Training | Optimizer | AdamW | – |
| Learning rate | RL: , Mamba: | – |
| Cow ID | PLF-Mamba | Transformer | LSTM | MLP | No-RL |
|---|---|---|---|---|---|
| C01 | 0.682 | 0.559 | 0.638 | 0.386 | 0.271 |
| C02 | 0.717 | 0.761 | 0.795 | 0.500 | −0.042 |
| C03 | 0.647 | 0.891 | 0.740 | 0.659 | 0.335 |
| C04 | 0.650 | 0.709 | 0.558 | 0.602 | −1.254 |
| C05 | 0.599 | 0.336 | 0.445 | 0.449 | 0.037 |
| C06 | 0.645 | 0.642 | 0.503 | 0.346 | −1.097 |
| C07 | 0.659 | 0.511 | 0.684 | 0.732 | −1.164 |
| C08 | 0.867 | 0.879 | 0.831 | 0.610 | −2.862 |
| C09 | 0.490 | 0.502 | 0.576 | 0.680 | −1.708 |
| C10 | 0.609 | 0.608 | 0.556 | 0.515 | −0.106 |
| Average | 0.656 | 0.640 | 0.633 | 0.548 | −0.759 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2026 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license.
Share and Cite
Kim, J.; Sohn, C.-B. PLF-Mamba: Analyzing Individual Milk Yield Dynamics Under Data Scarcity Using Selective State Space Models. Agriculture 2026, 16, 389. https://doi.org/10.3390/agriculture16030389
Kim J, Sohn C-B. PLF-Mamba: Analyzing Individual Milk Yield Dynamics Under Data Scarcity Using Selective State Space Models. Agriculture. 2026; 16(3):389. https://doi.org/10.3390/agriculture16030389
Chicago/Turabian StyleKim, Jonghyun, and Chae-Bong Sohn. 2026. "PLF-Mamba: Analyzing Individual Milk Yield Dynamics Under Data Scarcity Using Selective State Space Models" Agriculture 16, no. 3: 389. https://doi.org/10.3390/agriculture16030389
APA StyleKim, J., & Sohn, C.-B. (2026). PLF-Mamba: Analyzing Individual Milk Yield Dynamics Under Data Scarcity Using Selective State Space Models. Agriculture, 16(3), 389. https://doi.org/10.3390/agriculture16030389

