51975a8639d0b83544ec2f932567656b25bfc965,slm_lab/agent/algorithm/math_util.py,,calc_nstep_returns,#Any#Any#Any#Any#,47

Before Change


    // to add back the subtracted with v_pred at n
    gammas = calc_gammas(batch, gamma)
    final_terms = gammas * v_preds
    final_terms = torch.cat([final_terms[n:], torch.zeros((n,))])[:rets_len]

    nstep_rets = rets - tail_rets + final_terms
    assert not np.isnan(nstep_rets).any(), f"N-step returns has nan: {nstep_rets}"
    return nstep_rets

After Change


        then add v_pred for n as final term
    """
    rets = copy.deepcopy(batch["rewards"])
    nstep_rets = np.zeros_like(rets) + rets
    cur_gamma = gamma
    for i in range(1, n):
        // Shift returns by one and pad with zeros
        rets[:-1] = rets[1:]
        rets[-1] = 0
        nstep_rets += cur_gamma * rets
        // Update current gamma
        cur_gamma *= cur_gamma
    // Add final terms. Note no next state if epi is done
    final_terms = cur_gamma * next_v_preds * (1 - batch["dones"])
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 5

Instances


Project Name: kengz/SLM-Lab
Commit Name: 51975a8639d0b83544ec2f932567656b25bfc965
Time: 2018-09-02
Author: lgraesser@users.noreply.github.com
File Name: slm_lab/agent/algorithm/math_util.py
Class Name:
Method Name: calc_nstep_returns


Project Name: arraiy/torchgeometry
Commit Name: bdd3f2f8f306000f9b0c34e0ec2a86a75cee885b
Time: 2020-04-29
Author: ducha.aiki@gmail.com
File Name: kornia/feature/laf.py
Class Name:
Method Name: ellipse_to_laf


Project Name: kymatio/kymatio
Commit Name: 6d781d6720bcaeb5aa75874180e5d636e9f4248f
Time: 2018-11-21
Author: janden@flatironinstitute.org
File Name: scattering/scattering1d/backend/backend_torch.py
Class Name:
Method Name: modulus_complex