def line_search(self, model, rollout, original_policy_loss, original_policy_params, original_parameter_vec,<EOL>full_step, expected_improvement_full):
current_parameter_vec = original_parameter_vec.clone()<EOL>for idx in range(self.line_search_iters):<EOL><INDENT>stepsize = <NUM_LIT:0.5> ** idx<EOL>new_parameter_vec = current_parameter_vec + stepsize * full_step<EOL>v2p(new_parameter_vec, model.policy_parameters())<EOL>with torch.no_grad():<EOL><INDENT>policy_params = model.policy(rollout.batch_tensor('<STR_LIT>'))<EOL>policy_entropy = torch.mean(model.entropy(policy_params))<EOL>kl_divergence = torch.mean(model.kl_divergence(original_policy_params, policy_params))<EOL>new_loss = self.calc_policy_loss(model, policy_params, policy_entropy, rollout)<EOL>actual_improvement = original_policy_loss - new_loss<EOL>expected_improvement = expected_improvement_full * stepsize<EOL>ratio = actual_improvement / expected_improvement<EOL><DEDENT>if kl_divergence.item() > self.mak_kl * <NUM_LIT>:<EOL><INDENT>continue<EOL><DEDENT>elif ratio < expected_improvement:<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>return True, ratio, actual_improvement, new_loss, kl_divergence<EOL><DEDENT><DEDENT>v2p(original_parameter_vec, model.policy_parameters())<EOL>return False, torch.tensor(<NUM_LIT:0.0>), torch.tensor(<NUM_LIT:0.0>), torch.tensor(<NUM_LIT:0.0>), torch.tensor(<NUM_LIT:0.0>)<EOL>
Find the right stepsize to make sure policy improves