예제 #1
0
def test_F3_oh_value():

    for i in range(3):
        ll_runs = 1
        steps = 10000
        ep_s = ExponentialDecay(steps / 16, 0.5, 0.05, steps)
        lr_s = ConstantSched(0.05)
        device = 'cuda'
        actions = 3
        obs_shape = (1, )
        batch_size = 32

        env = gym.make('F3-v0')
        #env = RewardPerStep(env, reward_per_step=-0.01)
        env = TimeLimit(env, max_episode_steps=20)
        env = NormalizeFunctional(env,
                                  obs_f=normalize_obs,
                                  reward_f=normalize_reward)
        env = LookAhead(env)
        env = Reset(env)
        #env = Monitor(env)
        env = BatchTensor(env, device='cuda')

        #critic = FixupV(obs_shape, 4).to(device)
        critic = OneHotV(obs_shape, 12).to(device)
        policy = VPolicy(critic,
                         actions,
                         EpsilonGreedyProperDiscreteDist,
                         epsilon=1.0).to(device)

        exp_buffer = ExpBuffer(max_timesteps=steps // 10,
                               ll_runs=ll_runs,
                               batch_size=batch_size,
                               observation_shape=obs_shape)

        stepper = td_value.Stepper(env, OneObsToState(), exp_buffer)

        run_on(stepper=stepper,
               learner=td_value.train_one_value,
               env=env,
               critic=critic,
               policy=policy,
               ll_runs=ll_runs,
               eps_sched=ep_s,
               actions=actions,
               exp_buffer=exp_buffer,
               batch_size=batch_size,
               discount=0.8,
               lr_sched=lr_s,
               rendermode='episodic',
               steps=steps,
               logging_freq=1,
               run_id=f'f5_value_{i}',
               warmup_steps=0)
예제 #2
0
 def __init__(self,
              env,
              critic,
              behaviour_policy,
              greedy_policy,
              exp_buffer,
              join=OneObsToState(),
              device='cuda',
              viewer=None,
              plot=None):
     self.env = env
     self.state = self.env.reset()
     self.join = join
     self.exp_buffer = exp_buffer
     self.v = viewer
     self.tb = None
     self.critic = critic
     self.behaviour_policy = behaviour_policy
     self.greedy_policy = greedy_policy
     self.device = device
     self.plotter = plot