Markov Constraints

Exact controlled generation for variable-order Markov models. Train a model, define a regular language, and sample from the conditioned distribution—or find its most probable sequence.

Source & installation · 0.4.0-rc.1 prerelease · npm package: npm install markov-constraints@next

Explore the Guillaume de Machaut melody laboratory →

Context graph × constraint DFA → reachable product → backward DP → generation

Model & constraints

Reduced memory recomputes backward blocks and disables the sampling cache. Use it when memory is more important than repeated-generation speed. Use a lower source order or enable a backoff mixture to allow novelty. Blank fields disable optional constraints. Melody uses comma-separated pitches; journeys use comma-separated tokens. Computation runs in a Web Worker.

Generate

Ready.

Your sequence will appear here.

Training preview


        

Position marginals


        

Inference diagnostics

Exact with respect to the supplied model, subject to floating-point arithmetic. Ordinary mass can underflow; log mass remains available. Optimization may repeat patterns.

Greedy is not optimization

If P(a)=0.60 and P(b)=0.40, greedy chooses a. But a splits equally into ax and ay, each with probability 0.30. If b always continues to x, bx is the most probable complete sequence at 0.40. Exact sampling explores all three with their conditional probabilities.