Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyBrain neuron manipulation

Is there a good way to add/remove a neuron and its associated connections into/from a fully connected PyBrain network? Say I start with:

from pybrain.tools.shortcuts import buildNetwork
net = buildNetwork(2,3,1)

How would I go about making it a (2,4,1) or a (2,2,1) network WHILE maintaining all the old weights (and initializing any new ones to be random as is done when initializing the network)? The reason I want to do this is because I am attempting to use an evolutionary learning strategy to determine the best architecture and the 'mutation' step involves adding/removing nodes with some probability. (The input and output modules should always remain the same.)

edit: I found NeuronDecomposableNetwork which should make this easier, but it still seems that I have to keep track of neurons and connections separately.

like image 374
ubomb Avatar asked Jul 25 '12 23:07

ubomb


1 Answers

I assume you're doing along the lines of the NEAT algorithm? There are two different answers to your question:

  1. Open ended evolution of the network topology: in this case, I recommend encapsulating every neuron in its own "layer"/module, and add/remove them and their connections to the network iteratively, a bit like in this tutorial, except that there will be many more (single-neuron) layers. Don't forget to call the sortModules() method after each topological change.

  2. Finding the best topology within a predefined framework (say a maximum of 1000 neurons). In that case it's easier and more efficient to build the full network in the beginning, and just mask some of the connections (e.g. using the MaskedParameters module). Among others, memetic algorithms (used like this) are designed to search such topology spaces.

An alternative, as you say, is manually managing all the weights (by tracking what is where, or using NeuronDecomposableNetwork) but I don't recommend that.


A general comment: for more advanced uses of pybrain such as yours, relying on the `buildNetwork' shortcut is really too limited, and you will want to use the Network/Module/Connection API directly.

like image 61
schaul Avatar answered Sep 23 '22 02:09

schaul