# The minimum jerk hypothesis¶

Marcos Duarte

Hogan and Flash (1984, 1985), based on observations of voluntary movements in primates, suggested that movements are performed (organized) with the smoothest trajectory possible. In this organizing principle, the endpoint trajectory is such that the mean squared-jerk across time of this movement is minimum.

Jerk is the derivative of acceleration and the observation of the minimum-jerk trajectory is for the endpoint in the extracorporal coordinates (not for joint angles) and according to Flash and Hogan (1985), the minimum-jerk trajectory of a planar movement is such that minimizes the following objective function:

$$C=\frac{1}{2} \int\limits_{t_{i}}^{t_{f}}\;\left[\left(\frac{d^{3}x}{dt^{3}}\right)^2+\left(\frac{d^{3}y}{dt^{3}}\right)^2\right]\:\mathrm{d}t$$

Hogan (1984) found that the solution for this objective function is a fifth-order polynomial trajectory (see Shadmehr and Wise (2004) for a simpler proof):

$$\begin{array}{l l} x(t) = a_0+a_1t+a_2t^2+a_3t^3+a_4t^4+a_5t^5 \\ y(t) = b_0+b_1t+b_2t^2+b_3t^3+b_4t^4+b_5t^5 \end{array}$$

With the following boundary conditions for $x(t)$ and $y(t)$: initial and final positions are $(x_i,y_i)$ and $(x_f,y_f)$ and initial and final velocities and accelerations are zero.

Let's employ Sympy to find the solution for the minimum jerk trajectory using symbolic algebra.

In [1]:
# import the necessary libraries
from __future__ import division, print_function
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
#sns.set()
sns.set_context("notebook", font_scale=1.2, rc={"lines.linewidth": 2, "lines.markersize": 10})
from IPython.display import display, Math, Latex
from sympy import symbols, Matrix, latex, Eq, collect, solve, diff, simplify
from sympy.utilities.lambdify import lambdify


Using Sympy, the equation for minimum jerk trajectory for x is:

In [2]:
# declare the symbolic variables
x, xi, xf, y, yi, yf, d, t = symbols('x, x_i, x_f, y, y_i, y_f, d, t')
a0, a1, a2, a3, a4, a5 = symbols('a_0:6')
x = a0 + a1*t + a2*t**2 + a3*t**3 + a4*t**4 + a5*t**5
display(Math(latex('x(t)=') + latex(x)))

$$x(t)=a_{0} + a_{1} t + a_{2} t^{2} + a_{3} t^{3} + a_{4} t^{4} + a_{5} t^{5}$$

Without loss of generality, consider $t_i=0$ and let's use $d$ for movement duration ($d=t_f$). The system of equations with the boundary conditions for $x$ is:

In [3]:
# define the system of equations
s = Matrix([Eq(x.subs(t,0)          , xi),
Eq(diff(x,t,1).subs(t,0),  0),
Eq(diff(x,t,2).subs(t,0),  0),
Eq(x.subs(t,d)          , xf),
Eq(diff(x,t,1).subs(t,d),  0),
Eq(diff(x,t,2).subs(t,d),  0)])
display(Math(latex(s, mat_str='matrix', mat_delim='[')))

$$\left[\begin{matrix}a_{0} = x_{i}\\a_{1} = 0\\2 a_{2} = 0\\a_{0} + a_{1} d + a_{2} d^{2} + a_{3} d^{3} + a_{4} d^{4} + a_{5} d^{5} = x_{f}\\a_{1} + 2 a_{2} d + 3 a_{3} d^{2} + 4 a_{4} d^{3} + 5 a_{5} d^{4} = 0\\2 a_{2} + 6 a_{3} d + 12 a_{4} d^{2} + 20 a_{5} d^{3} = 0\end{matrix}\right]$$

Which gives the following solution:

In [4]:
# algebraically solve the system of equations
sol = solve(s, [a0, a1, a2, a3, a4, a5])
display(Math(latex(sol)))

$$\left \{ a_{0} : x_{i}, \quad a_{1} : 0, \quad a_{2} : 0, \quad a_{3} : \frac{1}{d^{3}} \left(10 x_{f} - 10 x_{i}\right), \quad a_{4} : \frac{1}{d^{4}} \left(- 15 x_{f} + 15 x_{i}\right), \quad a_{5} : \frac{1}{d^{5}} \left(6 x_{f} - 6 x_{i}\right)\right \}$$

