Over the last few weeks, I had been looking for a versatile software to draw neural net beautifully and consistently. OmniGraffle is my most favorite application when it comes to chart drawing. But unfortunately, it did not work so well when I attempted to use it to draw a neural net.

Using Tikz requires spending sometimes on reading its manual, which is about 400 pages. It is exceedingly overwhelming for a package but we actually don’t need to read all of that. To draw neural net, solely reading Chapter 13 of the manual should be sufficient.

As far as I am concerned, using Tikz have some exceptional advantages over using applications. For example,

  • Consistency Because Tikz allows to define for-loop and styles in a similar manner to CSS, I can consistenly define and adjust the whole structure of the network within seconds.
  • Elegance Beautifulness is more or less about personal taste, but to me figures generated by Tikz are very pleasant.

Besides some pros, there are certainly a few cons can be listed.

  • Clumsiness It is definitely clumsy to write codes in Latex.
  • Readability When I write some lines of code, get away a few days and look back, it is challenging to understand even my own codes. I strongly advocate a good comment and coding style if you don’t want to be like “What the hell!” when look back at your own codes.

Below are some examples of neural nets generated by Tikz. They are accompanied with source codes for further personal modifications as well.

Fig 1. General three layers NN

Fig 1. General three layers NN

Fig 1. A specific NN with 3 inputs, 3 hidden neurons, and 3 outputs

Fig 1. A specific NN with 3 inputs, 3 hidden neurons, and 3 outputs

Fig 1. Signal flow at neuron j

Fig 1. Signal flow at neuron j