# Gating Mechanism¶

## Overview¶

A GatingMechanism is a subclass of ModulatoryMechanism that is restricted to using only GatingSignals and not ControlSignals. Accordingly, its constructor has a gating_signals argument in place of a modulatory_signals argument. It also lacks any attributes related to control. In all other respects it is identical to its parent class, ModulatoryMechanism.

## Creating A GatingMechanism¶

GatingMechanism can be created using the standard Python method of calling the constructor for the desired type. A GatingMechanism is also created automatically if gating is specified for an InputState, OutputState or Mechanism, in which case a GatingProjection is automatically created that projects from the GatingMechanism to the specified target

### Specifying gating¶

GatingMechanism are used to modulate the value of an InputState or OutputState. An InputState or OutputState can be specified for gating by assigning it a GatingProjection or GatingSignal anywhere that the Projections to a State or its ModulatorySignals can be specified. A Mechanism can also be specified for gating, in which case the primary InputState of the specified Mechanism is used. States (and/or Mechanisms) can also be specified in the gating_signals argument of the constructor for a GatingMechanism. The gating_signals argument must be a list, each item of which must refer to one or more States (or the Mechanism(s) to which they belong) to be gated by that GatingSignal. The specification for each item in the list can use any of the forms used to specify a GatingSignal.

#### GatingSignals¶

A GatingSignal is created for each item listed in the gating_signals argument of the constructor, and all of the GatingSignals for a GatingMechanism are listed in its gating_signals attribute. Each GatingSignal is assigned one or more GatingProjections to the InputState(s) and/or OutputState(s) it gates. By default, the function of GatingMechanism generates a a value – its gating_allocation – with a single item, that is used by all of the GatingMechanism’s GatingSignals. However, if a custom function is specified that generates a gating_allocation with more than one item, different GatingSignals can be assigned to the different items (see Function below).

#### Modulation¶

Each GatingMechanism has a modulation attribute, that provides a default for the way in which its GatingSignals modulate the value of the States they gate (see modulation for an explanation of how this attribute is specified and used to modulate the value of a State). Each GatingSignal uses this value, unless its value is individually specified.

## Structure¶

### Input¶

By default, a GatingMechanism has a single InputState, the value of which is used as the input to the GatingMechanism’s function.

### Function¶

