Exact Regular-Constrained Sampling for Variable-Order Markov Generation
Abstract
We study how to sample a sequence of a fixed length from a variable-order Markov model while satisfying regular constraints, such as ending with a specified symbol, placing given symbols at selected positions, or avoiding copied fragments. The model predicts each next symbol from a context of preceding symbols and backs off to a shorter context when needed. Existing belief-propagation methods solve this problem for first-order Markov chains, which use only the last symbol as context. Our contribution is an exact extension to variable-order models. We build a graph of the contexts observed in the training data and combine it with a finite automaton that checks the constraints. This retains the context needed by the predictor and yields samples from a fixed finite-memory source conditioned on the constraints. The backward pass takes time proportional to the requested sequence length times the number of reachable transitions in this combined graph. The method also supports data augmentation through reversible transformations without storing the transformed training sequences, while preserving the probabilities obtained by learning from all the copies. Exhaustive enumeration verifies the constrained probabilities, and Bach Prelude experiments demonstrate practical generation with combined musical constraints