Algorithm 1 Mocapy++’s Viterbi path approximation algorithm. samples[m, l] corre-
sponds to slice l in sample m. P (samples[m, l]|samples[n, l − 1]) is the likelihood of all
the node values in slice l, where the values for the nodes are taken from position l of
sample m, and the nodes’ parent values in the previous slice are taken from position
l − 1 of sample n. Sequence indices run from 0 to L − 1. If a previous approximation of
the Viterbi path is available, it can be added to the initial list of samples. The procedure
will then come up with an improved variant of it or produce the same path.
S=number of samples
L=sequence length
V =number of scalars in a sequence slice
samples=sequence (S × L × V matrix)
score=matrix(S × L)
path=matrix(S × L)
# Start of dynamic programming
# 1. Initialization
for m = 0 to S − 1:
score[m, 0]=log P(samples[m, 0]])
# 2. Recursion
for l = 0 to L − 1:
for m = 0 to S − 1:
p=matrix(S)
for n = 0 to S − 1:
p[n]=log P(samples[m, l]|samples[n, l − 1])
index=argmax(p)
score[m, l]=score[m, l − 1]+p[index]
path[m, l]=index
# 3. Termination
index=argmax(score[L − 1])
viterbi=matrix(L × V )
viterbi[L − 1]=samples[index, L − 1]
# 4. Backtracking
for l = L − 2 to 0:
index=path[index, l]
viterbi[l]=samples[index, l]
report viterbi
sponds to slice l in sample m. P (samples[m, l]|samples[n, l − 1]) is the likelihood of all
the node values in slice l, where the values for the nodes are taken from position l of
sample m, and the nodes’ parent values in the previous slice are taken from position
l − 1 of sample n. Sequence indices run from 0 to L − 1. If a previous approximation of
the Viterbi path is available, it can be added to the initial list of samples. The procedure
will then come up with an improved variant of it or produce the same path.
S=number of samples
L=sequence length
V =number of scalars in a sequence slice
samples=sequence (S × L × V matrix)
score=matrix(S × L)
path=matrix(S × L)
# Start of dynamic programming
# 1. Initialization
for m = 0 to S − 1:
score[m, 0]=log P(samples[m, 0]])
# 2. Recursion
for l = 0 to L − 1:
for m = 0 to S − 1:
p=matrix(S)
for n = 0 to S − 1:
p[n]=log P(samples[m, l]|samples[n, l − 1])
index=argmax(p)
score[m, l]=score[m, l − 1]+p[index]
path[m, l]=index
# 3. Termination
index=argmax(score[L − 1])
viterbi=matrix(L × V )
viterbi[L − 1]=samples[index, L − 1]
# 4. Backtracking
for l = L − 2 to 0:
index=path[index, l]
viterbi[l]=samples[index, l]
report viterbi