def calculate_gradient(self, batch_info, device, model, rollout):
evaluator = model.evaluate(rollout)<EOL>advantages = evaluator.get('<STR_LIT>')<EOL>returns = evaluator.get('<STR_LIT>')<EOL>rollout_values = evaluator.get('<STR_LIT>')<EOL>logprobs = evaluator.get('<STR_LIT>')<EOL>values = evaluator.get('<STR_LIT>')<EOL>entropy = evaluator.get('<STR_LIT>')<EOL>policy_loss = -torch.mean(advantages * logprobs)<EOL>value_loss = <NUM_LIT:0.5> * F.mse_loss(values, returns)<EOL>policy_entropy = torch.mean(entropy)<EOL>loss_value = (<EOL>policy_loss - self.entropy_coefficient * policy_entropy + self.value_coefficient * value_loss<EOL>)<EOL>loss_value.backward()<EOL>return {<EOL>'<STR_LIT>': policy_loss.item(),<EOL>'<STR_LIT>': value_loss.item(),<EOL>'<STR_LIT>': policy_entropy.item(),<EOL>'<STR_LIT>': torch.norm(advantages).item(),<EOL>'<STR_LIT>': explained_variance(returns, rollout_values)<EOL>}<EOL>
Calculate loss of the supplied rollout