StatefulFunction¶

class psyneulink.core.components.functions.statefulfunctions.statefulfunction.StatefulFunction(default_variable=None, rate=None, noise=None, initializer=None, params=None, owner=None, prefs=None, context=None, **kwargs)

Abstract base class for Functions the result of which depend on their previous_value attribute.

Parameters: default_variable (number, list or array : default class_defaults.variable) – specifies a template for variable. initializer (float, list or 1d array : default 0.0) – specifies initial value for previous_value. If it is a list or array, it must be the same length as variable (see initializer for details). rate (float, list or 1d array : default 1.0) – specifies value used as a scaling parameter in a subclass-dependent way (see rate for details); if it is a list or array, it must be the same length as variable. noise (float, function, list or 1d array : default 0.0) – specifies random value added in each call to function; if it is a list or array, it must be the same length as variable (see noise 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 array – current input value.

initializer

float or 1d array – determines initial value assigned to previous_value. If variable is a list or array, and initializer is a float or has a single element, it is applied to each element of previous_value. If initializer is a list or array,each element is applied to the corresponding element of previous_value.

previous_value

1d array – last value returned (i.e., for which state is being maintained).

initializers

list – stores the names of the initialization attributes for each of the stateful attributes of the function. The index i item in initializers provides the initialization value for the index i item in stateful_attributes.

stateful_attributes

list – stores the names of each of the stateful attributes of the function. The index i item in stateful_attributes is initialized by the value of the initialization attribute whose name is stored in index i of initializers. In most cases, the stateful_attributes, in that order, are the return values of the function.

.. _Stateful_Rate
rate

float or 1d array – on each call to function, applied to variable, previous_value, neither, or both, depending on implementation by subclass. If it is a float or has a single value, it is applied to all elements of its target(s); if it has more than one element, each element is applied to the corresponding element of its target(s).

.. _Stateful_Noise
noise

float, function, list, or 1d array – random value added on each call to function. If variable is a list or array, and noise is a float or function, it is applied for each element of variable. If noise is a function, it is executed and applied separately for each element of variable. If noise is a list or array, it is applied elementwise (i.e., in Hadamard form).

Hint

To generate random noise that varies for every execution, a probability distribution function should be used (see Distribution Functions for details), that generates a new noise value from its distribution on each execution. If noise is specified as a float, a function with a fixed output, or a list or array of either of these, then noise is simply an offset that remains the same across all executions.

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 – the PreferenceSet for the 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 Preferences for details).

_parse_value_order(**kwargs)
Returns: the values of the keyword arguments in the order in which they appear in this Component’s value tuple
reset(*args, context=None, **kwargs)

Resets value and previous_value to the specified value(s).

If arguments are passed into the reset method, then reset sets each of the attributes in stateful_attributes to the value of the corresponding argument. Next, it sets the value to a list containing each of the argument values.

If reset is called without arguments, then it sets each of the attributes in stateful_attributes to the value of the corresponding attribute in initializers. Next, it sets the value to a list containing the values of each of the attributes in initializers.

Often, the only attribute in stateful_attributes is previous_value and the only attribute in initializers is initializer, in which case the reset method sets previous_value and value to either the value of the argument (if an argument was passed into reset) or the current value of initializer.

For specific types of StatefulFunction functions, the reset method may carry out other reinitialization steps.