Network customization#

Depending on the task you are simulating or the mechanisms you are testing, you may need to customize the weights in your network or the parameters applied to different parts of the network.

Network addresses#

A network contains multiple subdivisions that help organize how different parts are used. When initializing a network, you must indicate which segments to include on the item \(f\) and \(c\) layers.

Layers are specified using an address:


A layer of the network; either f or c.


A sublayer within that layer. This is used to allow different behavior within a layer, for example different context evolution rates.


Segment within the sublayer. This is used for convenience to organize sublayers. For example, may designate one segment for items, another as a start unit, and another segment to represent distractor items.


Unit within the segment, indicated as an integer. The first unit is 0.

These can be specified at different levels of scope. For example, a segment of a layer is specified using layer, sublayer, and segment labels.

Parts of weight matrices connecting layers are specified using addresses for both the \(f\) and \(c\) layers. An area of a weight matrix is called a region and is indicated by two segment specifications.

In [1]: from cymr import network

In [2]: f_segment = {'task': {'item': 24, 'start': 1}}

In [3]: c_segment = {
   ...:     'loc': {'item': 24, 'start': 1},
   ...:     'cat': {'item': 3, 'start': 1},
   ...: }

In [4]: net = network.Network(f_segment, c_segment)

In [5]: print(net)
task: 25 units
    item: 24 units
    start: 1 units

loc: 25 units
    item: 24 units
    start: 1 units
cat: 4 units
    item: 3 units
    start: 1 units

Setting connection weights#

Connection weights may be specified using a patterns dictionary together with a weights template.

In [6]: cat = np.zeros((24, 3))

In [7]: cat[:8, 0] = 1

In [8]: cat[8:16, 1] = 1

In [9]: cat[16:, 2] = 1

In [10]: patterns = {
   ....:     'vector': {
   ....:         'loc': np.eye(24),
   ....:         'cat': cat,
   ....:     },
   ....: }

Once a set of patterns has been defined, they can be referenced in a weights template to indicate where they should be placed. First, define the sublayers to be included in the model.

In [11]: from cymr import cmr

In [12]: param_def = cmr.CMRParameters()

In [13]: param_def.set_sublayers(f=['task'], c=['loc', 'cat'])

Regions of the weights matrices are addressed as tuples of ('sublayer', 'segment') for the \(f\) and \(c\) layers. Segments will be added as needed to include all of the indicated weights.

In [14]: weights = {
   ....:     (('task', 'item'), ('loc', 'item')): 'loc',
   ....:     (('task', 'item'), ('cat', 'item')): 'cat',
   ....: }

In [15]: param_def.set_weights('fc', weights)

In [16]: param_def.set_weights('cf', weights)

The weights template indicates which regions to add weights to. For each specified region, you may use any expression referencing any of the vector patterns in the patterns dictionary, and optionally any parameter. The expression may also use any numpy function available from the main numpy namespace. In this simple example, here, we just reference the loc and cat patterns to place those patterns in the specified regions in the \(M^{FC}\) and \(M^{CF}\) weight matrices.