IntegratorMechanism

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 (Integrator) 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 size 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 InputState, 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 OutputState, 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 OutputState. For the default function (Integrator), if the value specified for default_variable is a list or array, or size is greater than 1, each element of the array is independently integrated. If its rate parameter is a single value, that rate will be used for integrating each element. If the rate parameter is a list or array, then each element will be 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 size).

Class Reference

class psyneulink.components.mechanisms.processing.integratormechanism.IntegratorMechanism(default_variable=None, size=None, function=AdaptiveIntegrator(rate=0.5), params=None, name=None, prefs=None)

Subclass of ProcessingMechanism that integrates its input.

Parameters:
  • default_variable (number, list or np.ndarray) – the input to the Mechanism to use if none is provided in a call to its execute or run methods; also serves as a template to specify the length of variable for function, and the primary outputState of the Mechanism.
  • size (int, list or np.ndarray of ints) –

    specifies default_variable as array(s) of zeros if default_variable is not passed as an argument; if default_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 (IntegratorFunction : default Integrator) – 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.
  • 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 IntegratorMechanism.
  • prefs (PreferenceSet or specification dict : default Mechanism.classPreferences) – specifies the PreferenceSet for the IntegratorMechanism; see prefs for details.
variable

value: default – the input to Mechanism’s function.

name

str – the name of the IntegratorMechanism; 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 IntegratorMechanism; 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).

class AdaptiveIntegrator(default_variable=None, rate=1.0, noise=0.0, scale: parameter_spec = 1.0, offset: parameter_spec = 0.0, initializer, params=None, owner=None, prefs=None)

Computes an exponentially weighted moving average.

(1 - rate) * previous_value + rate * variable + noise

Parameters:
  • default_variable (number, list or np.array : default ClassDefaults.variable) – specifies a template for the value to be integrated; if it is a list or array, each element is independently integrated.
  • rate (float, list or 1d np.array : default 1.0) – specifies the smoothing factor of the EWMA. If it is a list or array, it must be the same length as variable (see rate for details).
  • noise (float, PsyNeuLink Function, list or 1d np.array : default 0.0) – specifies random value to be added in each call to function. (see noise for details).
  • float, list or 1d np.array (initializer) – specifies starting value for integration. If it is a list or array, it must be the same length as default_variable (see initializer for details).
  • params (Dict[param keyword: param value] : default None) – a parameter dictionary that specifies the parameters for the function. Values specified for parameters in the dictionary override any assigned to those parameters in arguments of the constructor.
  • owner (Component) – component to which to assign the Function.
  • name (str : default see name) – specifies the name of the Function.
  • prefs (PreferenceSet or specification dict : default Function.classPreferences) – specifies the PreferenceSet for the Function (see prefs for details).
variable

number or np.array – current input value some portion of which (determined by rate) will be added to the prior value; if it is an array, each element is independently integrated.

rate

float or 1d np.array – determines the smoothing factor of the EWMA. All rate elements must be between 0 and 1 (rate = 0 –> no change, variable is ignored; rate = 1 –> previous_value is ignored).

If rate is a float, it is applied to all elements of variable (and previous_value); if it has more than one element, each element is applied to the corresponding element of variable (and previous_value).

noise

float, function, list, or 1d np.array – specifies random value to be added in each call to function.

If noise is a list or array, it must be the same length as variable.

If noise is specified as a single float or function, while variable is a list or array, noise will be applied to each variable element. In the case of a noise function, this means that the function will be executed separately for each variable element.

Note

In order to generate random noise, we recommend selecting a probability distribution function (see Distribution Functions for details), which will generate a new noise value from its distribution on each execution. If noise is specified as a float or as a function with a fixed output, then the noise will simply be an offset that remains the same across all executions.

initializer

float, 1d np.array or list – determines the starting value for time-averaging (i.e., the value to which previous_value is originally set).

If initializer is a list or array, it must be the same length as variable.

previous_value

1d np.array : default ClassDefaults.variable – stores previous value with which variable is integrated.

owner

Componentcomponent to which the Function has been assigned.

name

str – the name of the Function; if it is not specified in the name argument of the constructor, a default is assigned by FunctionRegistry (see Naming for conventions used for default and duplicate names).

prefs

PreferenceSet or specification dict : Function.classPreferences – the PreferenceSet for function; if it is not specified in the prefs argument of the Function’s constructor, a default is assigned using classPreferences defined in __init__.py (see PreferenceSet for details).

function(variable=None, params=None, context=None)

Return: some fraction of variable combined with some fraction of previous_value.

Parameters:
  • variable (number, list or np.array : default ClassDefaults.variable) – a single value or array of values to be integrated.
  • params (Dict[param keyword: param value] : default None) – a parameter dictionary that specifies the parameters for the function. Values specified for parameters in the dictionary override any assigned to those parameters in arguments of the constructor.
Returns:

updated value of integral

Return type:

2d np.array