A GatingMechanism’s function uses outcome (the value of its OUTCOME InputState) to generate a gating_allocation. By default, function is assigned the DefaultAllocationFunction, which takes a single value as its input, and assigns this as the value of each item of modulatory_allocation. Each of these items is assigned as the allocation for the corresponding GatingSignal in gating_signals. Thus, by default, the GatingMechanism distributes its input as the allocation to each of its gating_signals, and/or by specifying that individual GatingSignals reference different items in gating_allocation as their allocation (i.e., the value of their variable.

### Output¶

A GatingMechanism has a GatingSignal for each InputState and/or OutputState specified in its gating_signals attribute, to which it sends a GatingProjection. If the GatingMechanism’s function generates a gating_allocation with a single value (the default), then this is used as the value of all of the GatingMechanism’s gating_signals. If the gating_allocation has multiple items, and this is the same as the number of GatingSignals, then each GatingSignal is assigned the value of the corresponding item in the gating_allocation. If there is a different number of gating_signals than the number of items in the gating_allocation, then the index attribute of each GatingSignal must be specified (e.g., in a specification dictionary in the gating_signal argument of the GatingMechanism’s constructor), or an error is generated. The GatingSignals of a GatingMechanism are listed in its gating_signals attribute. Since GatingSignals are a type of OutputState, they are also listed in the GatingMechanism’s output_states attribute. The InputStates and/or OutputStates modulated by a GatingMechanism’s GatingSignals can be displayed using its show method.

## Execution¶

A GatingMechanism executes in the same way as a ProcessingMechanism, based on its place in the System’s graph. Because GatingProjections are likely to introduce cycles (recurrent connection loops) in the graph, the effects of a GatingMechanism and its projections will generally not be applied in the first TRIAL (see initialization for a description of how to configure the initialization of feedback loops in a System; also see Scheduler for a description of detailed ways in which a GatingMechanism and its dependents can be scheduled to execute).

When executed, a GatingMechanism uses its input to determine the value of its gating_allocation, each item of which is used by a corresponding GatingSignal to determine its gating_signal and assign to its GatingProjections. In the subsequent TRIAL, each GatingProjection’s value is used by the State to which it projects to modulate the value of that State (see modulation fon an explanation of how the value of a State is modulated).

Note

A State that receives a GatingProjection does not update its value (and therefore does not reflect the influence of its GatingSignal) until that State’s owner Mechanism executes (see Lazy Evaluation for an explanation of “lazy” updating).

## Class Reference¶

class psyneulink.core.components.mechanisms.adaptive.gating.gatingmechanism.GatingMechanism(default_gating_allocation=None, size=None, function=Linear(slope=1, intercept=0), gating_signals:tc.optional(list) = None, modulation=ModulationParam.MULTIPLICATIVE, params=None, name=None, prefs=None)

Subclass of AdaptiveMechanism that gates (modulates) the value(s) of one or more States.

Parameters: default_gating_allocation (value, list or ndarray : default defaultGatingAllocation) – the default value for each of the GatingMechanism’s GatingSignals; its length must equal the number of items specified in the gating_signals argument. size (int, list or 1d np.array of ints) – specifies default_gating_allocation as an array of zeros if default_gating_allocation is not passed as an argument; if default_gating_allocation is specified, it takes precedence over the specification of size. As an example, the following mechanisms are equivalent: T1 = TransferMechanism(size = [3, 2]) T2 = TransferMechanism(default_variable = [[0, 0, 0], [0, 0]])  function (TransferFunction : default Linear(slope=1, intercept=0)) – specifies the function used to transform the GatingMechanism’s variable to a gating_allocation. gating_signals (List[GatingSignal, InputState, OutputState, Mechanism, tuple[str, Mechanism], or dict]) – specifies the InputStates and/or OutputStates to be gated by the GatingMechanism; the number of items must equal the length of the default_gating_allocation argument; if a Mechanism is specified, its primary InputState is used (see GatingMechanism_GatingSignals for details). modulation (ModulationParam : ModulationParam.MULTIPLICATIVE) – specifies the default form of modulation used by the GatingMechanism’s GatingSignals, unless they are individually specified. params (Dict[param keyword: param value] : default None) – a parameter dictionary that can be used to specify the parameters for the Mechanism, parameters for its function, and/or a custom function and its parameters. Values specified for parameters in the dictionary override any assigned to those parameters in arguments of the constructor. name (str : default see name) – specifies the name of the GatingMechanism. prefs (PreferenceSet or specification dict : default Mechanism.classPreferences) – specifies the PreferenceSet for the GatingMechanism; see prefs for details.
variable

value, list or ndarray – used as the input to the GatingMechanism’s function. Its format is determined by the default_gating_allocation or size argument of the GatingMechanism’s constructor (see above), and is the same format as its gating_allocation (unless a custom function has been assigned).

function

TransferFunction – determines the function used to transform the GatingMechanism’s variable to a gating_allocation; the default is an identity function that simply assigns variable as the gating_allocation.

gating_signals

ContentAddressableList[GatingSignal] – list of GatingSignals for the GatingMechanism, each of which sends GatingProjection(s) to the InputState(s) and/or OutputStates that it gates; same as GatingMechanism output_states attribute.

gating_projections

List[GatingProjection] – list of all of the GatingProjections assigned to the GatingMechanism’s GatingSignals (i.e., listed in its gating_signals attribute.

value

scalar or 1d np.array of ints – the result of the GatingMechanism’s function; each item is the value assigned to the corresponding GatingSignal listed in gating_signals, and used by each GatingSignal to generate the gating_signal assigned to its GatingProjections; same as the GatingMechanism’s gating_allocation attribute. Default is a single item used by all of the gating_signals.

gating_allocation

scalar or 1d np.array of ints – the result of the GatingMechanism’s function; each item is the value assigned to the corresponding GatingSignal listed in gating_signals, and used by each GatingSignal to generate the gating_signal assigned to its GatingProjections; same as the GatingMechanism’s value attribute. Default is a single item used by all of the gating_signals.

modulation : ModulationParam
the default form of modulation used by the GatingMechanism’s GatingSignals, unless they are individually specified.
name : str
the name of the GatingMechanism; if it is not specified in the name argument of the constructor, a default is assigned by MechanismRegistry (see Naming for conventions used for default and duplicate names).
prefs : PreferenceSet or specification dict
the PreferenceSet for the GatingMechanism; if it is not specified in the prefs argument of the constructor, a default is assigned using classPreferences defined in __init__.py (see PreferenceSet for details).
outputStateTypes

alias of GatingSignal`