-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscratch2.py
59 lines (40 loc) · 1.35 KB
/
scratch2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
"""
Created on Tue May 24 17:59:24 2016
@author: boldingd
"""
import SnnBase
class GapCounter:
def __init__(self, name):
self.name = name
self.time = 0.0
self.gaps = []
self.last_spike = 0.0
def step(self, dt):
self.time += dt
def notify_of_spike(self):
self.gaps.append(self.time - self.last_spike)
self.last_spike = self.time
def report(self):
fname = self.name + ".dat"
with open(fname, "w") as ofile:
for gap in self.gaps:
ofile.write(str(gap) + "\n")
# each is 10 Hz
poisson = SnnBase.PoissonSpiker(1.0, 10.0)
naive = SnnBase.NaiveRandomSpiker(1.0, 10.0)
pulsar = SnnBase.Pulsar(1.0, 10.0)
poisson_counter = SnnBase.Counter(name="poisson")
poisson.add_spike_listener(poisson_counter)
naive_counter = SnnBase.Counter(name="naive")
naive.add_spike_listener(naive_counter)
pulsar_counter = SnnBase.Counter(name="pulsar")
pulsar.add_spike_listener(pulsar_counter)
poisson_gaps = GapCounter(name="poisson_gaps")
poisson.add_spike_listener(poisson_gaps)
entities = [poisson, naive, pulsar, poisson_counter, naive_counter, pulsar_counter, poisson_gaps]
SnnBase.run_simulation(10.0, 1.0 / 1000.0, entities)
poisson_counter.report()
naive_counter.report()
pulsar_counter.report()
poisson_gaps.report()