-
Notifications
You must be signed in to change notification settings - Fork 4
/
util.py
31 lines (24 loc) · 820 Bytes
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
import autograd.numpy as np
import matplotlib.pyplot as plt
def run_dynamics(u_old, system, dt, x_init, x_old=None, u_deltas=None):
x_new = [x_init]
u_new = []
x = x_init
for t in range(len(u_old)):
u = u_old[t]
if u_deltas is not None and x_old is not None:
x_delta = system.x_delta(x, x_old[t])
x_delta = np.concatenate([[1], x_delta])
u = u + u_deltas[t] @ x_delta
x = system.step(x, u, dt)
u_new.append(u)
x_new.append(x)
return np.array(x_new), np.array(u_new)
def plot_costs(costs, filename='costs', path='vis/costs', file_ext='png'):
plt.figure()
plt.plot(costs)
plt.ylabel('Cost')
plt.xlabel('Iteration')
plt.savefig(os.path.join(path, filename + '.' + file_ext))
plt.show()