#P16028. [CSPro 23] 脉冲神经网络

[CSPro 23] 脉冲神经网络

Background

Luogu’s testdata is for community communication only and is not official testdata. Official judging link: https://www.cspro.org/.

In this problem, you need to implement a simulator for an SNN (spiking neural network). An SNN consists of the following parts:

  1. Neurons: update internal states by certain formulas, receive spikes, and can fire spikes.
  2. Spike sources: fire spikes at specific times.
  3. Synapses: connect neuron-to-neuron or spike-source-to-neuron, and are responsible for transmitting spikes.

Problem Description

A neuron updates its internal state following certain rules. In this problem, time is discretized: we set a time interval Δt\Delta t, and only consider times t=kΔt(k∈Z+)t = k\Delta t (k \in Z^+), and compute the variables at time kk from the values at time k−1k - 1 using the following formulas:

$$\begin{aligned} v_k &= v_{k-1} + \Delta t(0.04v_{k-1}^2 + 5v_{k-1} + 140 - u_{k-1}) + I_k \\ u_k &= u_{k-1} + \Delta t a(bv_{k-1} - u_{k-1}) \end{aligned}$$

Here, vv and uu are internal variables of the neuron that change over time, while aa and bb are constants that do not change over time. IkI_k is the sum of the strengths of all spike inputs received by this neuron at time kk; if no spike is received, then Ik=0I_k = 0. After the computation above, if vk≥30v_k \geq 30, the neuron fires a spike, which is propagated to other neurons through synapses. Meanwhile, set vkv_k to cc and set uku_k to uk+du_k + d, where cc and dd are also constants. Figure 1 shows the curve of the neuron variable vv over time.

:::align{center} :::

A synapse represents a connection between neuron-to-neuron or spike-source-to-neuron, and contains one input node and one output node (self-loops and multiple edges may exist). When the input node (a neuron or a spike source) fires a spike at time kk, after a propagation delay of D(D>0)D (D > 0) time steps, i.e. at time k+Dk + D, the output node (a neuron) will receive a spike with strength ww.

Each spike source fires a spike at each time with a certain probability. To simulate this process, each spike source has a parameter 0<r≤32,7670 < r \leq 32,767, and the following pseudorandom function is used uniformly:

C++ version:

static unsigned long next = 1;

/* RAND_MAX assumed to be 32767 */
int myrand(void) {
    next = next * 1103515245 + 12345;
    return((unsigned)(next/65536) % 32768);
}

Python version:

next = 1
def myrand():
    global next
    next = (next * 1103515245 + 12345) % (2 ** 64)
    return (next // 65536) % 32768

Java version:

long next = 1;
int myrand() {
    next = next * 1103515245 + 12345;
    return (int)((Long.divideUnsigned(next, 65536)) % 32768);
}

At each time step, in increasing order of their indices, each spike source calls the pseudorandom function once. If r>myrand()r > \text{myrand}(), it fires one spike at the current time, and the spike is propagated to neurons through synapses.

During the simulation, the states of all neurons at time 00 are known. Starting from time 11, compute according to the rules above, until finishing the computation at time TT. Then output the minimum and maximum values of neurons’ vv at time TT, and the minimum and maximum numbers of spikes fired by neurons during the whole simulation.

In the input, nodes are indexed in the following order: [0,N−1][0, N - 1] are neuron indices, and [N,N+P−1][N, N + P - 1] are spike source indices.

Please use double-precision floating-point types in your code.

Input Format

Read input from standard input.

The first line contains four positive integers N S P TN\ S\ P\ T separated by spaces, meaning there are NN neurons, SS synapses, and PP spike sources, and you need to output the neurons’ vv values at time TT.

The second line contains a positive real number Δt\Delta t, the time interval.

The next several lines each contain one positive integer RNR_N and six real numbers v u a b c dv\ u\ a\ b\ c\ d separated by spaces. Each line corresponds to RNR_N neurons that share the same initial state and constants: v uv\ u are the values of the neuron variables at time 00; a b c da\ b\ c\ d are the four constants in the neuron differential equation. It is guaranteed that the sum of all RNR_N equals NN. These lines describe the neurons in increasing index order, and each line corresponds to a consecutive segment of neuron indices.

The next PP lines each contain one positive integer rr. In order, each line gives the rr parameter of one spike source.

The next SS lines each contain two integers s(0≤s<N+P)s (0 \leq s < N + P) and t(0≤t<N)t (0 \leq t < N), one real number w(w≥0)w (w \geq 0), and one positive integer DD, separated by spaces. Here ss and tt are the indices of the input node and the output node; ww and DD are the spike strength and the propagation delay.

Output Format

Write output to standard output.

There are two lines. The first line contains two real numbers rounded to 3 decimal places, which are the minimum and maximum of variable vv over all neurons at time TT. The second line contains two integers, which are the minimum and maximum numbers of spikes fired by neurons during the whole simulation.

As long as you implement according to the requirements, you will pass; you will not get a wrong answer due to precision issues.

1 1 1 10
0.1
1 -70.0 -14.0 0.02 0.2 -65.0 2.0
30000
1 0 30.0 2
-35.608 -35.608
2 2
2 4 2 10
0.1
1 -70.0 -14.0 0.02 0.2 -65.0 2.0
1 -69.0 -13.0 0.04 0.1 -60.0 1.0
30000
20000
2 0 15.0 1
3 1 20.0 1
1 0 10.0 2
0 1 40.0 3
-60.000 -22.092
1 2

Hint

Sample 1 Explanation

This sample has 1 neuron, 1 synapse, and 1 spike source, with time interval Δt=0.1\Delta t = 0.1. The only spike source connects to the only neuron through a synapse with spike strength 30.030.0 and propagation delay 22.

This sample runs a simulation for 10 time steps. The random number generator produces 10 random numbers as follows:

16838
5758
10113
17515
31051
5627
23010
7419
16212
4086

Therefore, the only spike source fires spikes at times 1-41\text{-}4 and 6-106\text{-}10. From time 11 to 1010, the neuron’s vv values are:

-70.000
-70.000
-40.000
-8.200
-65.000
-35.404
-32.895
0.181
-65.000
-35.608

This neuron fires at time 55 and time 99, and the final result is v=−35.608v = -35.608.

Subtasks

Subtask TT NN SS PP DD Score
1 ≤102\leq 10^2 30
2 ≤103\leq 10^3 40
3 ≤105\leq 10^5 ^ ≤10\leq 10 30

Translated by ChatGPT 5