In a feed-forward neural network with synchronous update the order

advertisement
Problem 6: Neural
Source file: neural.c
In a feed-forward neural network with synchronous update the order by which each
neuron's activation value is calculated is determined by the configuration of the net.
The activation value of a neuron can only be determined when all of the neurons that
contribute for that value have already been processed.
Figure 1 - Neuron 1 is calculated before neuron 2 and after
neuron 0.
In the neural network of Figure 1 is easy to determine the right order of activation but
suppose you have a network a little more complicated...
Figure 2 - A little more complicated network.
Neural - Page 1 of 4
Now what's the right order of activation?
The objective of this problem is to develop a function that receives as input the
description of several networks and as output give the right order of activation. It has to
be also capable of determine the input nodes, nodes that don't have any input
connection, and output nodes, nodes that don't have any output connection.
Input:
The input format is the following:
An integer representing the number of networks in the input;
For each network:
An integer, n, representing the number of neurons of the network.
For each neuron:
The number of output connections followed by the number of
each neuron connected.
Note that the neurons’ numbers are between 0 and n-1 (see the above input format).
There will be no closed cycles, i.e., there will be no loops in the networks.
Output:
The output format is the following:
For each network:
A title line “Network X”, where X is the network number.
For each input neuron:
A line “Neuron I is an input.”, where I is the input neuron
number.
For each output neuron:
A line “Neuron O is an output.”, where O is the output neuron
number.
If the network has close cycles
A line “Close cycle.”.
else
A line “Order”
A line “A B C D ..”, where A, B, C, D, etc are the neuron
numbers of the right activation order.
Neural - Page 2 of 4
Sample Input:
The representation of Figures 1 and 2:
2
3
1 1
1 2
0
12
1 3
3 0 4 5
3 1 5 6
1 7
2 7 8
1 4
1 9
1 10
1 11
1 11
1 11
0
2
3
11
12
0

12
13
3045
3156
17
278
14
19
110
111
111
111
0
Neural - Page 3 of 4
Sample Output:
Network 0
Neuron 0 is an input.
Neuron 2 is an output.
Order
0 1 2
Network 1
Neuron 2 is an input.
Neuron 11 is an output.
Order
2 1 0 3 5 4 6 7 8 9 10 11
Network0
Neuron0isaninput.
Neuron2isanoutput.
Order
012

Network1
Neuron2isaninput.
Neuron11isanoutput.
Order
21035467891011
Note:
When the order of activation is not relevant the output should be order by number.
The “Neuron x is an input.” messages should always came before the “Neuron x is an
output” ones. And all messages must be order by the number of the neurons.
Neural - Page 4 of 4
Download