IntegratorMechanism¶
Contents¶
Overview¶
An IntegratorMechanism integrates its input, possibly based on its prior values. The input can be a single
scalar value or an array of scalars (list or 1d np.array). If it is a list or array, then each value is
independently integrated. The default function (IntegratorFunction
) can be parametrized to implement either a simple
increment rate, additive accumulator, or an (exponentially weighted) time-averaging of its input. It can also be
assigned a custom function.
Creating an IntegratorMechanism¶
An IntegratorMechanism can be created directly by calling its constructor, or using the mechanism
command and
specifying INTEGRATOR_MECHANISM as its mech_spec argument. Its function is specified in the function
argument, which can be parametrized by calling its constructor with parameter values:
>>> import psyneulink as pnl
>>> my_time_averaging_mechanism = pnl.IntegratorMechanism(function=pnl.AdaptiveIntegrator(rate=0.5))
The default_variable argument specifies the format of its input (i.e., whether it is a single scalar or an array), as well as the value to use if none is provided when Mechanism is executed. Alternatively, the input_shapes argument can be used to specify the length of the array, in which case it will be initialized with all zeros.
Structure¶
An IntegratorMechanism has a single InputPort, the value
of which is
used as the variable
for its function
.
The default for function
is AdaptiveIntegrator(rate=0.5)
. However,
a custom function can also be specified, so long as it takes a numeric value, or a list or np.ndarray of numeric
values as its input, and returns a value of the same type and format. The Mechanism has a single OutputPort,
the value
of which is assigned the result of the call to the Mechanism’s
function
.
Execution¶
When an IntegratorMechanism is executed, it carries out the specified integration, and assigns the result to the
value
of its primary OutputPort. For the default function
(IntegratorFunction
), if the value specified for default_variable is a list or array, or input_shapes is greater
than 1, each element of the array is independently integrated. If its rate
parameter is a
single value, that rate is used for integrating each element. If the rate
parameter is a
list or array, then each element is used as the rate for the corresponding element of the input (in this case, rate
must be the same length as the value specified for default_variable or input_shapes).
Integration can be reset to the value of its function
s initializer by setting
its `reset
parameter to a non-zero value, as described below.
Resetting the IntegratorMechanism¶
An IntegatorMechanism has a modulable reset
parameter
that can be used to reset its value to the value of its function
s initializer
. This also clears the value
history
,
thus effectively setting the previous_value
of its function
to None.
The reset
parameter can be used to reset the IntegratorMechanism under the control of a
ControlMechanism. This simplest way to do this is to specify the reset
parameter of
the IntgeratorMechanism in the control argument of the ControlMechanism’s constructor, and to specify OVERRIDE
in its modulation argument, as in the following example:
>>> my_integrator = IntegratorMechanism()
>>> ctl_mech = pnl.ControlMechanism(modulation=pnl.OVERRIDE, control=(pnl.RESET, my_integrator))
In this case, any non-zero value of the ControlMechanism’s ControlSignal will reset the IntegratorMechanism.
OVERRIDE must be used as its modulation
parameter (instead of its default value
of MULTIPLICATIVE), so that the value of the ControlMechanism’s ControlSignal is assigned directly to the
IntegratorMechanism’s reset
parameter (otherwise, since the default of the reset
parameter is 0, the ControlSignal’s value has no effect). An alternative is to specify
the reset_default agument in the IntegratorMechanism constructor with a non-zero value, and while allowing the
ControlMechanism to use its default value for modulation
(i.e., MULTIPLICATIVE):
>>> my_integrator = IntegratorMechanism(reset_default=1)
>>> ctl_mech = pnl.ControlMechanism(control=(pnl.RESET, my_integrator))
In this case, a ControlSignal with a zero value suppresses a reset by multiplying the reset
parameter by 0, whereas a ControlSignal with a non-zero value multiples the reset
parameter’s non-zero default value, resulting in a non-zero value that elicits a reset.
Class Reference¶
- class psyneulink.core.components.mechanisms.processing.integratormechanism.IntegratorMechanism(default_variable=None, input_shapes=None, input_ports=None, function=None, reset_default=0, output_ports=None, params=None, name=None, prefs=None, **kwargs)¶
Subclass of ProcessingMechanism that integrates its input. See Mechanism for additional arguments and attributes.
- Parameters
function (IntegratorFunction : default IntegratorFunction) – specifies the function used to integrate the input. Must take a single numeric value, or a list or np.array of values, and return one of the same form.
reset_default (number, list or np.ndarray : default 0) – specifies the default value used for the
reset
parameter.
- reset¶
if non-zero, the IntegratorMechanism’s
reset
method is called, which resets thevalue
of the IntegratorMechanism to its initial value (see Resetting the IntegratorMechanism for additional details).- Type
int, float or 1d array of length 1 : default 0
- _handle_default_variable(default_variable=None, input_shapes=None, input_ports=None, function=None, params=None)¶
If any parameters with len>1 have been specified for the Mechanism’s function, and Mechanism’s default_variable has not been specified, reshape Mechanism’s variable to match function’s, but make sure function’s has the same outer dimensionality as the Mechanism’s
- _execute(variable=None, context=None, runtime_params=None, **kwargs)¶
Override to check for call to reset by ControlSignal
- exception psyneulink.core.components.mechanisms.processing.integratormechanism.IntegratorMechanismError(message, component=None)¶