--- tags: - myenv-v1 - ppo - deep-reinforcement-learning - reinforcement-learning - custom-implementation - deep-rl-course model-index: - name: PPO results: - task: type: reinforcement-learning name: reinforcement-learning dataset: name: myenv-v1 type: myenv-v1 metrics: - type: mean_reward value: -1.10 +/- 0.00 name: mean_reward verified: false --- # PPO Agent Playing myenv-v1 This is a trained model of a PPO agent playing callosp. # Gameplay # Hyperparameters ```python {'exp_name': 'ppo_no_pbt' 'seed': 1 'torch_deterministic': True 'cuda': True 'track': False 'wandb_project_name': 'cleanRL' 'wandb_entity': None 'capture_video': False 'env_id': 'myenv-v1' 'total_timesteps': 10000 'learning_rate': 0.00025 'num_envs': 1 'num_steps': 2048 'anneal_lr': True 'anneal_ent_coef': False 'anneal_clip_coef': False 'gae': True 'gamma': 0.99 'gae_lambda': 0.95 'num_minibatches': 64 'update_epochs': 3 'norm_adv': True 'clip_coef': 0.2 'clip_vloss': True 'ent_coef': 0.03 'vf_coef': 0.5 'max_grad_norm': 0.5 'target_kl': None 'repo_id': 'MRNH/ppo-callofsp' 'save_path': 'agent.pt' 'save_every': 10 'batch_size': 2048 'minibatch_size': 32} ``` Structure Actor-critic: ``` def layer_init(layer, std=np.sqrt(2), bias_const=0.0): torch.nn.init.orthogonal_(layer.weight, std) torch.nn.init.constant_(layer.bias, bias_const) return layer class Agent(nn.Module): def __init__(self, envs): super().__init__() obs_dim = int(np.array(envs.single_observation_space.shape).prod()) n_actions = envs.single_action_space.n self.critic = nn.Sequential( layer_init(nn.Linear(obs_dim, 64)), nn.Tanh(), layer_init(nn.Linear(64, 64)), nn.Tanh(), layer_init(nn.Linear(64, 1), std=1.0), ) self.actor = nn.Sequential( layer_init(nn.Linear(obs_dim, 64)), nn.Tanh(), layer_init(nn.Linear(64, 64)), nn.Tanh(), layer_init(nn.Linear(64, n_actions), std=0.01), ) def get_value(self, x): return self.critic(x) def get_action_and_value(self, x, action=None): logits = self.actor(x) probs = Categorical(logits=logits) if action is None: action = probs.sample() return action, probs.log_prob(action), probs.entropy(), self.critic(x) ```