Setting parameters with Configs

Building models with the modelling API involves constructing many objects, each with many parameters that can be set. To make setting all of these parameters easier, Nengo has a config system and pre-set configurations.

The config system

Nengo’s config system is used for two important functions:

  1. Setting default parameters with a hierarchy of defaults.
  2. Associating new information with Nengo classes and objects without modifying the classes and objects themselves.

A tutorial-style introduction to the config system can be found below:

config system API

class nengo.Config(*configures)[source]

Configures network-level defaults and additional parameters.

Every Network contains an associated Config object which can be manipulated to change network-specific defaults, and to store additional parameters (for example, those specific to a backend).

A Config object can configure objects of any class, but it has to be told the classes to configure first. This is either done on instantiation of the Config object or by calling the configures method. This sets up a mapping between configured class and a ClassParams object that sets the default values for that class. Attempting to configure an instance of a configure class will create a mapping from that instance to an InstanceParams object to configure additional parameters for that instance.

Parameters:

*configures

The classes that this Config instance will configure.

Examples

To configure defaults on a network:

net = nengo.Network()
net.config[nengo.Ensemble].radius = 1.5
with net:
    ens = nengo.Ensemble(10, 1)
ens.radius == 1.5  # True

To add a new parameter to a Nengo object:

net.config[nengo.Ensemble].set_param(
    'location', nengo.params.Parameter('location'))
net.config[ens].location = 'cortex'

To group together a set of prameters:

gaba = nengo.Config(nengo.Connection)
gaba[nengo.Connection].synapse = nengo.Lowpass(0.008)
with net, gaba:
    conn = nengo.Connection(ens, ens)
conn.synapse == nengo.Lowpass(0.008)  # True

To configure a new type of object:

class SynapseInfo(object):
    label = nengo.params.StringParam('label')
gaba.configures(SynapseInfo)
gaba[SynapseInfo].label = "GABA"  # Set default label

Attributes

params (dict) Maps configured classes and instances to their ClassParams or InstanceParams object.
static all_defaults(nengo_cls=None)[source]

Look up all of the default values in the current context.

Parameters:

nengo_cls : class, optional

If specified, only the defaults for a particular class will be returned. If not specified, the defaults for all configured classes will be returned.

Returns:

str

static default(nengo_cls, param)[source]

Look up the current default value for a parameter.

The default is found by going through the config stack, from most specific to least specific. The network that an object is in is the most specific; the top-level network is the least specific. If no default is found there, then the parameter’s default value is returned.

configures(*classes)[source]

Start configuring a particular class and its instances.

class nengo.config.ClassParams(configures)[source]

A class to store extra parameters and defaults on configured classes.

This is used by Config to associate defaults and new Parameter instances with existing objects. It should not be instantiated outside of Config.configures.

Parameters:

configures : class

The class with which to associate new defaults and parameters.

update(d)[source]

Sets a number of parameters at once given a dictionary.

class nengo.config.InstanceParams(configures, clsparams)[source]

A class to store parameter value on configured objects.

In contrast to ClassParams, the only thing that can be done with InstanceParams is get and set parameter values. Use the corresponding ClassParams to set defaults and create new parameters.

Preset configs

Nengo includes preset configurations that can be dropped into your model to enable specific neural circuits.

nengo.presets.ThresholdingEnsembles(threshold, intercept_width=0.15, radius=1.0)[source]

Configuration preset for a thresholding ensemble.

This preset adjust ensemble parameters for thresholding. The ensemble’s neurons will only fire for values above threshold. One can either decode the represented value (if it is above the threshold) or decode a step function if binary classification is desired.

This preset:

  • Sets intercepts to be between threshold and radius with an exponential distribution (shape parameter of intercept_width). This clusters intercepts near the threshold for better approximation.
  • Sets encoders to 1.
  • Sets dimensions to 1.
  • Sets evaluation points to be uniformly distributed between threshold and radius.
  • Sets the radius.
Parameters:

threshold : float

Point at which ensembles should start firing.

intercept_width : float, optional (Default: 0.15)

Controls how widely distributed the intercepts are. Smaller values give more clustering at the threshold, larger values give a more uniform distribution.

radius : float, optional (Default: 1.)

Ensemble radius.

Returns:

nengo.Config

Configuration with presets.