# Is it possible to implement a Neural Network using a graph data structure?

I'm trying to implement a feedforward neural network using a graph. The thing is: I haven't found any example in which is used a graph data structure. So far the examples I've found used arrays.

Can anyone please point me in the direction of some literature on the topic or some tutorial?

• huh? how do you make a NN out of arrays? – vzn Aug 9 '14 at 17:32
• @vzn They used arrays as a mean to represent matrices. – m-oliv Aug 10 '14 at 20:25

Many implementations you can find out in the web are done on matrices (MATLAB for instance) since it provides a compact notation. Haykin's textbook on neural networks takes this approach. Matrices also provide a simple translation to hardware design (FPGA, ASIC, etc.). They are also more often implemented on the FPU.

If you implement a neural network in an object oriented manner, you are effectively doing what your question asks: implementing a neural network on a graph. Your neurons are then objects that have relations with each others. There are a few books that take that approach. One I can think of is an undergrad level book by Renard called Réseaux de neurones (sorry, only in French).

• good answer, but if anyone knows any english books I would love to hear about them! – Joe S Mar 4 at 21:50

You should use a directed graph since information passes in one way when running the network and in the other when training. Your data structure should support enumerating all incoming and all outgoing edges for each node, as well as enumerating nodes by their depth. Any data structure supporting these operations can be used to implement neural networks. Take it as an exercise.

I believe what you are looking for is a Graph Convolutional Network (GCN), though I'm sure you've long since found your answer.

https://tkipf.github.io/graph-convolutional-networks/

https://towardsdatascience.com/how-to-do-deep-learning-on-graphs-with-graph-convolutional-networks-7d2250723780