CombinationFunctions¶
Overview¶
Functions that combine multiple items with the same shape, yielding a result with a single item that has the same shape as the individual items.
All CombinationFunctions must have two attributes  multiplicative_param and additive_param  each of which is assigned the name of one of the function’s parameters; this is for use by ModulatoryProjections (and, in particular, GatingProjections, when the CombinationFunction is used as the function of an InputState or OutputState).

class
psyneulink.core.components.functions.combinationfunctions.
Concatenate
(default_variable=class_defaults.variable, scale=1.0, offset=0.0, params=None, owner=None, prefs=None)¶ Concatenates items in outer dimension (axis 0) of of
variable
into a single array, optionally scaling and/or adding an offset to the result after concatenating.function
returns a 1d array with lenght equal to the sum of the lengths of the items invariable
.Parameters:  default_variable (list or np.array : default class_defaults.variable) – specifies a template for the value to be transformed and its default value; all entries must be numeric.
 scale (float) – specifies a value by which to multiply each element of the output of
function
(seescale
for details)  offset (float) – specifies a value to add to each element of the output of
function
(seeoffset
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).

default_variable
¶ list or np.array – contains template of array(s) to be concatenated.

scale
¶ float – value is applied multiplicatively to each element of the concatenated, before applying the
offset
(if it is specified).

offset
¶ float – value is added to each element of the concatentated array, after
scale
has been applied (if it is specified).

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 usingclassPreferences
defined in __init__.py (see PreferenceSet for details).

class
psyneulink.core.components.functions.combinationfunctions.
Rearrange
(default_variable=class_defaults.variable, arrangement=None, scale=1.0, offset=0.0, params=None, owner=None, prefs=None)¶ Rearranges items in outer dimension (axis 0) of
variable
, as specified by arrangement, optionally scaling and/or adding an offset to the result after concatenating.The arrangement argument specifies how to rearrange the items of
variable
, possibly concatenating subsets of them into single 1d arrays. The specification must be an integer, a tuple of integers, or a list containing either or both. Each integer must be an index of an item in the outer dimension (axis 0) ofvariable
. Items referenced in a tuple are concatenated in the order specified into a single 1d array, and that 1d array is included in the resulting 2d array in the order it appears in arrangement. If arrangement is specified, then only the items ofvariable
referenced in the specification are included in the result; if arrangement is not specified, all of the items ofvariable
are concatenated into a single 1d array (i.e., it functions identically toConcatenate
).function
returns a 2d array with the items ofvariable
rearranged (and possibly concatenated) as specified by arrangement.Examples
>>> r = Rearrange(arrangement=[(1,2),(0)]) >>> print(r(np.array([[0,0],[1,1],[2,2]]))) [array([1., 1., 2., 2.]) array([0., 0.])]
>>> r = Rearrange() >>> print(r(np.array([[0,0],[1,1],[2,2]]))) [0. 0. 1. 1. 2. 2.]
Parameters:  default_variable (list or np.array : default class_defaults.variable) – specifies a template for the value to be transformed and its default value; all entries must be numeric.
 arrangement (int, tuple, or list : default None) – specifies ordering of items in
variable
and/or ones to concatenate. (see above for details).  scale (float) – specifies a value by which to multiply each element of the output of
function
(seescale
for details).  offset (float) – specifies a value to add to each element of the output of
function
(seeoffset
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).

default_variable
¶ list or np.array – contains template of array(s) to be concatenated.

arrangement
¶ list of one or more tuples – determines ordering of items in
variable
and/or ones to concatenate (see above for additional details).

scale
¶ float – value is applied multiplicatively to each element of the concatenated, before applying the
offset
(if it is specified).

offset
¶ float – value is added to each element of the concatentated array, after
scale
has been applied (if it is specified).

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 usingclassPreferences
defined in __init__.py (see PreferenceSet for details).

class
psyneulink.core.components.functions.combinationfunctions.
Reduce
(default_variable=class_defaults.variable, weights=None, exponents=None, operation=SUM, scale=1.0, offset=0.0, params=None, owner=None, prefs=None)¶ Combines values in each of one or more arrays into a single value for each array, with optional weighting and/or exponentiation of each item within an array prior to combining, and scaling and/or offset of result after combining.
function
returns an array of scalar values, one for each array invariable
.Parameters:  default_variable (list or np.array : default class_defaults.variable) – specifies a template for the value to be transformed and its default value; all entries must be numeric.
 weights (1d or 2d np.array : default None) – specifies values used to multiply the elements of each array in
