First, import the files for a neural network:
-
from pyrobot.brain.conx import *
It would be easiest for me if you now went and read * in pyro.brain.conx; that way I could perhaps stop writing. Still here? Believe the rest of this at your own risk because it's only my guess. Feel free to correct the mistakes you catch.
To write a brain, carry out the usual steps (see BuildingBrains). Add a network to your brain, say self.net, by calling Network() or SRN(), depending on what kind of network you want self.net to be. Let's pretend you chose to keep an SRN, i.e. typed self.net = SRN(). You can automatically create and connect the four typical SRN layers: input, hidden, context and output, by typing self.net.addSRNLayers( <input-size>, <hidden-size>, <output-size>). Or you can define your own layers one at a time as follows:
-
self.net.add(Layer(<layer-name (string)>, <layer-size>))
If you do the latter, you will also need to connect your layers yourself:
-
self.net.connect(Layer(<from-layer>, <to-layer>))
And you may possibly wish to initialize some layers with specific activations. To do so, use copyActivations, for example:
-
self.net.getLayer('context').copyActivations([0.5, 0.5])
Now to set various network variables, about which I don't really know much. Maybe you do. Most of them are probably clearly described by their names. Here are the settings we used:
-
self.net.setBatch(0)
self.net.setVerbosity(0)
self.net.setEpsilon(.5)
self.net.setMomentum(.1)
self.net.setLearning(0)
Once the network is initialized, you may do what you like to it. In general, take care that you:
1. Set inputs, i.e. make sure the input layer has up-to-date activations
-
self.net.getLayer('input').copyActivations([a,b,c]), or self.net.setInputs([[a,b,c]])
2. Ensure that the context layer has the right values (probably done automatically most of the time?)
-
self.net.getLayer('context').copyActivations( self.net.getLayer('hidden').activation )
-
This copies the activation list/vector of 'hidden' into 'context'.
3. Propagate
-
self.net.propagate()
4. Set targets for the output layer if you want the network to learn anything
-
self.net.getLayer('output').copyTarget([j, c, k, l])
5. Back-propagate to determine the difference between the output targets and the values generated by propagate (i.e. the error)
-
self.net.backprop()
6. Change weights so that the network really does learn instead of passively observing its errors
-
self.net.change_weights()
These steps need not be done in the above order. In fact, if you know your target outputs beforehand, you can set them first, set your inputs and skip all the other steps by calling self.net.sweep() (or self.net.step(), which is supposed to keep it simple).
To access the activation of a specific cell in a specific layer, such as the first output layer cell, consider using
-
self.net.getLayer('output').activation[0]
