Algorithmadvanced
Verbs and adverbs motion interpolation
Also called verbs and adverbs.
Interpolate a set of example motions over a space of control parameters with radial basis functions plus a linear term.
- Time
- O(n (a + q)) evaluateO(n^3 + n^2 (a + q)) fit
- Space
- O(n (n + q)) model
- Where
- a = the number of adverbs; n = the number of examples; q = the number of values per example
- Model
- Real RAM
- Properties
- deterministicexactofflineiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Charles Rose, Michael F. Cohen, Bobby Bodenheimer, 1998
Verbs and adverbs makes a new motion for any point in a space of control parameters from a small set of example motions. A verb is an action, such as walk or reach. Its adverbs are the numbers that describe how it is done, such as the speed and the turn of a walk, or the target of a reach. Each of the examples has an adverb point and the values of its time aligned joint curves. The interpolant is
a linear part fitted by least squares, plus radial basis functions that pass exactly through the examples. The linear part gives a sensible trend between and beyond the examples; the radial part adds the detail that the linear part misses, and it is zero far from all examples. Rose, Cohen and Bodenheimer (1998) presented the method with a verb graph that joins verbs by transitions.
In plain words
You have captured a few walks: slow, fast, turning left, turning right, and some in between. Each walk has a label with its speed and its turn. Now you want a walk with a speed and turn that you did not capture. The method first finds the straight line trend: how the joint curves change, on average, as the speed or the turn goes up. That trend alone does not go through each captured walk exactly. So the method adds small bumps, one at each captured walk, that fix the difference there and fade away with distance. The new walk is the trend plus the bumps.
The problem
The input is example motions of one verb, all time aligned to a common structure of keytimes (for a walk: heel strike, toe off, the next heel strike), so that frame of the normalized time means the same moment of the step in every example. Each example has an adverb vector and a value vector : for example the control points of the B-spline curves of all joints, and the keytimes. The task is a function that reproduces every example, , is smooth, and stays close to a linear trend away from the examples.
The output for a query is a value vector; rebuilding the joint curves from it and playing them over the interpolated keytimes gives the motion. The interpolation acts on each value separately: all values use the same radial functions, and each value has its own coefficients.
The algorithm
FIT-VERB(P, Y) ▷ adverb points pᵢ, value vectors yᵢ- 1
X ← the rows (1, pᵢ) ▷ an n × (a + 1) matrix - 2
[c₀; C] ← (XᵀX)⁻¹ XᵀY ▷ the least squares linear part - 3
eᵢ ← yᵢ - (c₀ + C pᵢ) for every example ▷ the residuals - 4
αᵢ ← 2 · min over k ≠ i of |pᵢ - pₖ| ▷ the support of Rᵢ, a choice of the code - 5
K[r][i] ← Rᵢ(pᵣ) = B(2 |pᵣ - pᵢ| / αᵢ) ▷ B is the cubic B-spline, zero beyond 2 - 6
W ← K⁻¹ E ▷ the radial weights, one row per example EVALUATE(p)- 7
return c₀ + C p + Σᵢ wᵢ Rᵢ(p)
The radial function is the uniform cubic B-spline for , for , and beyond. So is at and zero at the distance and beyond. The paper uses radial cubic B-splines with a width that depends on the spacing of the examples; the rule of line L4, twice the distance to the nearest other example, is the choice of the code. Because the differ, is not symmetric, and the code solves it by Gaussian elimination with partial pivoting.
The interpolant is linear in the example values, so it can also be written as with weights that depend only on the adverb points: a weighted blend of the examples. This form is how the method drives a blend of motions directly.
Example
By hand. One adverb, three examples with the scalar values . Line L2: the mean of is 1 and the mean of is , and , so the slope is 0 and the linear part is the constant . Line L3: the residuals are , , . Line L4: every example has its nearest neighbor at distance 1, so every and . Line L5: , and , so
By symmetry and , with and , so and . At : for the first two examples and for the third, and
At the value is 1, the example. At only the third radial function reaches, , and . At no radial function reaches, and , the linear part.
A measured case. The test uses two adverbs, a speed in and a turn in , and 8 values per example from a smooth nonlinear function. With 25 random examples (seed 5) and 200 random test points, the squared error, summed over the 8 values and averaged over the test points, is 0.0026 for the full interpolant and 0.0171 for the linear part alone. This is a measurement on one function, not a bound.
Correctness
The proof file works under two hypotheses: (H1) the adverb points do not all lie on one hyperplane, so is nonsingular; (H2) the matrix is nonsingular. H2 is not proved for these radial functions; the code raises an error if is singular. Under them it shows:
- Lines L1 to L3 give the least squares linear part, and the residuals are orthogonal to the constant and to every adverb.
- The interpolant reproduces every example exactly (Theorem 1).
- If the examples come from a linear function, the radial weights are zero and the interpolant is that linear function everywhere (Theorem 2).
- Beyond the distance from every example, only the linear part is left.
How well the interpolant matches motion that was not captured is only measured. The choice of adverbs, the time alignment, and the radial widths are tuning, and that an interpolated walk looks natural is a visual heuristic.
Proof: The verb interpolant reproduces its examples, is exact on linear data, and is linear far from the examplesfull
We use the notation of the page. The arithmetic is exact. There are examples with adverb points and value vectors , and the are distinct. is the by matrix with rows . The radial function of example is , where is the cubic B-spline of the page and is twice the distance from to the nearest other example. is the by matrix .
Two hypotheses are needed, and the code raises an error when either fails:
- (H1) is nonsingular, that is, the points do not all lie on one hyperplane of (so );
- (H2) is nonsingular.
H2 is not proved for this choice of radial functions. The differ, so is not symmetric, and the theory of positive definite radial kernels does not apply.
The linear part
Lemma 1. Lines L1 to L3 give the least squares fit: the coefficient matrix minimizes , and the residuals satisfy and for every adverb .
Proof. The objective is a convex quadratic in , and its gradient is . It is zero exactly at the solution of the normal equations , which is unique under H1. The two families of equations in the claim are the rows of : the row of ones and the row of adverb .
The radial part
Lemma 2. , and when .
Proof. is on , on , and 0 for , and exactly when .
is : at both pieces have the value , the slope and the second derivative , and at the second piece has value, slope and second derivative 0.
Theorem 1. Under H1 and H2, the interpolant of line L7 satisfies for every example .
Proof. Line L6 solves , where row of is the residual . So , and .
Theorem 2. Under H1 and H2, if the examples are linear, , then and for every .
Proof. The true coefficients give zero residuals, so they minimize the least squares objective, and by uniqueness (H1) the fit returns them. Then , and gives under H2.
Theorem 3. If for every , then .
Proof. Lemma 2 makes every radial term zero.
So, far from all examples, the interpolant falls back to the least squares hyperplane, and it does not oscillate there.
What is not proved
The interpolation error at a new adverb point is not bounded on this page. The test measures it on one smooth synthetic verb: the radial part lowers the mean squared error at 200 random points compared with the linear part alone. That is a measurement of one case, not a property of the method.
Complexity
The linear part needs and in and a solve in . The matrix costs , and its solve costs . With , fitting costs time. Evaluation costs for the linear part and for the radial part. The model stores during the fit and the weights, space. The paper uses tens of examples per verb, so the cost is small; the values (control points of all joints) dominate.
Properties
- Exact at the examples. Under H1 and H2, every example is reproduced.
- Linear far away. Outside the supports of all radial functions, the result is the linear trend, which keeps extrapolation sane for a small distance.
- Linear in the values. The result is a weighted sum of the example values, with weights that depend only on the adverb points.
- Not convex. Weights can be negative, so the result is not always between the examples; the hand example has a negative radial weight.
Variants and improvements
- Pseudo examples. Later work by Rose, Sloan and Cohen adds examples made from the interpolant itself to make the weights better behaved over the space.
- Weights per example. Precompute the cardinal weights on a grid of adverbs and blend the examples with them, as in a blend tree.
- Other kernels. Gaussian, thin plate or polyharmonic radial functions with a polynomial part; a Gaussian process gives the same form with a statistical reading.
- Pose space deformation. Pose space deformation uses the same radial interpolation for corrective shapes of a mesh over joint angles instead of motions over adverbs.
- Automatic alignment. Registration curves replace the hand set keytimes by an automatic timewarp.
When to use it
Use verbs and adverbs when a few captured or hand made examples must cover a continuous range of a parameter, such as walk speed or reach target, and when exact reproduction of the examples matters. It needs good time alignment of the examples, and a sensible choice of adverbs. For a large database with no parameterization, motion matching searches the data instead.
Pitfalls
- Bad time alignment. If the keytimes do not match, the interpolant blends different phases, and the feet slide.
- Points on a line. If all examples vary only in speed, there is no information about the turn; the fit is singular in that direction (H1 fails).
- Close examples. Two examples very close in adverb space but with different values make ill conditioned and the weights large.
- Extrapolation. Far outside the examples, only the linear trend is left; a walk at three times the fastest example speed is a linear guess.
- The name. "Motion interpolation" is also an alias of motion blending, which mixes clips with weights given by the user.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/verbs-and-adverbs/. The authors are listed in prov/G3VDNR.jsonl.
"""Verbs and adverbs interpolation (Rose, Cohen and Bodenheimer 1998).
A verb has n time aligned example motions. Example i has an adverb vector
p_i (a numbers, for example speed and turn) and a value vector y_i (q
numbers, for example the control points of every joint curve after time
alignment to a common key time structure). The interpolant is
y(p) = c_0 + C p + sum_i w_i R_i(|p - p_i|),
computed in two steps:
1. the linear part (c_0, C) by least squares over the examples;
2. the radial part: the residuals of step 1 are interpolated exactly by
the radial functions R_i(d) = B(2 d / alpha_i), where B is the cubic
B-spline with support [0, 2] and alpha_i is twice the distance from p_i
to the nearest other example. So R_i is zero beyond alpha_i.
The matrix K[k][i] = R_i(|p_k - p_i|) of step 2 is not symmetric, because
the alpha_i differ, and its invertibility is not proved; solve() raises an
error if it is singular.
"""
import math
def bspline(s):
"""The uniform cubic B-spline B(s), s >= 0, with B(0) = 2/3, zero for s >= 2."""
s = abs(s)
if s >= 2.0:
return 0.0
if s >= 1.0:
return (2.0 - s) ** 3 / 6.0
return 2.0 / 3.0 - s * s + 0.5 * s ** 3
def solve(A, b, eps=1e-14):
"""Gaussian elimination with partial pivoting. b has one row per row of
A, and each row of b holds one value per right hand side."""
n = len(A)
A = [row[:] for row in A]
B = [list(r) for r in b]
for c in range(n):
p = max(range(c, n), key=lambda r: abs(A[r][c]))
if abs(A[p][c]) < eps:
raise ValueError("singular matrix")
A[c], A[p] = A[p], A[c]
B[c], B[p] = B[p], B[c]
for r in range(c + 1, n):
f = A[r][c] / A[c][c]
if f:
for k in range(c, n):
A[r][k] -= f * A[c][k]
for k in range(len(B[r])):
B[r][k] -= f * B[c][k]
X = [[0.0] * len(B[0]) for _ in range(n)]
for r in range(n - 1, -1, -1):
for k in range(len(B[0])):
s = B[r][k] - sum(A[r][t] * X[t][k] for t in range(r + 1, n))
X[r][k] = s / A[r][r]
return X
def dist(a, b):
return math.sqrt(sum((x - y) ** 2 for x, y in zip(a, b)))
class Verb:
def __init__(self, adverbs, values):
self.P = [list(p) for p in adverbs]
self.Y = [list(y) for y in values]
n, a = len(self.P), len(self.P[0])
self.n, self.a, self.q = n, a, len(self.Y[0])
# step 1: least squares for the linear part, by the normal equations
X = [[1.0] + p for p in self.P] # @line L1
XtX = [[sum(X[r][i] * X[r][j] for r in range(n)) for j in range(a + 1)] for i in range(a + 1)]
XtY = [[sum(X[r][i] * self.Y[r][k] for r in range(n)) for k in range(self.q)] for i in range(a + 1)]
self.lin = solve(XtX, XtY) # @line L2
resid = [[self.Y[r][k] - self.linear(self.P[r])[k] for k in range(self.q)] for r in range(n)] # @line L3
# step 2: radial functions through the residuals
self.alpha = []
for i in range(n):
near = min(dist(self.P[i], self.P[k]) for k in range(n) if k != i) if n > 1 else 1.0
self.alpha.append(2.0 * near) # @line L4
K = [[self.radial(i, self.P[r]) for i in range(n)] for r in range(n)] # @line L5
self.w = solve(K, resid) # @line L6
self.resid = resid
def linear(self, p):
return [self.lin[0][k] + sum(self.lin[1 + l][k] * p[l] for l in range(self.a))
for k in range(self.q)]
def radial(self, i, p):
return bspline(2.0 * dist(p, self.P[i]) / self.alpha[i])
def __call__(self, p):
y = self.linear(p)
for i in range(self.n):
r = self.radial(i, p)
if r:
for k in range(self.q):
y[k] += self.w[i][k] * r
return y # @line L7
test_verbs_and_adverbs.py 89 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/verbs-and-adverbs/. The authors are listed in prov/G3VDNR.jsonl.
"""Tests of verbs and adverbs interpolation.
The interpolant reproduces every example, reproduces linear data exactly
everywhere with zero radial weights, has a least squares linear part (the
residuals are orthogonal to the columns), and is only linear far from the
examples. On a smooth nonlinear verb, the error at new adverbs is measured
against the linear part alone. Examples are made in code with a fixed seed.
"""
import math
import random
import verbs_and_adverbs as va
def curve(p, samples=8):
"""Control values of a joint curve for adverbs p = (speed, turn)."""
speed, turn = p
return [0.4 * speed * math.sin(2 * math.pi * k / samples) + 0.3 * turn * math.cos(speed + k)
+ 0.1 * speed * turn for k in range(samples)]
def examples(rng, n):
P = [(rng.uniform(0.5, 2.5), rng.uniform(-1.0, 1.0)) for _ in range(n)]
return P, [curve(p) for p in P]
def test_bspline_values():
assert va.bspline(0.0) == 2.0 / 3.0
assert abs(va.bspline(1.0) - 1.0 / 6.0) < 1e-15
assert va.bspline(2.0) == 0.0 and va.bspline(3.0) == 0.0
h = 1e-5
for s in (1.0,):
d1 = (va.bspline(s + h) - va.bspline(s - h)) / (2 * h)
assert abs(d1 + 0.5) < 1e-6
def test_examples_are_reproduced():
rng = random.Random(1)
P, Y = examples(rng, 12)
v = va.Verb(P, Y)
for p, y in zip(P, Y):
assert max(abs(a - b) for a, b in zip(v(p), y)) < 1e-9
def test_linear_data_is_exact():
rng = random.Random(2)
P = [(rng.uniform(0, 1), rng.uniform(0, 1), rng.uniform(0, 1)) for _ in range(10)]
f = lambda p: [1.0 + 2.0 * p[0] - p[1] + 0.5 * p[2], -3.0 + p[2]]
v = va.Verb(P, [f(p) for p in P])
assert max(abs(x) for row in v.w for x in row) < 1e-9
for _ in range(50):
p = (rng.uniform(-1, 2), rng.uniform(-1, 2), rng.uniform(-1, 2))
assert max(abs(a - b) for a, b in zip(v(p), f(p))) < 1e-9
def test_linear_part_is_least_squares():
rng = random.Random(3)
P, Y = examples(rng, 15)
v = va.Verb(P, Y)
for k in range(v.q):
r = [v.resid[i][k] for i in range(v.n)]
assert abs(sum(r)) < 1e-9
for l in range(v.a):
assert abs(sum(ri * p[l] for ri, p in zip(r, P))) < 1e-9
def test_far_from_examples_only_linear():
rng = random.Random(4)
P, Y = examples(rng, 10)
v = va.Verb(P, Y)
far = (20.0, 20.0)
assert v(far) == v.linear(far)
def test_measured_error_against_linear_only():
rng = random.Random(5)
P, Y = examples(rng, 25)
v = va.Verb(P, Y)
err_full = err_lin = 0.0
for _ in range(200):
p = (rng.uniform(0.7, 2.3), rng.uniform(-0.8, 0.8))
y = curve(p)
err_full += sum((a - b) ** 2 for a, b in zip(v(p), y))
err_lin += sum((a - b) ** 2 for a, b in zip(v.linear(p), y))
# measured on this seed: the radial part lowers the squared error
assert err_full < err_lin
History
Charles Rose, Michael F. Cohen and Bobby Bodenheimer described verbs and adverbs in 1998, with the keytime alignment, the radial interpolation with a linear part, and a verb graph whose edges are transitions between verbs. Peter-Pike Sloan, Charles Rose and Michael Cohen later used the same interpolation for shapes, and Rose, Sloan and Cohen applied it to inverse kinematics from examples. Radial basis function interpolation itself is older and comes from the interpolation of scattered data.
References
- Charles Rose, Michael F. Cohen and Bobby Bodenheimer, Verbs and adverbs, multidimensional motion interpolation, IEEE Computer Graphics and Applications 18(5), 1998, 32 to 40, the verbs and adverbs, the time alignment by keytimes, the interpolation by a linear part plus radial basis functions, and the verb graph
- Lucas Kovar and Michael Gleicher, Flexible automatic motion blending with registration curves, ACM SIGGRAPH/Eurographics Symposium on Computer Animation, 2003, 214 to 224, the automatic time alignment of example motions for a weighted blend
- Rick Parent, Computer Animation, Algorithms and Techniques, 3rd edition, Morgan Kaufmann, 2012, the material on motion capture data and its processing
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag G3VDNR Edit this page History Report an error Markdown