variable
. If it is 1d, its length must equal the number of items invariable
; if it is 2d, the length of each item must be the same as those invariable
, and there must be the same number of items as there are invariable
(seeweights
for details)  exponents (1d or 2d np.array : default None) – specifies values used to exponentiate the elements of each array in
variable
. If it is 1d, its length must equal the number of items invariable
; if it is 2d, the length of each item must be the same as those invariable
, and there must be the same number of items as there are invariable
(seeexponents
for details)  operation (SUM or PRODUCT : default SUM) – specifies whether to sum or multiply the elements in
variable
offunction
.  scale (float) – specifies a value by which to multiply each element of the output of
function
(seescale
for details)  offset (float) – specifies a value to add to each element of the output of
function
(seeoffset
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).

default_variable
¶ list or np.array – contains array(s) to be reduced.

operation
¶ SUM or PRODUCT – determines whether elements of each array in
variable
offunction
are summmed or multiplied.

scale
¶ float – value is applied multiplicatively to each element of the array after applying the
operation
(seescale
for details); this done before applying theoffset
(if it is specified).

offset
¶ float – value is added to each element of the array after applying the
operation
andscale
(if it is specified).

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 usingclassPreferences
defined in __init__.py (see PreferenceSet for details).

class
psyneulink.core.components.functions.combinationfunctions.
LinearCombination
(default_variable, weights=None, exponents=None, operation=SUM, scale=None, offset=None, params=None, owner=None, name=None, prefs=None)¶ Linearly combine arrays of values, optionally weighting and/or exponentiating each array prior to combining, and scaling and/or offsetting after combining.
function
combines the arrays in the outermost dimension (axis 0) ofvariable
either additively or multiplicatively (as specified byoperation
), applyingweights
and/orexponents
(if specified) to each array prior to combining them, and applyingscale
and/oroffeset
(if specified) to the result after combining, and returns an array of the same length as the operand arrays.Parameters:  variable (1d or 2d np.array : default class_defaults.variable) – specifies a template for the arrays to be combined. If it is 2d, all items must have the same length.
 weights (scalar or 1d or 2d np.array : default None) – specifies values used to multiply the elements of each array in variable.
