In [1]:
import sys
sys.path.append('..')
import deep_control as dc

import numpy as np

In [2]:
import matplotlib.pylab as plt
import seaborn as sns
%matplotlib inline

In [4]:
import pickle

In [5]:
[x_train, y_train, x_test, y_test, idx_train] = pickle.load(open('../traj/quadrotor_power.pic', 'rb'))

In [120]:
import time
    
def timeNN(networks, x_train):
    iters = 100000
    t0 = time.time()
    m1,n1 = networks[0]
    m2,n2 = networks[1]
    
    for i in range(iters):
        

        x = x_train[i]
        x = dc.nn.preprocess(m1, x)
        u1 = n1['pred'](x.reshape(1,-1))[0,0]     
        u2 = n2['pred'](x.reshape(1,-1))[0,0]
        y = dc.nn.postprocess(m1, np.asarray([u1,u2]).reshape(1,-1)) 

    tf = time.time()
    print((tf-t0)/iters*1000, 'ms')

In [122]:
model_th = dc.nn.load_model('../nets/mass_clean/0/ReLu_outputLog_1_1104.model')
network_th = dc.nn.load_network(model_th, base_dir='../')

model_dth = dc.nn.load_model('../nets/mass_clean/1/ReLu_outputLog_1_1104.model')
network_dth = dc.nn.load_network(model_dth, base_dir='../')

networks = [(model_th,network_th),(model_dth,network_dth)]

print(model_th['nlayers'], ',', model_th['units'])
timeNN(networks, x_train)


1 , 1104
0.09851061582565307 ms

In [124]:
model_th = dc.nn.load_model('../nets/mass_clean/0/ReLu_outputLog_4_64.model')
network_th = dc.nn.load_network(model_th, base_dir='../')

model_dth = dc.nn.load_model('../nets/mass_clean/1/ReLu_outputLog_4_64.model')
network_dth = dc.nn.load_network(model_dth, base_dir='../')

networks = [(model_th,network_th),(model_dth,network_dth)]

print(model_th['nlayers'], ',', model_th['units'])
timeNN(networks, x_train)


4 , 64
0.10701493740081787 ms

In [125]:
model_th = dc.nn.load_model('../nets/mass_clean/1/ReLu_outputLog_4_128.model')
network_th = dc.nn.load_network(model_th, base_dir='../')

model_dth = dc.nn.load_model('../nets/mass_clean/1/ReLu_outputLog_4_128.model')
network_dth = dc.nn.load_network(model_dth, base_dir='../')

networks = [(model_th,network_th),(model_dth,network_dth)]

print(model_th['nlayers'], ',', model_th['units'])
timeNN(networks, x_train)


4 , 128
0.13597254037857054 ms

In [126]:
model_th = dc.nn.load_model('../nets/mass_clean/1/ReLu_outputLog_4_256.model')
network_th = dc.nn.load_network(model_th, base_dir='../')

model_dth = dc.nn.load_model('../nets/mass_clean/1/ReLu_outputLog_4_256.model')
network_dth = dc.nn.load_network(model_dth, base_dir='../')

networks = [(model_th,network_th),(model_dth,network_dth)]

print(model_th['nlayers'], ',', model_th['units'])
timeNN(networks, x_train)


4 , 256
0.22221683979034423 ms

In [10]:
import time
    
def timeAMPL(model, x_train, nodes):
    iters = 100
    t0 = time.time()
    for i in range(iters):
        x = x_train[i]
        conditions = {'n':nodes,
              'vx': x[1],
              'z': x[2],
              'vz': x[3],
              'theta': x[4],
              'm': x[0]}        
        traj = dc.data.get_trajectory(model, conditions)
        
    tf = time.time()
    print((tf-t0)/iters*1000, 'ms')

In [ ]:
model = 'main_rw_mass'

In [6]:
[x_train, y_train, x_test, y_test, idx_train] = pickle.load(open('../traj/quadrotor_power.pic', 'rb'))

In [21]:
model = 'main_quadrotor_power'

In [22]:
nodes = 5
print(nodes)
timeAMPL('../SpaceAMPL/lander/hs/' + model + '.mod', x_train, nodes)


5
38.86234521865845 ms

In [23]:
nodes = 20
print(nodes)
timeAMPL('../SpaceAMPL/lander/hs/' + model + '.mod', x_train, nodes)


20
168.71016263961792 ms

In [24]:
nodes = 50
print(nodes)
timeAMPL('../SpaceAMPL/lander/hs/' + model + '.mod', x_train, nodes)


50
594.8709654808044 ms

In [25]:
[x_train, y_train, x_test, y_test, idx_train] = pickle.load(open('../traj/quadrotor_time.pic', 'rb'))
model = 'main_quadrotor_time'

In [26]:
nodes = 5
print(nodes)
timeAMPL('../SpaceAMPL/lander/hs/' + model + '.mod', x_train, nodes)


5
32.66479015350342 ms

In [27]:
nodes = 20
print(nodes)
timeAMPL('../SpaceAMPL/lander/hs/' + model + '.mod', x_train, nodes)


20
257.9648518562317 ms

In [28]:
nodes = 50
print(nodes)
timeAMPL('../SpaceAMPL/lander/hs/' + model + '.mod', x_train, nodes)


50
1245.9835362434387 ms

In [30]:
[x_train, y_train, x_test, y_test, idx_train] = pickle.load(open('../traj/mass_thrusters.pic', 'rb'))

In [33]:
model = 'main_thrusters'

In [34]:
nodes = 5
print(nodes)
timeAMPL('../SpaceAMPL/lander/hs/' + model + '.mod', x_train, nodes)

nodes = 20
print(nodes)
timeAMPL('../SpaceAMPL/lander/hs/' + model + '.mod', x_train, nodes)


nodes = 50
print(nodes)
timeAMPL('../SpaceAMPL/lander/hs/' + model + '.mod', x_train, nodes)


5
72.94856786727905 ms
20
386.44155263900757 ms
50
3488.824133872986 ms

In [36]:
[x_train, y_train, x_test, y_test, idx_train] = pickle.load(open('../traj/mass_clean.pic', 'rb'))

In [37]:
model = 'main_rw_mass'
nodes = 5
print(nodes)
timeAMPL('../SpaceAMPL/lander/hs/' + model + '.mod', x_train, nodes)

nodes = 20
print(nodes)
timeAMPL('../SpaceAMPL/lander/hs/' + model + '.mod', x_train, nodes)


nodes = 50
print(nodes)
timeAMPL('../SpaceAMPL/lander/hs/' + model + '.mod', x_train, nodes)


5
82.81638860702515 ms
20
280.70225715637207 ms
50
1736.792504787445 ms

In [ ]: