def recurrent_generator(self, advantages, num_mini_batch):
num_processes = self.rewards.size(1)
num_envs_per_batch = num_processes // num_mini_batch
perm = torch.randperm(num_processes)
for start_ind in range(0, num_processes, num_envs_per_batch):
observations_batch = []
states_batch = []
actions_batch = []
return_batch = []
masks_batch = []
old_action_log_probs_batch = []
adv_targ = []
for offset in range(num_envs_per_batch):
ind = perm[start_ind + offset]
observations_batch.append(self.observations[:-1, ind])
states_batch.append(self.states[0:1, ind])
actions_batch.append(self.actions[:, ind])
return_batch.append(self.returns[:-1, ind])
masks_batch.append(self.masks[:-1, ind])
old_action_log_probs_batch.append(self.action_log_probs[:, ind])
adv_targ.append(advantages[:, ind])
observations_batch = torch.cat(observations_batch, 0)
states_batch = torch.cat(states_batch, 0)
actions_batch = torch.cat(actions_batch, 0)
return_batch = torch.cat(return_batch, 0)
masks_batch = torch.cat(masks_batch, 0)
old_action_log_probs_batch = torch.cat(old_action_log_probs_batch, 0)
adv_targ = torch.cat(adv_targ, 0)
yield observations_batch, states_batch, actions_batch, \
return_batch, masks_batch, old_action_log_probs_batch, adv_targ
评论列表
文章目录