(
pre, post, rewards, nu, dt, tc_plus, tc_minus, tc_e, a_plus=1.0, a_minus=-1.0
)
| 66 | |
| 67 | |
| 68 | def _florian_mstdpet( |
| 69 | pre, post, rewards, nu, dt, tc_plus, tc_minus, tc_e, a_plus=1.0, a_minus=-1.0 |
| 70 | ): |
| 71 | T, npre, npost = pre.shape[0], pre.shape[1], post.shape[1] |
| 72 | p_plus = torch.zeros(npre) |
| 73 | p_minus = torch.zeros(npost) |
| 74 | elig = torch.zeros(npre, npost) |
| 75 | etrace = torch.zeros(npre, npost) |
| 76 | w = torch.zeros(npre, npost) |
| 77 | w_hist = [] |
| 78 | for t in range(T): |
| 79 | etrace = etrace * torch.exp(torch.tensor(-dt / tc_e)) + elig / tc_e |
| 80 | w = w + nu * dt * rewards[t] * etrace |
| 81 | p_plus = p_plus * torch.exp(torch.tensor(-dt / tc_plus)) + a_plus * pre[t] |
| 82 | p_minus = p_minus * torch.exp(torch.tensor(-dt / tc_minus)) + a_minus * post[t] |
| 83 | elig = torch.outer(p_plus, post[t]) + torch.outer(pre[t], p_minus) |
| 84 | w_hist.append(w.clone()) |
| 85 | return torch.stack(w_hist) |
| 86 | |
| 87 | |
| 88 | # --------------------------------------------------------------------------- # |
no test coverage detected