#P1038. Neural Network Signal Propagation
Neural Network Signal Propagation
Neural Network Signal Propagation
In Lanlan's model, a neural network is represented as a directed graph where nodes (neurons) are arranged in layers. There is at most one edge between any two neurons. Each neuron i has several properties: input channels (e.g. (X_1) to (X_3)), output channels ((Y_1) to (Y_2)), a state (C_i), and a threshold (U_i) (an intrinsic parameter). In this model, neurons are divided into an input layer, one or more hidden layers, and an output layer. Neurons in a given layer receive signals only from the previous layer and send signals only to the next layer. If a neuron is in an excited (active) state (i.e. (C_i > 0)), it will send out a signal in the next second with strength (C_i); otherwise, it remains quiet.
The state of a neuron is determined by the formula:
[ C_i = \left( \sum_{(j,i) \in E} W_{ji} \cdot C_j \right) - U_i ]
where (W_{ji}) (which may be negative) is the weight of the edge from neuron j to neuron i. Note that in the summation, only neurons that are excited (i.e. those with (C_j > 0)) will effectively contribute their signal (if (C_j \le 0), they send no signal).
Given a neural network along with the initial states for the input layer neurons, compute the final states of the output layer neurons after signal propagation through the network. All neurons (except those in the input layer) compute their state in a single feedforward pass following the layer order. The input layer neurons have their states given directly. For any neuron (in non-input layers), its state (C_i) is computed by summing contributions from neurons in the previous layer (each contributing (W_{ji}\times C_j) only if (C_j>0)) and then subtracting its threshold (U_i).
inputFormat
The input begins with an integer (L) ((L \ge 2)) representing the number of layers in the neural network. The second line contains (L) space-separated integers representing the number of neurons in each layer (the first layer is the input layer and the last layer is the output layer).
The third line contains (N) space-separated integers representing the threshold (U_i) for each neuron, where (N) is the total number of neurons (ordered layer by layer).
The fourth line contains an integer (M) representing the number of directed edges in the network. Each of the next (M) lines contains three values: two integers and a number: (a), (b) and (W), indicating that there is an edge from neuron (a) to neuron (b) with weight (W). Neurons are numbered sequentially across layers in order.
The last line contains the initial states for the input layer neurons ((C_i) for neurons in layer 1), given as space‐separated numbers.
outputFormat
Output the final states of the output layer neurons in order, separated by a space. (Note: The final state of a neuron is computed using (C_i = \left( \sum_{(j,i) \in E} W_{ji}\cdot (\text{if } C_j > 0 \text{ then } C_j \text{ else } 0) \right) - U_i).)
sample
3
2 2 1
1 0 1 0 2
6
1 3 2
1 4 -1
2 3 3
2 4 2
3 5 1
4 5 4
3 2
13