In [1]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [2]:
fulltraj = load('enlair.npy')

fulltraj = fulltraj[:, [1, 2, 4, 5]]
traj = fulltraj[415:442]

plot(traj)


Out[2]:
[<matplotlib.lines.Line2D at 0x105b3eb10>,
 <matplotlib.lines.Line2D at 0x105b3ed90>,
 <matplotlib.lines.Line2D at 0x105b3efd0>,
 <matplotlib.lines.Line2D at 0x105b4b1d0>]

In [3]:
plot(concatenate((traj, traj, traj)))


Out[3]:
[<matplotlib.lines.Line2D at 0x105c9c190>,
 <matplotlib.lines.Line2D at 0x105c9c410>,
 <matplotlib.lines.Line2D at 0x105c9c650>,
 <matplotlib.lines.Line2D at 0x105c9c810>]

In [4]:
from pydmps.dmp_rhythmic import DMPs_rhythmic

In [5]:
BFS = 10

In [6]:
dmp = DMPs_rhythmic(dmps=traj.shape[1], bfs=BFS)

In [7]:
reconstructed = dmp.imitate_path(traj.T).T

In [8]:
plot(linspace(0, len(traj), len(reconstructed)), reconstructed)
plot(traj)


Out[8]:
[<matplotlib.lines.Line2D at 0x106c60e90>,
 <matplotlib.lines.Line2D at 0x106bc5250>,
 <matplotlib.lines.Line2D at 0x106bc5410>,
 <matplotlib.lines.Line2D at 0x106bff350>]

In [9]:
dmp = DMPs_rhythmic(dmps=traj.shape[1], bfs=BFS)
reconstructed = dmp.imitate_path(traj.T).T

dmp.timesteps *= 2
y, _, _ = dmp.rollout()

i = 1

plot(linspace(0, 2, 2*len(traj)), concatenate((traj[:, i], traj[:, i])))
plot(linspace(0, 2, len(y)), y[:, i])

legend(('fit', 'rollout'))


Out[9]:
<matplotlib.legend.Legend at 0x106da8450>

In [10]:
from __init__ import save

with open('base_dmp.json', 'w') as f:
    save(dmp, f)

In [ ]: