In [9]:
%matplotlib inline
import numpy as np
import pylab
import pytry
import pandas
import seaborn
from nengo_bee import NengoBee
In [10]:
data = pytry.read('gather8-hover')
In [11]:
bee = NengoBee()
all_x = np.vstack([d['x_world'][:-1] for d in data])
all_x_body = bee.bee.world_state_to_body(all_x)
all_u = np.vstack([d['u'][:-1] for d in data])
all_du = np.vstack([np.diff(d['u'], axis=0) for d in data])/0.001
mean_x = np.mean(all_x, axis=0)
mean_x_body = np.mean(all_x_body, axis=0)
mean_u = np.mean(all_u, axis=0)
mean_du = np.mean(all_du, axis=0)
std_x = np.std(all_x, axis=0)
std_x_body = np.std(all_x_body, axis=0)
std_u = np.std(all_u, axis=0)
std_du = np.std(all_du, axis=0)
In [4]:
x_names = [
'$\phi_r$',
'$\psi_r$',
'$\dot{\phi}_r$',
'$\dot{\psi}_r$',
'$\phi_l$',
'$\psi_l$',
'$\dot{\phi}_l$',
'$\dot{\psi}_l$',
'$\phi$',
'$\\theta$',
'$\psi$',
'$x$',
'$y$',
'$z$',
'$\dot{\phi}$',
'$\dot{\\theta}$',
'$\dot{\psi}$',
'$\dot{x}$',
'$\dot{y}$',
'$\dot{z}$',
]
u_names = [
'stroke ampl.', 'pitch torque', 'yaw torque', 'roll'
]
In [6]:
for i in range(20):
pylab.figure()
seaborn.distplot(all_x[:,i])
pylab.title('x[%d] %s ($\mu$=%1.4f, $\sigma$=%1.4f)' % (i, x_names[i], mean_x[i], std_x[i]))
for i in range(4):
pylab.figure()
if std_u[i] > 0:
seaborn.distplot(all_u[:,i])
pylab.title('u[%d] %s ($\mu$=%1.4f, $\sigma$=%1.4f)' % (i, u_names[i], mean_u[i], std_u[i]))
for i in range(4):
pylab.figure()
if std_u[i] > 0:
seaborn.distplot(all_du[:,i])
pylab.title('$\dot{u}$[%d] %s rate ($\mu$=%1.4f, $\sigma$=%1.4f)' % (i, u_names[i], mean_du[i], std_du[i]))
In [12]:
norm_x = (all_x - mean_x) / std_x
norm_x_body = (all_x_body - mean_x_body) / std_x_body
norm_u = (all_u - mean_u) / std_u
norm_du = (all_du - mean_du) / std_du
In [13]:
keep_x = [15,16,19]
keep_u = []#0,1,3]
x_vals = norm_x[:,keep_x]
u_vals = norm_u[:,keep_u]
du_vals = norm_du[:,[0,1,3]]
pts = np.hstack([x_vals, u_vals])
In [29]:
import nengo
model = nengo.Network()
with model:
D = pts.shape[1]
ens = nengo.Ensemble(n_neurons=500, dimensions=D, neuron_type=nengo.LIFRate(), radius=np.sqrt(D))
du = nengo.Node(None, size_in=3)
c = nengo.Connection(ens, du, eval_points=pts, scale_eval_points=False, function=du_vals)
In [30]:
sim = nengo.Simulator(model)
In [31]:
sim.data[c].solver_info
Out[31]:
In [132]:
pylab.plot(fn)
Out[132]:
In [14]:
np.savez('gather8-hover',
mean_x=mean_x,
mean_x_body=mean_x_body,
mean_u=mean_u,
std_x=std_x,
std_x_body=std_x_body,
std_u=std_u,
mean_du=mean_du,
std_du=std_du,
all_du=all_du,
all_u=all_u,
all_x=all_x,
all_x_body=all_x_body,
norm_x=norm_x,
norm_x_body=norm_x_body,
norm_u=norm_u,
norm_du=norm_du)
In [ ]: