RecurrentTransferMechanism¶
Overview¶
A RecurrentTransferMechanism is a subclass of TransferMechanism that implements a singlelayered recurrent
network, in which each element is connected to every other element (instantiated in a recurrent
AutoAssociativeProjection referenced by the Mechanism’s matrix
parameter).
It can report the energy and, if appropriate, the entropy of its output, and can be configured to implement
autoassociative (e.g., Hebbian) learning.
Creating a RecurrentTransferMechanism¶
A RecurrentTransferMechanism is created directly by calling its constructor.:
import psyneulink as pnl
my_linear_recurrent_transfer_mechanism = pnl.RecurrentTransferMechanism(function=pnl.Linear)
my_logistic_recurrent_transfer_mechanism = pnl.RecurrentTransferMechanism(function=pnl.Logistic(gain=1.0,
bias=4.0))
The recurrent projection is automatically created using (1) the matrix argument or (2) the auto and hetero
arguments of the Mechanism’s constructor, and is assigned to the mechanism’s recurrent_projection
attribute.
If the matrix argument is used to create the recurrent projection, it must specify either a square matrix or an
AutoAssociativeProjection that uses one (the default is FULL_CONNECTIVITY_MATRIX
).:
recurrent_mech_1 = pnl.RecurrentTransferMechanism(default_variable=[[0.0, 0.0, 0.0]],
matrix=[[1.0, 2.0, 2.0],
[2.0, 1.0, 2.0],
[2.0, 2.0, 1.0]])
recurrent_mech_2 = pnl.RecurrentTransferMechanism(default_variable=[[0.0, 0.0, 0.0]],
matrix=pnl.AutoAssociativeProjection)
If the auto and hetero arguments are used to create the recurrent projection, they set the diagonal and offdiagonal terms, respectively.:
recurrent_mech_3 = pnl.RecurrentTransferMechanism(default_variable=[[0.0, 0.0, 0.0]],
auto=1.0,
hetero=2.0)
Note
In the examples above, recurrent_mech_1 and recurrent_mech_3 are identical.
In all other respects, a RecurrentTransferMechanism is specified in the same way as a standard TransferMechanism.
Configuring Learning¶
A RecurrentTransferMechanism can be configured for learning when it is created by assigning True
to the
enable_learning argument of its constructor. This creates an AutoAssociativeMechanism that is used to
train its recurrent_projection
, and assigns as its function
the one specified in the learning_function argument of the RecurrentTransferMechanism’s
constructor. By default, this is the Hebbian
Function; however, it can be replaced by any other function that is
suitable for autoassociative learning; that is, one that takes a list or 1d array of numeric values
(an “activity vector”) and returns a 2d array or square matrix (the “weight change matrix”) with the same dimensions
as the length of the activity vector. The AutoAssociativeLearningMechanism is assigned to the learning_mechanism
attribute and is used to modify the matrix
parameter of its recurrent_projection
(also referenced by the RecurrentTransferMechanism’s own matrix
parameter.
If a RecurrentTransferMechanism is created without configuring learning (i.e., enable_learning is assigned False
in its constructor – the default value), then learning cannot be enabled for the Mechanism until it has been
configured for learning; any attempt to do so will issue a warning and then be ignored. Learning can be configured
once the Mechanism has been created by calling its configure_learning
method, which also enables learning.
Structure¶
The distinguishing feature of a RecurrentTransferMechanism is a selfprojecting AutoAssociativeProjection – that
is, one that projects from the Mechanism’s primary OutputState back to its primary
InputState. This can be parametrized using its matrix
,
auto
, and hetero
attributes, and is
stored in its recurrent_projection
attribute.
A RecurrentTransferMechanism also has two additional OutputStates
is bounded between 0 and 1 (e.g., a Logistic
function), an ENTROPY
OutputState. Each of these report the respective values of the vector in it its RESULTS (primary) OutputState.
Finally, if it has been specified for learning, the RecurrentTransferMechanism is
associated with an AutoAssociativeMechanism that is used to train its AutoAssociativeProjection.
The learning_enabled
attribute indicates whether learning
is enabled or disabled for the Mechanism. If learning was not configured when the Mechanism was created, then it cannot
be enabled until the Mechanism is configured for learning.
In all other respects the Mechanism is identical to a standard TransferMechanism.
Execution¶
When a RecurrentTransferMechanism executes, its variable, as is the case with all mechanisms, is determined by the
projections the mechanism receives. This means that a RecurrentTransferMechanism’s variable is determined in part by the
value of its own primary OutputState on the previous execution, and the matrix
of the
recurrent projection.
Like a TransferMechanism, the function used to update each element can be assigned using its function
parameter. It then transforms its input
(including from the recurrent projection) using the specified function and parameters (see Execution),
and returns the results in its OutputStates.
If it has been configured for learning and is executed as part of a System, then its associated Learning Mechanism is executed during the learning phase of the System's execution.
Class Reference¶

class
psyneulink.library.mechanisms.processing.transfer.recurrenttransfermechanism.
RECURRENT_OUTPUT
¶ Standard OutputStates for RecurrentTransferMechanism
 RESULT : 1d np.array
 the result of the
function
of the Mechanism
 MEAN : float
 the mean of the result
 VARIANCE : float
 the variance of the result
 ENERGY : float
 the energy of the result, which is calculated using the
Stability Function
with theENERGY
metric

class
psyneulink.library.mechanisms.processing.transfer.recurrenttransfermechanism.
RecurrentTransferMechanism
(default_variable=None, size=None, function=Linear, matrix=FULL_CONNECTIVITY_MATRIX, auto=None, hetero=None, initial_value=None, noise=0.0, smoothing_factor=0.5, clip=(float:min, float:max), learning_rate=None, learning_function=Hebbian, integrator_mode=False, params=None, name=None, prefs=None)¶ Subclass of TransferMechanism that implements a singlelayer autorecurrent network.
Parameters:  default_variable (number, list or np.ndarray : default Transfer_DEFAULT_BIAS) – specifies the input to the Mechanism to use if none is provided in a call to its
execute
orrun
method; also serves as a template to specify the length ofvariable
forfunction
, and the primary OutputState of the Mechanism.  size (int, list or np.ndarray of ints) –
specifies variable as array(s) of zeros if variable is not passed as an argument; if variable 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) – specifies the function used to transform the input; can be
Linear
,Logistic
,Exponential
, or a custom function.  matrix (list, np.ndarray, np.matrix, matrix keyword, or AutoAssociativeProjection : default FULL_CONNECTIVITY_MATRIX) – specifies the matrix to use for creating a recurrent AutoAssociativeProjection, or an AutoAssociativeProjection to use. If auto or hetero arguments are specified, the matrix argument will be ignored in favor of those arguments.
 auto (number, 1D array, or None : default None) – specifies matrix as a diagonal matrix with diagonal entries equal to auto, if auto is not None; If auto and hetero are both specified, then matrix is the sum of the two matrices from auto and hetero. For example, setting auto to 1 and hetero to 1 would set matrix to have a diagonal of 1 and all nondiagonal entries 1. If the matrix argument is specified, it will be overwritten by auto and/or hetero, if either is specified. auto can be specified as a 1D array with length equal to the size of the Mechanism, if a nonuniform diagonal is desired. Can be modified by control.
 hetero (number, 2D array, or None : default None) – specifies matrix as a hollow matrix with all nondiagonal entries equal to hetero, if hetero is not None; If auto and hetero are both specified, then matrix is the sum of the two matrices from auto and hetero. For example, setting auto to 1 and hetero to 1 would set matrix to have a diagonal of 1 and all nondiagonal entries 1. If the matrix argument is specified, it will be overwritten by auto and/or hetero, if either is specified. hetero can be specified as a 2D array with dimensions equal to the matrix dimensions, if a nonuniform diagonal is desired. Can be modified by control.
 initial_value (value, list or np.ndarray : default Transfer_DEFAULT_BIAS) – specifies the starting value for timeaveraged input (only relevant if
integrator_mode
is True).  noise (float or function : default 0.0) – a stochasticallysampled value added to the result of the
function
: if it is a float, it must be in the interval [0,1] and is used to scale the variance of a zeromean Gaussian; if it is a function, it must return a scalar value.  smoothing_factor (float : default 0.5) –
the smoothing factor for exponential time averaging of input when
integrator_mode
is set to True:result = (smoothing_factor * variable) + (1smoothing_factor * input to mechanism's function on the previous time step)
 clip (Optional[Tuple[float, float]]) – specifies the allowable range for the result of
function
: the first item specifies the minimum allowable value of the result, and the second its maximum allowable value; any element of the result that exceeds the specified minimum or maximum value is set to the value ofclip
that it exceeds.  enable_learning (boolean : default False) – specifies whether the Mechanism should be configured for learning; if it is not (the default), then learning
cannot be enabled until it is configured for learning by calling the Mechanism’s
configure_learning
method.  learning_rate (scalar, or list, 1d or 2d np.array, or np.matrix of numeric values: default False) – specifies the learning rate used by its
learning function
. If it isNone
, the default learning_rate for a LearningMechanism is used; if it is assigned a value, that is used as the learning_rate (seelearning_rate
for details).  learning_function (function : default Hebbian) – specifies the function for the LearningMechanism if learning has been specified for the RecurrentTransferMechanism. It can be any function so long as it
takes a list or 1d array of numeric values as its
variable
and returns a sqaure matrix of numeric values with the same dimensions as the length of the input.  params (Dict[param keyword: param value] : default None) – a parameter dictionary that can be used to specify the parameters for the Mechanism, 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 RecurrentTransferMechanism.  prefs (PreferenceSet or specification dict : default Mechanism.classPreferences) – specifies the
PreferenceSet
for the RecurrentTransferMechanism; seeprefs
for details.  context (str : default componentType+INITIALIZING) – string used for contextualization of instantiation, hierarchical calls, executions, etc.

function
¶ Function – the Function used to transform the input.

matrix
¶ 2d np.array – the
matrix
parameter of therecurrent_projection
for the Mechanism.

recurrent_projection
¶ AutoAssociativeProjection – an AutoAssociativeProjection that projects from the Mechanism’s primary OutputState back to its primary inputState.

initial_value
¶ value, list or np.ndarray : Transfer_DEFAULT_BIAS – determines the starting value for timeaveraged input (only relevant if
smoothing_factor
parameter is not 1.0).

noise
¶ float or function : default 0.0 – a stochasticallysampled value added to the output of the
function
: if it is a float, it must be in the interval [0,1] and is used to scale the variance of a zeromean Gaussian; if it is a function, it must return a scalar value.

smoothing_factor
¶ float : default 0.5 – the smoothing factor for exponential time averaging of input when
integrator_mode
is set to True:result = (smoothing_factor * current input) + (1smoothing_factor * result on previous time_step)

clip
¶ Tuple[float, float] – determines the allowable range of the result: the first value specifies the minimum allowable value and the second the maximum allowable value; any element of the result that exceeds minimum or maximum is set to the value of
clip
it exceeds. Iffunction
isLogistic
,clip
is set by default to (0,1).

previous_input
¶ 1d np.array of floats – the value of the input on the previous execution, including the value of
recurrent_projection
.

learning_enabled
¶ bool : default False – indicates whether learning has been enabled for the RecurrentTransferMechanism. It is set to
True
if learning is specified at the time of construction (i.e., if the enable_learning argument of the Mechanism’s constructor is assignedTrue
, or when it is configured for learning using theconfigure_learning
method. Once learning has been configured,learning_enabled
can be toggled at any time to enable or disable learning; however, if the Mechanism has not been configured for learning, an attempt to setlearning_enabled
toTrue
elicits a warning and is then ignored.

learning_rate
¶ float, 1d or 2d np.array, or np.matrix of numeric values : default None – specifies the learning rate used by the
learning_function
of thelearning_mechanism
(seelearning_rate
for details concerning specification and default value assignement).

learning_function
¶ function : default Hebbian – the function used by the
learning_mechanism
to train therecurrent_projection
if learning is specified.

learning_mechanism
¶ LearningMechanism – created automatically if learning is specified, and used to train the
recurrent_projection
.

value
¶ 2d np.array [array(float64)] – result of executing
function
; same value as first item ofoutput_values
.

output_states
¶ Dict[str: OutputState] – an OrderedDict with the following OutputStates:
TRANSFER_RESULT
, thevalue
of which is the result offunction
;TRANSFER_MEAN
, thevalue
of which is the mean of the result;TRANSFER_VARIANCE
, thevalue
of which is the variance of the result;ENERGY
, thevalue
of which is the energy of the result, calculated using theStability
Function with the ENERGY metric;ENTROPY
, thevalue
of which is the entropy of the result, calculated using theStability
Function with the ENTROPY metric; note: this is only present if the Mechanism’sfunction
is bounded between 0 and 1 (e.g., theLogistic
function).

output_values
¶ List[array(float64), float, float] – a list with the following items:
 result of the
function
calculation (value of TRANSFER_RESULT OutputState);  mean of the result (
value
of TRANSFER_MEAN OutputState)  variance of the result (
value
of TRANSFER_VARIANCE OutputState);  energy of the result (
value
of ENERGY OutputState);  entropy of the result (if the ENTROPY OutputState is present).
 result of the

name
¶ str – the name of the RecurrentTransferMechanism; 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 RecurrentTransferMechanism; if it is not specified in the prefs argument of the constructor, a default is assigned usingclassPreferences
defined in __init__.py (see PreferenceSet for details).
Returns: instance of RecurrentTransferMechanism Return type: RecurrentTransferMechanism 
configure_learning
(learning_function=None, learning_rate=None)¶ Configure RecurrentTransferMechanism for learning. Creates the following Components:
 an AutoAssociativeMechanism – if the learning_function and/or learning_rate arguments are specified, they are used to construct the LearningMechanism, otherwise the values specified in the RecurrentTransferMechanism’s constructor are used;
 a MappingProjection from the RecurrentTransferMechanism’s primary OutputState to the AutoAssociativeLearningMechanism’s ACTIVATION_INPUT InputState;
 a LearningProjection from the AutoAssociativeLearningMechanism’s LEARNING_SIGNAL OutputState to
the RecurrentTransferMechanism’s
recurrent_projection
.
 default_variable (number, list or np.ndarray : default Transfer_DEFAULT_BIAS) – specifies the input to the Mechanism to use if none is provided in a call to its