- The paper presents tensorized algorithms that enable efficient forward filtering and Viterbi decoding for both HMMs and factorial HMMs.
- It leverages mode-wise tensor contractions to reduce computational complexity from exponential to nearly linear scaling in state-space size.
- Benchmark experiments show speedups over 4500x and demonstrate numerical equivalence with standard vectorized methods.
Tensorized Algorithms and Scalable Filtering for HMM and fHMM
Introduction
Hidden Markov models (HMMs) serve as foundational tools for probabilistic modeling of time-series data with latent state dynamics. However, many systems—such as those in speech, genomics, or biophysics—are influenced by multiple independent latent factors, motivating the use of factorial hidden Markov models (fHMMs), which feature several parallel Markov chains. The principal computational barrier for fHMMs is state-space explosion: naively, exact inference involves a cost exponential in the number of chains, limiting their practical applicability. This paper introduces tensorized algorithms for fHMM inference, exploiting the multilinear algebraic structure to achieve substantial computational and memory efficiency, and provides thorough benchmarking against the standard vectorized approaches (2607.07008).
The formalism is centered around the realization that the combinatorial state-space for K parallel Markov chains is the Cartesian product of subsystem state-spaces. For K subsystems with state sizes Mk, the joint state-space has cardinality M=∏k=1KMk. In standard implementations, forward filtering and Viterbi decoding involve matrix-vector operations over this exponential space.
This work systematically develops a tensor calculus for state and parameter representations. The forward algorithm is generalized to operate with tensors whose axes represent the factors (chains), allowing recursive filtering and decoding to be performed with mode-wise contractions and tensor products, rather than with Kronecker-flattened vectors and matrices. The authors employ vectorization and folding/unfolding mappings, mode-k products, tensor contractions, and Kronecker product identities to formalize the recursions.
Tensorized Forward Filtering: Algorithmic Advances
For fHMMs, the standard approach—recasting as a single joint HMM—leads to computational cost per iteration scaling as O(NM2), i.e., O(N∏k=1K(Mk)2), due to dense matrix-vector multiplications. By exploiting tensor contractions that mirror the independence structure, the tensorized algorithm achieves a per-step complexity of O(NM∑kMk) and memory requirements are dramatically reduced, since Kronecker-expanded objects are never instantiated.
In the tensorized algorithm, the recursive filtering step updates a K-mode tensor An (of shape K0):
- The initial step involves Hadamard products and mode-wise stretches of the emission tensor and initial state distributions.
- Each subsequent step contracts along each mode with the corresponding subsystem transition matrix and takes a Hadamard product with the new emission tensor slice.
This yields a speedup scaling as K1 for K2 subsystems of size K3, relative to naive vectorization—transformative for practical settings with K4.
To validate both correctness and efficiency, the authors conduct extensive benchmark experiments using synthetic fHMMs of varying dimension and number of chains. Numerical accuracy is verified: over K5 random trials, maximum discrepancies between tensorized and vectorized outputs are at the scale of machine epsilon, demonstrating that reformulating the recursions in tensor algebra introduces no detectable numerical artifacts.
For performance, runtime scaling is assessed for different system sizes:
The memory efficiency is an equally significant achievement; in practical implementations, the tensorized method enables analyses of models previously excluded from consideration.
Additional arrangement experiments show that the order of tensor modes (i.e., placement of large state spaces in the contraction sequence) may yield minor performance benefits, with the fastest execution when larger subsystems are placed on the early tensor modes. This insight can inform practical implementation choices for further efficiency.

Figure 2: Assessment of the runtime performance with all subsystem sizes equal (Mk4). Tensorized approaches scale quartically; vectorized methods scale sextically.
Decoding Algorithms and Exactness Guarantees
The tensorized formalism is extended to the Viterbi decoding problem, with mode-wise maximizations replacing vectorized argmax operations. The resulting algorithm provably yields identical sequences to the vectorized approach, as confirmed by zero Hamming distances across Mk5 synthetic benchmarks.
Practical and Theoretical Implications
This work demonstrates that tensor algebra can be used to rigorously and efficiently realize exact inference for factorial Markovian models, bypassing both prohibitive runtime and memory constraints of conventional approaches. Importantly, the algorithms maintain strict numerical equivalence to the standard vector operations, with no loss of stability or precision.
The tensorized schemes align naturally with modern scientific computing tools that support multidimensional arrays and optimized tensor contractions (e.g., NumPy, MATLAB), facilitating their adoption in large-scale data pipelines and nonparametric Bayesian inference workflows.
Beyond the immediate task of forward filtering and decoding, this approach lays groundwork for several advances:
- Scaling Bayesian inference methods (e.g., generic Metropolis–Hastings MCMC) for sequential models with non-conjugate likelihoods, rare transitions, or highly structured latent spaces.
- Enabling principled model selection/comparison where repeated likelihood evaluations are required, e.g., for evidence-based dynamical system identification or hidden process partitioning.
- Extending the approach to nonlinear or non-Gaussian state-space models that also exhibit factorial structure.
Conclusion
The proposed tensorized filtering and decoding algorithms for fHMMs offer a scalable, memory-efficient, and numerically robust alternative to standard vectorized implementations. By leveraging the multi-way structure inherent in factorial models, the algorithms enable principled time-series inference for dimensionalities previously considered intractable, with broad applicability in domains such as genomics, signal processing, and biophysics. The availability of fast, exact algorithms for these models is likely to catalyze further developments in scalable Bayesian inference, sequential data modeling, and resource-constrained applications requiring interpretable latent variable modeling.