Java API Example: Coding a Network that Integrates

The following Java code builds and runs a model of a neural integrator. Imports, class structure, etc. are excluded for clarity. Here is the source code for the complete working example.

//Create a new network ...
Network network = new NetworkImpl();

//Create an external input to the network as a function of time (a constant function in this case) ...

Function f = new ConstantFunction(1, 1f);
FunctionInput input = new FunctionInput("input", new Function[]{f}, Units.UNK);

//Put the external input in the network ...
network.addNode(input);

//Create a "factory", a tool for easily creating ensembles of neurons ...
NEFEnsembleFactory ef = new NEFEnsembleFactoryImpl();

//Create an ensemble of neurons using the above factory and add it to the network ...

NEFEnsemble integrator = ef.make("integrator", 500, 1, "integrator1", false);
network.addNode(integrator);

//Set up a "termination" (an input) onto this ensemble and attach the function input to it (the termination has post-synaptic current dynamics with time constant 5ms) ...

float tau = .05f;
Termination interm = integrator.addDecodedTermination("input", new float[][]{new float[]{tau}}, tau, false);
network.addProjection(input.getOrigin(FunctionInput.ORIGIN_NAME), interm);

//Set up another termination for feedback from the ensemble to itself, which will make the ensemble maintain its activity with no input, as an integrator ...

Termination fbterm = integrator.addDecodedTermination("feedback", new float[][]{new float[]{1f}}, tau, false);
network.addProjection(integrator.getOrigin(NEFEnsemble.X), fbterm);

//Run the network for one second of simulation time ...
network.run(0, 1);

The above simulation doesn't provide any data to indicate what the network did. We can collect data by adding a "probe" before running, like this:

Probe integratorProbe = network.getSimulator().addProbe("integrator", NEFEnsemble.X, true);

Then, after running we can plot the output:

Plotter.plot(integratorProbe.getData(), .005f, "Integrator Output");

Please refer to the API documentation for more information about the meanings of method arguments and the definitions of various classes.