Closed arvoelke closed 4 years ago
Supercedes #158.
Some Poisson code here: https://github.com/nengo/nengo/issues/1487
Some stochastic code below (WIP):
class StochasticSpikingMixin: """Spiking via stochastic-rounding of some given tuning curve.""" probeable = ('spikes',) # TODO(arvoelke): the simulator should pass in the rng rng = np.random.RandomState(seed=0) def rates(self, x, gain, bias): J = self.current(x, gain, bias) output = np.zeros_like(J) self._curve(J=J, output=output) return output def step_math(self, dt, J, spiked): rates = np.zeros_like(J) self._curve(J=J, output=rates) e_spikes = rates * dt # https://en.wikipedia.org/wiki/Rounding#Stochastic_rounding n_spikes = np.floor(e_spikes) n_spikes[self.rng.rand(spiked.size) < e_spikes - n_spikes] += 1 spiked[...] = n_spikes / dt # no amplitude scaling def _curve(self, J, output): raise NotImplementError("_curve must be implemented")
Closing in favour of internal solution.
Supercedes #158.
Some Poisson code here: https://github.com/nengo/nengo/issues/1487
Some stochastic code below (WIP):