CombinationFunctions¶
Overview¶
Functions that combine multiple items, yielding a result with the same shape as a single operand
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.
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).

function
(variable=None, execution_id=None, params=None, context=None)¶ Parameters:  variable (list or np.array : default class_defaults.variable) – a list or np.array of numeric values.
 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: Sum or product of arrays in variable – in an array that is one dimension less than
variable
.Return type: array

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).

function
(variable=None, execution_id=None, params=None, context=None)¶ Parameters:  variable (1d or 2d np.array : default class_defaults.variable) – a single numeric array, or multiple arrays to be combined; if it is 2d, all arrays must have the same length.
 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: combined array – the result of linearly combining the arrays in
variable
.Return type: 1d array

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).

function
(variable=None, execution_id=None, params=None, context=None)¶ Parameters:  variable (1d or 2d np.array : default class_defaults.variable) – a single numeric array, or multiple arrays to be combined; if it is 2d, all arrays must have the same length.
 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: combined means – the result of taking the means of each array in
variable
and combining them.Return type: number

class
psyneulink.core.components.functions.combinationfunctions.
PredictionErrorDeltaFunction
(default_variable=None, gamma: <typecheck.framework.optional object at 0x104de5128> = 1.0, params=None, owner=None, prefs: <function is_pref_set at 0x1053079d8> = None)¶ Calculate temporal difference prediction error.
function
returns the prediction error using arrays invariable
:\[\delta(t) = r(t) + \gamma sample(t)  sample(t  1)\]
function
(variable=None, execution_id=None, params=None, context=None)¶ Parameters:  variable (2d np.array : default class_defaults.variable) – a 2d array representing the sample and target values to be used to calculate the temporal difference delta values. Both arrays must have the same length
 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: delta values
Return type: 1d np.array