Substituting this solution in the fifth order polynomial trajectory equation, we have the actual displacement trajectories:

In [5]:
# substitute the equation parameters by the solution
x2 = x.subs(sol)
x2 = collect(simplify(x2, ratio=1), xf-xi)
display(Math(latex('x(t)=') + latex(x2)))
y2 = x2.subs([(xi, yi), (xf, yf)])
display(Math(latex('y(t)=') + latex(y2)))

$$x(t)=x_{i} + \left(x_{f} - x_{i}\right) \left(\frac{10 t^{3}}{d^{3}} - \frac{15 t^{4}}{d^{4}} + \frac{6 t^{5}}{d^{5}}\right)$$
$$y(t)=y_{i} + \left(y_{f} - y_{i}\right) \left(\frac{10 t^{3}}{d^{3}} - \frac{15 t^{4}}{d^{4}} + \frac{6 t^{5}}{d^{5}}\right)$$

And for the velocity, acceleration, and jerk trajectories in x:

In [6]:
# symbolic differentiation
vx = x2.diff(t, 1)
display(Math(latex('v_x(t)=') + latex(vx)))
ax = x2.diff(t, 2)
display(Math(latex('a_x(t)=') + latex(ax)))
jx = x2.diff(t, 3)
display(Math(latex('j_x(t)=') + latex(jx)))

$$v_x(t)=\left(x_{f} - x_{i}\right) \left(\frac{30 t^{2}}{d^{3}} - \frac{60 t^{3}}{d^{4}} + \frac{30 t^{4}}{d^{5}}\right)$$
$$a_x(t)=\frac{60 t}{d^{3}} \left(x_{f} - x_{i}\right) \left(1 - \frac{3 t}{d} + \frac{2 t^{2}}{d^{2}}\right)$$
$$j_x(t)=\frac{60}{d^{3}} \left(x_{f} - x_{i}\right) \left(1 - \frac{6 t}{d} + \frac{6 t^{2}}{d^{2}}\right)$$

Let's plot the minimum jerk trajectory for x and its velocity, acceleration, and jerk considering $x_i=0,x_f=1,d=1$:

In [7]:
# substitute by the numerical values
x2  = x2.subs([(xi, 0), (xf, 1), (d, 1)])
#create functions for calculation of numerical values
xfu = lambdify(t, diff(x2, t, 0), 'numpy')
vfu = lambdify(t, diff(x2, t, 1), 'numpy')
afu = lambdify(t, diff(x2, t, 2), 'numpy')
jfu = lambdify(t, diff(x2, t, 3), 'numpy')
#plots using matplotlib
ts = np.arange(0, 1.01, .01)
font = {'weight':'normal', 'size':12}
plt.matplotlib.rc('font', **font)
fig, axs = plt.subplots(1, 4, figsize=(10, 4), sharex=True, squeeze=True)
axs[0].plot(ts, xfu(ts), linewidth=3)
axs[0].set_title('Displacement [$\mathrm{m}$]')
axs[1].plot(ts, vfu(ts), linewidth=3)
axs[1].set_title('Velocity [$\mathrm{m/s}$]')
axs[2].plot(ts, afu(ts), linewidth=3)
axs[2].set_title('Acceleration [$\mathrm{m/s^2}$]')
axs[3].plot(ts, jfu(ts), linewidth=3)
axs[3].set_title('Jerk [$\mathrm{m/s^3}$]')

for axi in axs:
axi.set_xlabel('Time [s]', fontsize=14)
axi.grid(True)

fig.suptitle('Minimum jerk trajectory kinematics', fontsize=20, y=1.03)
fig.tight_layout()
plt.show()


At the minimum jerk trajectory, initial and final values of both velocity and acceleration are zero, but not for the jerk.

Read more about the minimum jerk trajectory hypothesis in the Shadmehr and Wise's book companion site and in Paul Gribble's website.

## Problems¶

1. Calculate and plot the position, velocity, acceleration, and jerk trajectories for different movement speeds (for example, consider always a displacement of 1 m and movement durations of 0.5, 1, and 2 s).
2. For the data in the previous item, calculate the ratio peak speed to average speed. Shadmehr and Wise (2004) argue that psychophysical experiments show that reaching movements with the hand have this ratio equals to 1.75. Compare with the calculted values.