Beanshell Scripting

Beanshell is basically java in a form that can be executed dynamically.  So rather than writing and compiling java source code, you can simply write it and run it immediately. Since it is basically java, to use Beasnhell requires that you know java.   But many tasks are fairly routine and you can make them happen by modifing existing code (see the examples below).

The first thing you will often do in a script is to either (1) create objects and add them to the workspace, or (2) get access to objects already in the workspace. Objects could be networks, neurons, neuron groups, synapses, synpase groups, agents in worlds, plot components, or other components.   Once you have these objects you can do various things with them.

By default, beanshell scripts have access to two objects:

workspace: the underlying logical representation of all components in Simbrain.   You can add new components to the workspace, or get components and then modify them. This is the main point of access to Simbrain.

desktop: the graphical object which displays a workspace.  In scripts this is mostly used to specify where components are, or how large they are.

For example, to add a neuron to a neural network component named "Network1" in Simbrain, you can create the neuron then add it to Network1:

    Network network =  workspace.getComponent("Network 1").getNetwork();
    Neuron neuron1 = new Neuron(network, "LinearRule");
    neuron1.setLocation(2,2);
    network.addNeuron(neuron1);

To take full advantage of Simbrain, you will need to be familiar with the Simbrain source code, which has a great number of facilities for creating neural networks, connecting neurons together, laying them out, etc.   The source if fairly well documented.   See{SimbrainHome}/src

Coordinating Workspace Zip Files and Scripts

Sometimes it  is useful to create a script that modifies the behavior of a workspace file (a .zip file).   That way the script takes care of the custom behavior, and the workspace file can be incrementally modified using Simbrain's point and click methods.  Examples are the actor-critic  and Rescorla Wagner scripts.   To edit the workspace in such a case, just run the script, change the workspace, and then save the workspace.

Troubleshooting

Often scripts won't work at first.  To get feedback on errors that occur run Simbrain from a terminal, using this command

java -jar Simbrain.jar

Note that in beanshell you cannot use 2d arrays or generics.