Chapter 2 Inputs: From Analog to Digital
1 Why
Neurons in spiking neural networks make use of spikes to communicate with each other. This means that neurons in such networks cannot directly calculate analog signals. It is necessary for neurons in input layers to transform analog signals into spike trains. In this way, input values can be accepted by spiking neural networks.
Briefly speaking, before we use spiking neural networks, there is a question to be answered, “How to transform information into spikes with the least loss?”
As spike shapes are almost the same, neurons cannot rely on shapes to exchange information. A naive idea is that we can use 0 or 1 to represent whether input neuron should generate a spike when receiving an input value. We can split the time into discrete points and use 0 or 1 to indicate at each point whether a spike should be generated by a neuron in input layer. This monitoring period is called coding time window. In this way, input values are first transformed into binary string and then are transformed into spike trains. Figure 1 shows a toy example to transform a binary string into a spike train.
Fig. 1: A toy example for binary coding. The input value is 90 and its binary string is “1 0 1 1 0 1 0”. It has been transformed into a spike train, using “1” to indicate this neuron should spike. Here, time coding window is [ t0, t6 ].
This idea is actually naive because in practice it becomes more difficult to distinguish longer binary strings. Moreover, time coding window becomes longer which hinders the transformation efficiency.
Nevertheless, great ideas are frequently derived from naive ideas. The example above inspires an essential point for transformation: Time is a necessary factor. By knowing exact firing time, we can use spike trains of neurons in input layers to transfer information to neurons in other layers. Such methods are called temporal coding.
2 Temporal Coding
There are many approaches to make use of time to encode information into spike trains 1 2. Here we briefly introduce two of them to give some inspirations.
2.1 Time-to-First Spike Coding
Time-to-first spike coding 3 4 is an easy but concise method in transformation. It has two important assumptions: 1) time of the first spike carries, all or at least most, information and 2) the time when neurons generate the first spike after receiving an input value is related with the value of analog inputs.
Although when receiving an analog value, biological neurons often generate more than one spikes, this method deliberately overlooks other spikes. This is reasonable because if we only consider the first spike, its efficiency can be improved and neurons can make quicker responses 5. Figure 2 shows the process.
Fig. 2: Time-to-first spike coding. (a) shows the encoding rule: 1) When receiving 10 as input, the neuron will spike at 0.4ms, 2) when receiving 4.5 as input, the neuron will spike at 1ms and 3) when receiving 2.25 as input, the neuron will spike at 2ms. (b) gives three input example sets and shows when three neurons should spike separately in spike trains. x j ( i ) x_j^{(i)} xj(i) means the j-th input value in the i-th input set. Similarly, t j ( i ) t_j^{(i)} tj(i) means the spiking time for j-th neuron in i-th input set. For example, when “10, 4.5, 2.25” are received by three neurons, the first neuron should spike at 0.4ms*, the second neuron should spike at 1ms and the third neuron should spike at 2ms.*
2.2 Spike Latency Coding
Spike latency coding5 is inspired by biological optic nervous system. It encodes analog inputs into a spike train and allows a spike train to be decoded back to analog input. This method has an assumption that oscillation, existing in neurons, can help with encoding messages.
Oscillation appears in membrane potential of adjacent neurons. The phase lag is denoted by d Δ ϕ d\Delta\phi dΔϕ. Figure 3 shows a phase lag example between two neurons.
Fig. 3: Oscillation. Points in the left are all neurons. The phase leg of membrane potential between the red and green point is
d
Δ
ϕ
d\Delta\phi
dΔϕ.
The original function of membrane potential is φ ( t ) \varphi(t) φ(t). With oscillation, the function of neuron i is φ i ( t ) = φ [ t − ( i + 1 ) d Δ ϕ ] \varphi_i(t)=\varphi[ t-(i+1)d\Delta\phi] φi(t)=φ[t−(i+1)dΔϕ]. Figure 4 shows seven neurons oscillation where function period is 1ms.
Fig. 4: Oscillation of seven neurons. Neuron i follows the function
φ
i
(
t
)
=
φ
[
t
−
(
i
+
1
)
d
Δ
ϕ
]
\varphi_i(t)=\varphi[t-(i+1)d\Delta\phi]
φi(t)=φ[t−(i+1)dΔϕ].
Then a binary matrix is used to record the neuron index and corresponding spike time. Figure 5 shows the matrix.
Fig. 5: Binary matrix. Columns are discrete time points. The unit of time is 0.1ms. Rows are neurons. Here, seven neurons have been used. When elements in binary matrix A are “1”, the corresponding neurons will spike at corresponding time. Otherwise, neurons will not spike. For example, if a5,0.3 is “1”, this means Neuron 5 spikes at 0.3ms.
After defining the matrix, it is time to see how latency is applied. The number of input values should be the same as the number of neurons. Following the above seven neurons example, the inputs can be written as
S
=
(
s
0
,
s
1
,
s
2
,
s
3
,
s
4
,
s
5
,
s
6
)
=
(
6
,
9
,
4
,
2
,
3
,
1
,
14
)
S=(s_0,s_1,s_2,s_3,s_4,s_5,s_6)=(6,9,4,2,3,1,14)
S=(s0,s1,s2,s3,s4,s5,s6)=(6,9,4,2,3,1,14). If we treat input values as stimuluses, larger input values are larger stimuluses intensity. In neural systems, different stimulus intensity can lead to different spike generation time. So, the spiking time
t
i
t_i
ti should be the function of
s
i
s_i
si. More specifically, we can write
t
i
=
f
(
s
i
)
t_i = f(s_i)
ti=f(si). Usually monotonically decreasing function should be used. For example, one can use
t
i
=
f
(
s
i
)
=
t
m
a
x
−
l
n
(
α
s
i
+
1
)
t_i=f(s_i)=t_{max}-ln(\alpha s_i+1)
ti=f(si)=tmax−ln(αsi+1). Here we define
t
i
=
n
γ
s
i
t_i=\frac{n}{\gamma s_i}
ti=γsin where
γ
\gamma
γ is the period of
φ
i
(
t
)
\varphi_i(t)
φi(t),
n
n
n represents how many neurons are used and
s
i
s_i
si is input values to neuron i. In this way, different input values are converted into spiking latency
t
i
t_i
ti where larger values correspond to smaller latency (spiking earlier). Figure 6 shows this process.
Fig. 6: Spiking time, binary elements and input values.
t
i
t_i
ti tells when neuron i should spike;
a
i
,
t
i
a_{i,{t_i}}
ai,ti is the element in binary matrix
A
A
A whose value is “1”;
s
i
s_i
si is the value that neuron i receives.
After specifying when neuron i should spike and its function with oscillation φ i ( t ) \varphi_i(t) φi(t), we need to make use of different oscillation to bring convenience to encoding and decoding. Specifically, we want to build a one-to-one relationship between spikes and neurons. Alignment is employed here.
Spikes with latency will be aligned to the next peaks of
φ
i
(
t
)
\varphi_i(t)
φi(t). This procedure is represented by red lines in Figure 7. After alignment, spiking time will be projected into a spike train which consists of spiking time, which is shown by green lines in Figure 7. This projection is reversible because of alignment. When we need to decode a spike train, we can find which neuron’s function
φ
i
(
t
)
\varphi_i(t)
φi(t) reaches the peak at this spiking moment, and then determine which neuron generated this spike.
Fig. 7: Alignment. Red lines move spiking time to their next local maximum of
φ
i
(
t
)
\varphi_i(t)
φi(t). Green lines collapse different neurons’ spiking time into a single spike train. This procedure ensures the one-to-one relationship between neurons and spikes. Such a corresponding relation benefits in future our decoding of a spike train.
By spike latency coding, we can encode a series of input values into a single spike train. This can be accepted by a single neuron in input layer so that whole spiking neural networks can start processing.
2.3 Population Coding
Spike latency coding is designed to generate a spike train for a single neuron. Different from this, population coding6 focuses on using a group of neurons spiking at different time to represent an input value.
For example, Gaussian tuning curve can be used in population coding to transform analog values into a group of spiking time of different neurons. Suppose we want to use m ( m > 2 ) m(m>2) m(m>2) neurons to encode a variable x x x ranging from I m i n I_{min} Imin to I m a x I_{max} Imax. The neuron i (i = 1,2,…,m) corresponds to a Gaussian function of which the mean is μ i = I m i n + 2 i − 3 2 I m a x − I m i n m − 2 \mu_i=I_{min}+\frac{2i-3}{2}\frac{I_{max}-I_{min}}{m-2} μi=Imin+22i−3m−2Imax−Imin and the standard variance is σ = 1 β I m a x − I m i n m − 2 \sigma=\frac{1}{\beta}\frac{I_{max}-I_{min}}{m-2} σ=β1m−2Imax−Imin. In this case, β = 1.5 \beta=1.5 β=1.5.
So, the Gaussian function of neuron i can be written as
f
i
(
x
)
=
e
(
x
−
μ
)
2
2
σ
2
f_i(x)=e^{\frac{(x-\mu)^2}{2\sigma^2}}
fi(x)=e2σ2(x−μ)2. The input
x
x
x will find
m
m
m function values:
f
1
,
f
2
,
.
.
.
,
f
m
f_1, f_2, ..., f_{m}
f1,f2,...,fm. If the input
x
x
x is a vector that contains
n
n
n values, each value can find
m
m
m function values. Because
0
<
f
i
(
x
)
≤
1
0<f_i(x)\leq1
0<fi(x)≤1, we can define spiking time of neuron i as
t
i
=
T
(
1
−
f
i
(
x
)
)
t_i=T(1-f_i(x))
ti=T(1−fi(x)) where
T
T
T is the time window. Figure 8 shows how it works.
Fig. 8: Population coding. In this case, we use four neurons, indexing from 1 to 4. The input value
x
=
5.6
x=5.6
x=5.6 and maximum time
T
=
10
m
s
T=10ms
T=10ms. We use
t
i
t_i
ti to denote spiking time of neuron i and
f
i
f_i
fi to denote Gaussian function value of neuron i. We also set the relation between input value
x
x
x and
t
i
t_i
ti as
t
i
=
T
(
1
−
f
i
(
x
)
)
t_i=T(1-f_i(x))
ti=T(1−fi(x)). After population coding, we can get the spiking time of four neurons,
t
=
(
t
1
,
t
2
,
t
3
,
t
4
)
=
(
9
m
s
,
8
m
s
,
6
m
s
,
2
m
s
)
t=(t_1,t_2,t_3,t_4)=(9ms,8ms,6ms,2ms)
t=(t1,t2,t3,t4)=(9ms,8ms,6ms,2ms).
3 Examples
3.1 Time-to-First Spike Coding
It is supposed that when gray value p = 0, the neuron should spike at 0ms and when p = 225 the neuron should spike at Tmax = 10ms. Supposing spiking time is tf, then we can build a relationship by mathematical formula.
For example, we can construct a linear relationship between p and tf by the follow equation:
t
f
=
T
m
a
x
p
255
t^f = T_{max}\frac{p}{255}
tf=Tmax255p
This relationship is visualized by Figure 8.
Fig. 8: Linear relationship between spiking time and gray value. If gray values are 25, 128 and 250, neurons should spike at 0.98ms, 5.02ms and 9.8ms accordingly.
Similarly, we can also build a non-linear relationship by the following equation:
t
f
=
T
m
a
x
1
+
e
σ
(
128
−
p
)
t^f = \frac{T_{max}}{1 + e^{\sigma(128-p)}}
tf=1+eσ(128−p)Tmax
where
σ
\sigma
σ is a parameter.
When
σ
\sigma
σ is 0.05, this relationship is visualized by Figure 9.
Fig. 9: Non-linear relationship between spiking time and gray value. If gray values are 25, 128, 250, neurons should spike at 0.06ms, 5ms and 9.98ms accordingly.
When an image, with W × H W\times H W×H pixels, is encoded by time-to-first coding, there are also $ W × H W\times H W×H neurons in the input layer to spike in a certain order. Figure 10 shows neurons arrangement. It should be noted that, time-to-first coding has an implicit assumption: every neuron in the input layer only spikes once.
Fig. 10: Neuron arrangement in input layer under time-to-first coding. Yellow points in red girds are neurons in the input layer. There are
63
63
63 pixels and also
63
63
63 neurons. They correspond to pixels one by one and wait to spike at specific moments while stay quite at other moments.
3.2 Spike Latency Coding
During spike latency coding, one reception field will produce one spike train for one neuron in the input layer. Similar with convolution, this method is also compatible with padding and changing strides. Figure 11 shows an example without padding and
s
t
r
i
d
e
=
2
stride = 2
stride=2.
Fig. 11: Spike latency coding example. The input image has a shape of
10
×
10
10\times10
10×10 and reception field is
2
×
2
2\times2
2×2. So, there should be 25 reception fields in total. Accordingly, 25 neurons should be used in input layer to transform input values into spikes.
4 Reference
BUZSAKI G, LLINAS R, SINGER W, et al. Temporal Coding in the Brain[M]. Berlin, Heidelberg: Springer, 1994. ↩︎
PONULAK F, KASINSKI A. Introduction to spiking neural networks: information processing, learning and applications[J]. Acta Neurobiologiae Experimentalis, 2010, 71(4): 409-433. ↩︎
THORPE S, FIZE D, MARLOT C. Speed of processing in the human visual system[J]. Nature, 1996, 381(6582): 520-522. ↩︎
HEIL P. First-spike latency of auditory neurons revisited[J]. Current Opinion in Neurobiology, 2004, 14(4): 461-467. ↩︎
NADASDY Z. Information encoding and reconstruction from the phase of action potentials[J]. Frontiers in Systems Neuronscience, 2009, 3: 6. ↩︎ ↩︎
BOHTE S M, KOK J N, LA POUTRE H. Error-backpropagation in temporally encoded networks of spiking neurons[J]. Neurocomputing, 2002, 48(1): 17-37. ↩︎