If it is 1d, its length must equal the number of items in
variable
; if it is 2d, the length of each item must be the same as those invariable
, and there must be the same number of items as there are invariable
(seeweights
for details of how weights are applied).  exponents (scalar or 1d or 2d np.array : default None) – specifies values used to exponentiate the elements of each array in
variable
. If it is 1d, its length must equal the number of items invariable
; if it is 2d, the length of each item must be the same as those invariable
, and there must be the same number of items as there are invariable
(seeexponents
for details of how exponents are applied).  operation (SUM or PRODUCT : default SUM) – specifies whether the
function
takes the elementwise (Hadamarad) sum or product of the arrays invariable
.  scale (float or np.ndarray : default None) – specifies a value by which to multiply each element of the result of
function
(seescale
for details)  offset (float or np.ndarray : default None) – specifies a value to add to each element of the result of
function
(seeoffset
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
¶ 1d or 2d np.array – contains the arrays to be combined by function. If it is 1d, the array is simply linearly transformed by and
scale
andoffset
. If it is 2d, the arrays (all of which must be of equal length) are weighted and/or exponentiated as specified byweights
and/orexponents
and then combined as specified byoperation
.

weights
¶ scalar or 1d or 2d np.array – if it is a scalar, the value is used to multiply all elements of all arrays in
variable
; if it is a 1d array, each element is used to multiply all elements in the corresponding array ofvariable
; if it is a 2d array, then each array is multiplied elementwise (i.e., the Hadamard Product is taken) with the corresponding array ofvariable
. Allweights
are applied before any exponentiation (if it is specified).

exponents
¶ scalar or 1d or 2d np.array – if it is a scalar, the value is used to exponentiate all elements of all arrays in
variable
; if it is a 1d array, each element is used to exponentiate the elements of the corresponding array ofvariable
; if it is a 2d array, the element of each array is used to exponentiate the corresponding element of the corresponding array ofvariable
. In either case, all exponents are applied after application of theweights
(if any are specified).

operation
¶ SUM or PRODUCT – determines whether the
function
takes the elementwise (Hadamard) sum or product of the arrays invariable
.

scale
¶ float or np.ndarray – value is applied multiplicatively to each element of the array after applying the
operation
(seescale
for details); this done before applying theoffset
(if it is specified).

offset
¶ float or np.ndarray – value is added to each element of the array after applying the
operation
andscale
(if it is specified).

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 usingclassPreferences
defined in __init__.py (see PreferenceSet for details).

class
psyneulink.core.components.functions.combinationfunctions.
CombineMeans
(default_variable, weights=None, exponents=None, operation=SUM, scale=None, offset=None, params=None, owner=None, name=None, prefs=None)¶ Calculate and combine mean(s) for arrays of values, optionally weighting and/or exponentiating each mean prior to combining, and scaling and/or offsetting after combining.
function
takes the mean of each array in the outermost dimension (axis 0) ofvariable
, and combines them either additively or multiplicatively (as specified byoperation
), applyingweights
and/orexponents
(if specified) to each mean prior to combining them, and applyingscale
and/oroffeset
(if specified) to the result after combining, and returns a scalar value.Parameters:  variable (1d or 2d np.array : default class_defaults.variable) – specifies a template for the arrays to be combined. If it is 2d, all items must have the same length.
 weights (1d or 2d np.array : default None) – specifies values used to multiply the elements of each array in
variable
. If it is 1d, its length must equal the number of items invariable
; if it is 2d, the length of each item must be the same as those invariable
, and there must be the same number of items as there are invariable
(seeweights
for details)  exponents (1d or 2d np.array : default None) – specifies values used to exponentiate the elements of each array in
variable
. If it is 1d, its length must equal the number of items invariable
; if it is 2d, the length of each item must be the same as those invariable
, and there must be the same number of items as there are invariable
(seeexponents
for details)  operation (SUM or PRODUCT : default SUM) – specifies whether the
function
takes the sum or product of the means of the arrays invariable
.  scale (float or np.ndarray : default None) – specifies a value by which to multiply the result of
function
(seescale
for details)  offset (float or np.ndarray : default None) – specifies a value to add to the result of
function
(seeoffset
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
¶ 1d or 2d np.array – contains the arrays to be combined by function. If it is 1d, the array is simply linearly transformed by and
scale
andoffset
. If it is 2d, the arrays (all of which must be of equal length) are weighted and/or exponentiated as specified byweights
and/orexponents
and then combined as specified byoperation
.

weights
¶ 1d or 2d np.array : default NOne – if it is 1d, each element is used to multiply all elements in the corresponding array of
variable
; if it is 2d, then each array is multiplied elementwise (i.e., the Hadamard Product is taken) with the corresponding array ofvariable
. Allweights
are applied before any exponentiation (if it is specified).

exponents
¶ 1d or 2d np.array : default None – if it is 1d, each element is used to exponentiate the elements of the corresponding array of
variable
; if it is 2d, the element of each array is used to exponentiate the corresponding element of the corresponding array ofvariable
. In either case, exponentiating is applied after application of theweights
(if any are specified).

operation
¶ SUM or PRODUCT : default SUM – determines whether the
function
takes the elementwise (Hadamard) sum or product of the arrays invariable
.

scale
¶ float or np.ndarray : default None – value is applied multiplicatively to each element of the array after applying the
operation
(seescale
for details); this done before applying theoffset
(if it is specified).

offset
¶ float or np.ndarray : default None – value is added to each element of the array after applying the
operation
andscale
(if it is specified).

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 usingclassPreferences
defined in __init__.py (see PreferenceSet for details).

class
psyneulink.core.components.functions.combinationfunctions.
PredictionErrorDeltaFunction
(default_variable=None, gamma: <typecheck.framework.optional object at 0x11f567160> = 1.0, params=None, owner=None, prefs: <function is_pref_set at 0x11d33d8c8> = None)¶ Calculate temporal difference prediction error.
function
returns the prediction error using arrays invariable
:\[\delta(t) = r(t) + \gamma sample(t)  sample(t  1)\]