3

I am using pybrain to build neural network. Sometimes a graphical representation of the situation would be very useful.

Is it possible to plot the structure of a neural network generated using pybrain?

Donbeo
  • 17,067
  • 37
  • 114
  • 188
  • look "[how to print a network (nodes and weights)][1]" [1]: http://stackoverflow.com/questions/8150772/pybrain-how-to-print-a-network-nodes-and-weights – Gean Kleber Mar 13 '14 at 13:37
  • Thanks but it prints the results. I am more interested in a plot – Donbeo Mar 13 '14 at 16:09

2 Answers2

1

I think the original questioner was probably looking for something like this (as I am, though without the animation): http://www.codeproject.com/KB/dotnet/predictor/learn.gif

And I think this is more or less answered in this post: How to visualize a neural network

"More or less" because it would be nice to see the cell reference (A0, A1, A2, B0, etc, or whatever) inside each circle.

But I'm a total beginner in Python and in neural networks, feel free to correct me if I'm wrong.

  • Guy
Community
  • 1
  • 1
Guy
  • 11
  • 1
0

As was already mentioned, this answer How to visualize a neural network shows how to plot simple networks using pyplot.

Here is how to adapt this solution for PyBrain:

class PybrainNNVisualizer():
    def __init__(self, neural_network):
        """
        :type neural_network: Network
        """
        self.neural_network = neural_network

    def draw(self):
        widest_layer = max([layer.dim for layer in self.neural_network.modules])
        network = NeuralNetwork(widest_layer)
        for layer in self.neural_network.modulesSorted:
            if type(layer) is BiasUnit:
                continue
            network.add_layer(layer.dim)
        network.draw()

Usage:

fnn = buildNetwork(4, 8, 1)

PybrainNNVisualizer(fnn).draw()

Full source code: https://github.com/AlexP11223/SimplePyBrainNeuralNeutwork/blob/master/nnvisualizer.py

Alex P.
  • 3,697
  • 9
  • 45
  • 110