U[:, t] = du
# U[:,T/2:] = -2 * U[:,T/2:]
# U = np.mat(np.random.random_sample((arm.NU, T-1))/5)
# U[:,10:] = -2 * U[:,10:]

for t in xrange(1, T):
    X[:, t] = arm.dynamics(X[:, t - 1], U[:, t - 1])
    mus[:, t], Sigmas[:, :, t] = ekf_update(
        arm.dynamics, lambda x: arm.observe(s, x=x), Q, R, mus[:, t - 1], Sigmas[:, :, t - 1], U[:, t - 1], None
    )  # NOTE No obs

arm.draw_trajectory(X, mus, Sigmas)

Bel_bar = np.mat(np.zeros((arm.NB, T)))
for t in xrange(T):
    Bel_bar[:, t] = np.vstack((X[:, t], cov2vec(Sigmas[:, :, t])))

rho_bel = 0.2
rho_u = 0.3
N_iter = 1
goal_bel = np.copy(Bel_bar[:, -1])
goal_bel[arm.NX :] = 0

opt_bels, opt_ctrls, opt_vals = scp_solver_beliefs(
    s, Bel_bar.copy(), U, Q, R, rho_bel, rho_u, goal_bel, N_iter, arm.NX, method="shooting"
)


opt_mus = np.mat(np.zeros((arm.NX, T)))
opt_mus[:, 0] = X[:, 0]
opt_X = opt_mus.copy()
#U = np.mat(np.random.random_sample((arm.NU, T-1))/5)
#U[:,10:] = -2 * U[:,10:]

for t in xrange(1, T):
    X[:, t] = localizer.dynamics(X[:, t - 1], U[:, t - 1])
    mus[:, t], Sigmas[:, :,
                      t] = ekf_update(localizer.dynamics,
                                      lambda x: localizer.observe(s, x=x), Q,
                                      R, mus[:, t - 1], Sigmas[:, :, t - 1],
                                      U[:, t - 1], None)  #NOTE No obs

localizer.draw_trajectory(X, mus, Sigmas)

Bel_bar = np.mat(np.zeros((localizer.NB, T)))
for t in xrange(T):
    Bel_bar[:, t] = np.vstack((X[:, t], cov2vec(Sigmas[:, :, t])))

rho_bel = 0.1
rho_u = 0.1
N_iter = 5
goal_bel = np.copy(Bel_bar[:, -1])
goal_bel[localizer.NX:] = 0

opt_bels, opt_ctrls, opt_vals = scp_solver_beliefs(s, Bel_bar.copy(), U,\
               Q, R, rho_bel, rho_u, goal_bel, N_iter, localizer.NX, method='shooting')

opt_mus = np.mat(np.zeros((localizer.NX, T)))
opt_mus[:, 0] = X[:, 0]
opt_X = opt_mus.copy()
opt_Sigmas = np.zeros((Q.shape[0], Q.shape[1], T))
opt_Sigmas[:, :, 0] = Sigmas[:, :, 0]