def run_cubic_decomp(): for n in [5, 6, 11, 35, 1021, 11111]: print(n) with ContextTimer(): print(cubic_decomp(n)[0]) with ContextTimer(): print(cubic_decomp_dp(n)) print()
def perf_ngsim_env_step(): basedir = os.path.expanduser('~/.julia/packages/NGSIM/9OYUa/data') filename = 'trajdata_i101_trajectories-0750am-0805am.txt' filepaths = [os.path.join(basedir, filename)] env = JuliaEnv(env_id='NGSIMEnv', env_params=dict(trajectory_filepaths=filepaths, ), using='AutoEnvs') n_steps = 10000 action = np.array([1., 0.]) env.reset() with ContextTimer(): for _ in range(n_steps): _, _, terminal, _ = env.step(action) if terminal: env.reset()
def step(self, action): self.steps_since_restart += 1 self.total_steps_ever += 1 # Send a state and get a response with ContextTimer(post_print=False) as timer: self.server.send_state(action) is_over, image, new_score = self._get_state() # # Print FPS? # if self.total_steps_ever % 1000 == 0: # print("FPS", 1 / (timer.elapsed + .00001)) # Update the score and log info reward = new_score - self.latest_total_score self.latest_total_score = new_score return image, reward, is_over, None
def perf_vectorized_ngsim_env_step(): basedir = os.path.expanduser('~/.julia/packages/NGSIM/9OYUa/data') filename = 'trajdata_i101_trajectories-0750am-0805am.txt' filepaths = [os.path.join(basedir, filename)] n_envs = 100 env = JuliaEnv(env_id='VectorizedNGSIMEnv', env_params=dict( n_envs=n_envs, trajectory_filepaths=filepaths, ), using='AutoEnvs') n_steps = 10000 action = np.zeros((n_envs, 2)) action[:, 0] = 1. env.reset() with ContextTimer(): for _ in range(0, n_steps, n_envs): _, _, terminal, _ = env.step(action) env.reset(terminal)
def collect(egoids, starts, args, exp_dir, use_hgail, params_filename, n_proc, max_steps=200, collect_fn=parallel_collect_trajectories): ''' Description: - prepare for running collection in parallel - multiagent note: egoids and starts are not currently used when running this with args.env_multiagent == True ''' # load information relevant to the experiment params_filepath = os.path.join(exp_dir, 'imitate/log/{}'.format(params_filename)) params = hgail.misc.utils.load_params(params_filepath) # validation setup validation_dir = os.path.join(exp_dir, 'imitate', 'validation') utils.maybe_mkdir(validation_dir) output_filepath = os.path.join( validation_dir, '{}_trajectories.npz'.format(args.ngsim_filename.split('.')[0])) with ContextTimer(): trajs = collect_fn(args, params, egoids, starts, n_proc, max_steps=max_steps, use_hgail=use_hgail) utils.write_trajectories(output_filepath, trajs)
for j in range(m): for k in range(m): if a[j, k] > a[j, i] + a[i, k]: a[j, k] = a[j, i] + a[i, k] return a if __name__ == '__main__': side = 200 random_adj_mat = np.random.rand(side * side) * side mask = np.random.rand(side**2) < .8 random_adj_mat[mask] = np.inf random_adj_mat = (random_adj_mat).reshape(side, side) inputs = [[[0, np.inf, 1], [1, 0, np.inf], [np.inf, 1, 0]], [[0, 5, np.inf, 10], [np.inf, 0, 3, np.inf], [np.inf, np.inf, 0, 1], [np.inf, np.inf, np.inf, 0]], random_adj_mat] inputs = [np.array(a) for a in inputs] expect = [[[0, 2, 1], [1, 0, 2], [2, 1, 0]], [[0, 5, 8, 9], [np.inf, 0, 3, 4], [np.inf, np.inf, 0, 1], [np.inf, np.inf, np.inf, 0]], 'no idea'] expect = [np.array(a) for a in expect] for (i, e) in zip(inputs, expect): print(e) with ContextTimer(): print(floyd_warshall(i.copy())) with ContextTimer(): print(floyd_warshall_fast(i.copy()))