| 51 | |
| 52 | |
| 53 | class LIFSpike(nn.Module): |
| 54 | def __init__(self, thresh=0.5, tau=0.25, gamma=1.0): |
| 55 | super(LIFSpike, self).__init__() |
| 56 | self.thresh = thresh |
| 57 | self.tau = tau |
| 58 | self.gamma = gamma |
| 59 | |
| 60 | def forward(self, x): |
| 61 | mem = torch.zeros_like(x[:, 0]) |
| 62 | spikes = [] |
| 63 | T = x.shape[1] |
| 64 | for t in range(T): |
| 65 | mem = mem * self.tau + x[:, t, ...] |
| 66 | spike = fire_function(self.gamma)(mem - self.thresh) |
| 67 | mem = (1 - spike) * mem |
| 68 | spikes.append(spike) |
| 69 | return torch.stack(spikes, dim=1) |
| 70 | |
| 71 | |
| 72 | def add_dimention(x, T): |