Statistics & probability

Hidden semi Markov sequence calculator with explicit duration distributions

Evaluate explicit state-duration sequences with log likelihood, segment Viterbi paths and posterior state occupancy.

Your numbers

Valid JSON. Duration row index0 means duration1; no self transitions; observation ends on a completed segment.
Valid JSON; preserve the shown array or object structure.
Valid JSON; preserve the shown array or object structure.
Valid JSON; preserve the shown array or object structure.
Valid JSON; preserve the shown array or object structure.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

A hidden semi-Markov model describes both transitions between latent states and the time spent in each state. An explicit duration distribution can represent short or concentrated runs that a geometric hidden-Markov duration cannot.

THE FORMULAGiven initialstateprob pi, no-self transition A, stateemissionprob B, durations d_j(l), finiteobservedsequenceoflengthT, use completed-segmentforward α_t(j)=Σ_l d_j(l)*Π_{r=t-l+1}^t B_j(o_r)*[1_{t=l}pi_j+Σ_{i!=j}α_{t-l}(i)A_ij]. Logsumexpandprefixlogemissions. FirstversionrequiressegmentendingexactlyatT;likelihoodΣ_jα_Tj. BackwardsmoothingandsegmentViterbi use sameterminal convention. Right-censoredterminaldurationuses survivalmass Σ_{l≥remaining}d_j(l) andmustbeseparatemode. No parameterlearningunlessimplemented.

A worked example

With the prefilled inputs, logLikelihood = 0. Duration row index0 means duration1; no self transitions; observation ends on a completed segment.

Good to know

Observed window begins and ends at segment boundaries; duration PMFs count complete segments. No right-censored final duration or learned parameters.

Make state duration explicit

A hidden semi-Markov model describes both transitions between latent states and the time spent in each state. An explicit duration distribution can represent short or concentrated runs that a geometric hidden-Markov duration cannot.

The observations remain probabilistic emissions from the current state. A run of similar symbols does not uniquely determine the hidden state, because several segmentations can explain the same observed sequence.

Deterministic semi-Markov segmentAn explicit duration makes the segment boundary mattert = 1state 0: At = 2state 0: Aone complete segment; duration = 2P(duration 2)=1 and P(A|state 0)=1Exact-ending likelihood for A,A is 1.
Scroll across to see the full diagram.
A deterministic state that emits A and lasts exactly two observations gives likelihood1 for the complete segment A,A. This single-state analytic illustration must be adapted to a supported public multi-state example.

Compare with the Hidden Markov model forward backward and Viterbi calculator. Infer latent segments with externally specified dwell-time distributions; an ordinary HMM imposes geometric durations.

Enter a complete probability model

Duration row index0 means duration1; no self transitions; observation ends on a completed segment.Supply initial state probabilities, transitions between different states, an emission distribution for each state and a probability distribution over positive integer durations. Keep all symbol and state orders consistent across those arrays.

Self transitions are excluded in this segment convention. Otherwise adjacent segments with the same state can be merged in several ways, obscuring what the entered duration distribution means. There are two to four latent states. Initial-state, transition, emission and duration rows must each be valid probability vectors. The transition diagonal must be zero, because an immediate transition back into the same state would blur the distinction between one long segment and two adjacent segments of identical state. Emission columns correspond to zero-based observed symbol labels. Duration position zero means one observation, not duration zero. The input sequence starts at a new segment and must end when a segment finishes; it is not treated as a censored fragment of an ongoing final state.

Choose the terminal convention

This version conditions the calculation on a segment ending exactly at the final observation. It adds probabilities only for segmentations whose final duration fits that endpoint.

A sequence that stops while a segment is still in progress requires a right-censored terminal contribution based on duration survival probabilities. The two likelihoods are different and must not be presented under the same unlabeled mode.

Sum over segmentations

The forward recurrence combines a completed previous segment, a transition, the next segment duration and that segment's emission likelihood. It sums over all allowed lengths and prior states.

Computing in logarithms prevents long products of small probabilities from disappearing numerically. The total likelihood is a sum over complete paths, whereas a Viterbi path selects only the single highest-probability segmentation.

A deterministic two-observation check

Use one state that emits A with probability one and has duration two with probability one. For observations A,A and the exact-ending convention, the unique allowed segmentation has likelihood one.

A one-observation sequence has no complete segment under that same convention and therefore likelihood zero. It would have a different result under a terminal-censoring interpretation, illustrating why the endpoint rule matters.

Understand state and segment summaries

A state path labels each observation, while a segment summary also records boundaries and durations. Two different segmentations can sometimes produce the same sequence of state labels when alternative conventions allow repeated states.

Posterior state probabilities average across compatible segmentations. A single Viterbi path should not be interpreted as certainty, especially when several duration patterns have similar likelihoods.

Keep inference separate from training

Evaluating a supplied model is not the same task as estimating its transition, duration and emission parameters. A calculator that scores one sequence should not claim to have learned a model from that sequence.

Assess model fit with independent sequences and domain-relevant duration checks. An impossible observation pattern may reveal a deliberate structural zero or an unsuitable probability model rather than a software failure. The forward recursion sums every admissible segmentation that ends at each time and state. A separate maximizing recursion records one highest-probability segment path, while backward messages recover posterior occupancy at each observation. A state can have high occupancy at a time without belonging to the single Viterbi path, because occupancy sums many alternative paths. Returned occupancy rows should sum to one and are checked numerically. The model parameters are entered, not fitted from the sequence. Longer duration support increases both runtime and the number of possible explanations; reaching the stated work or probability limits does not justify substituting a first-order hidden Markov approximation. Observed window begins and ends at segment boundaries; duration PMFs count complete segments. No right-censored final duration or learned parameters.

A few questions, answered

Is this just a hidden Markov model with another name?

No. State durations are supplied explicitly instead of being implied solely by repeated self transitions.

Why are self transitions excluded?

They make adjacent same-state segments ambiguous under the explicit-duration convention used here.

What does zero sequence likelihood mean?

No allowed segmentation and emission combination can produce the sequence under the supplied model and endpoint rule.

Does the best path probability equal the sequence likelihood?

Generally no. Sequence likelihood sums all compatible paths; the best path uses only the largest term.

Find your calculator

Start typing to explore the library.