Exemplo n.º 1
0
    # evaluate
    # load the weights from file
    #agent.load_state_dict(torch.load('./cem_cartpole.pth'))
    #agent.load_state_dict(torch.load('./cem_cartpole_5.pth')) # Path to load model from
    #agent.load_state_dict(torch.load('./mimic_cav_90_.pth'))
    num_episodes = num_eps
    rewards = []

    for i in range(num_episodes):
        #
        data_t = []
        data_d = []
        start_disp = None
        #

        state = env.reset()
        # For Graph
        #env.verbose = True
        start_disp = env.center_state(env.current_states[0])
        #

        reward = None
        t = 0
        while True:
            with torch.no_grad():
                #env.render()
                window.appendleft(torch.Tensor(state))
                action_probs = agent(deque2state(env)).detach().numpy()
                action = np.argmax(action_probs)
                a = (env.a_max - env.a_min) * (
                    (action) / (agent.action_size - 1)) + env.a_min

# CAV Simulator (Generates Fake Data now)
env = Simulator(num_leading_vehicle, num_following_vehicle)
env.normalize = False
#env.verbose = True
num_episodes = num_eps
rewards = []

for i in range(num_episodes):
    #
    data_t = []
    data_d = []
    start_disp = None
    #
    s = env.reset()
    #
    env.normalize = True
    start_disp = env.center_state(env.current_states[0])
    env.normalize = False
    #

    done = 0
    i = 0
    reward = None
    while not done:
        #print(env.t)
        #env.render()
        # For graph
        add2loc_map(env)
        #print(s)
    plt.xlabel("Time")
    plt.show()

env = Simulator(num_leading_vehicle,num_following_vehicle)
env.normalize = False
#env.verbose = True
num_episodes = num_eps
results = []

for i in range(num_episodes):
    #
    data_t = []
    data_d = []
    start_disp = None
    #
    s = env.reset()
    #
    env.normalize = True
    start_disp = env.center_state(env.current_states[0])
    env.normalize = False
    #

    done = 0
    i = 0
    reward = None
    while not done:
        #print(env.t)
        #env.render()
        # For graph
        add2loc_map(env)
        #print(s)