def retrace(self, rewards, dones, q_values, state_values, rho, final_values):
rho_bar = torch.min(torch.ones_like(rho) * self.retrace_rho_cap, rho)<EOL>q_retraced_buffer = torch.zeros_like(rewards)<EOL>next_value = final_values<EOL>for i in reversed(range(rewards.size(<NUM_LIT:0>))):<EOL><INDENT>q_retraced = rewards[i] + self.discount_factor * next_value * (<NUM_LIT:1.0> - dones[i])<EOL>next_value = rho_bar[i] * (q_retraced - q_values[i]) + state_values[i]<EOL>q_retraced_buffer[i] = q_retraced<EOL><DEDENT>return q_retraced_buffer<EOL>
Calculate Q retraced targets