(
pre, post, rewards, nu, dt, tc_plus, tc_minus, a_plus=1.0, a_minus=-1.0, lag=True
)
| 44 | # From-scratch Florian (2007) reference implementations. # |
| 45 | # --------------------------------------------------------------------------- # |
| 46 | def _florian_mstdp( |
| 47 | pre, post, rewards, nu, dt, tc_plus, tc_minus, a_plus=1.0, a_minus=-1.0, lag=True |
| 48 | ): |
| 49 | T, npre, npost = pre.shape[0], pre.shape[1], post.shape[1] |
| 50 | p_plus = torch.zeros(npre) |
| 51 | p_minus = torch.zeros(npost) |
| 52 | elig = torch.zeros(npre, npost) |
| 53 | w = torch.zeros(npre, npost) |
| 54 | w_hist, pplus_hist = [], [] |
| 55 | for t in range(T): |
| 56 | if lag: |
| 57 | w = w + nu * rewards[t] * elig |
| 58 | p_plus = p_plus * torch.exp(torch.tensor(-dt / tc_plus)) + a_plus * pre[t] |
| 59 | p_minus = p_minus * torch.exp(torch.tensor(-dt / tc_minus)) + a_minus * post[t] |
| 60 | elig = torch.outer(p_plus, post[t]) + torch.outer(pre[t], p_minus) |
| 61 | if not lag: |
| 62 | w = w + nu * rewards[t] * elig |
| 63 | w_hist.append(w.clone()) |
| 64 | pplus_hist.append(p_plus.clone()) |
| 65 | return torch.stack(w_hist), torch.stack(pplus_hist) |
| 66 | |
| 67 | |
| 68 | def _florian_mstdpet( |
no test coverage detected