StatefulFunction¶
- class psyneulink.core.components.functions.stateful.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 asvariable
(seeinitializer
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 asvariable
.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 asvariable
(seenoise
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 (seeprefs
for details).
- variable¶
current input value.
- Type
number or array
- initializer¶
determines initial value assigned to
previous_value
. Ifvariable
is a list or array, and initializer is a float or has a single element, it is applied to each element ofprevious_value
. If initializer is a list or array,each element is applied to the corresponding element ofprevious_value
.- Type
float or 1d array
- previous_value¶
last value returned (i.e., for which state is being maintained).
- Type
1d array
- initializers¶
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
.- Type
list
- stateful_attributes¶
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.- Type
list
- .. _Stateful_Rate
- rate¶
on each call to
function
, applied tovariable
,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).- Type
float or 1d array
- .. _Stateful_Noise
- noise¶
random value added on each call to
function
. Ifvariable
is a list or array, and noise is a float or function, it is applied for each element ofvariable
. If noise is a function, it is executed and applied separately for each element ofvariable
. 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.Note
A ParameterPort for noise will only be generated, and the noise Parameter itself will only be stateful, if the value of noise is entirely numeric (contains no functions) at the time of Mechanism construction.
- Type
float, function, list, or 1d array
- name¶
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).
- Type
str
- prefs¶
the
PreferenceSet
for the Function; if it is not specified in the prefs argument of the Function’s constructor, a default is assigned usingclassPreferences
defined in __init__.py (see Preferences for details).- Type
PreferenceSet or specification dict
- _validate(context=None)¶
Eventually should contain all validation methods, occurs at end of Component.__init__
- _validate_params(request_set, target_set=None, context=None)¶
Validate params and assign validated values to targets,
This performs top-level type validation of params
This can be overridden by a subclass to perform more detailed checking (e.g., range, recursive, etc.) It is called only if the parameter_validation attribute is
True
(which it is by default)- IMPLEMENTATION NOTES:
future versions should add recursive and content (e.g., range) checking
should method return validated param set?
- Parameters
validated (dict (target_set) - repository of params that have been) –
validated –
- Return none
- _parse_value_order(**kwargs)¶
- Returns
the values of the keyword arguments in the order in which they appear in this Component’s
value
- Return type
tuple
- reset(*args, context=None, **kwargs)¶
Resets
value
andprevious_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 thevalue
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 ininitializers
. Next, it sets thevalue
to a list containing the values of each of the attributes ininitializers
.Often, the only attribute in
stateful_attributes
isprevious_value
and the only attribute ininitializers
isinitializer
, in which case the reset method setsprevious_value
andvalue
to either the value of the argument (if an argument was passed into reset) or the current value ofinitializer
.For specific types of StatefulFunction functions, the reset method may carry out other reinitialization steps.