TransformFunctions¶
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 Transformfunctions 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 TransformFunction is used as the function of an InputPort or OutputPort).
- class psyneulink.core.components.functions.transformfunctions.Concatenate(default_variable=None, scale=None, offset=None, params=None, owner=None, prefs=None)¶
Concatenates items in outer dimension (axis 0) of
variableinto a single array, optionally scaling and/or adding an offset to the result after concatenating.functionreturns a 1d array with length equal to the sum of the lengths of the items invariable.derivativereturnsscale.- 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(seescalefor details)offset (float) – specifies a value to add to each element of the output of
function(seeoffsetfor 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
PreferenceSetfor the Function (seeprefsfor details).
- default_variable¶
contains template of array(s) to be concatenated.
- Type:
list or np.array
- scale¶
value is applied multiplicatively to each element of the concatenated, before applying the
offset(if it is specified).- Type:
float
- offset¶
value is added to each element of the concatentated array, after
scalehas been applied (if it is specified).- Type:
float
- 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
PreferenceSetfor function; if it is not specified in the prefs argument of the Function’s constructor, a default is assigned usingclassPreferencesdefined in __init__.py (see Preferences for details).- Type:
PreferenceSet or specification dict : Function.classPreferences
- _function(variable=None, context=None, params=None)¶
Use numpy hstack to concatenate items in outer dimension (axis 0) of variable.
- 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:
Concatenated array of items in variable (array) – in an array that is one dimension less than
variable.
- _validate_params(request_set, target_set=None, context=None)¶
Validate scale and offset parameters
Check that SCALE and OFFSET are scalars.
- _validate_variable(variable, context=None)¶
Insure that list or array is 1d and that all elements are numeric
- Parameters:
variable
context
- derivative(input)¶
Derivative of
functionat input.- Parameters:
input (number) – value of the input to the function at which derivative is to be taken.
covariates (2d np.array : default class_defaults.variable[1:]) – the input(s) to the Concatenate function other than the one for which the derivative is being computed; these are ignored and are accepted for consistency with other functions.
- Returns:
Scale of function (number or array)
- class psyneulink.core.components.functions.transformfunctions.CombineMeans(default_variable=None, weights=None, exponents=None, operation=None, scale=None, offset=None, params=None, owner=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.
functiontakes the mean of each array in the outermost dimension (axis 0) ofvariable, and combines them either additively or multiplicatively (as specified byoperation), applyingweightsand/orexponents(if specified) to each mean prior to combining them, and applyingscaleand/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(seeweightsfor 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(seeexponentsfor details)operation (SUM or PRODUCT : default SUM) – specifies whether the
functiontakes 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(seescalefor details)offset (float or np.ndarray : default None) – specifies a value to add to the result of
function(seeoffsetfor 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
PreferenceSetfor the Function (seeprefsfor details).
- variable¶
contains the arrays to be combined by function. If it is 1d, the array is simply linearly transformed by and
scaleandoffset. If it is 2d, the arrays (all of which must be of equal length) are weighted and/or exponentiated as specified byweightsand/orexponentsand then combined as specified byoperation.- Type:
1d or 2d np.array
- weights¶
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. Allweightsare applied before any exponentiation (if it is specified).- Type:
1d or 2d np.array : default NOne
- exponents¶
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).- Type:
1d or 2d np.array : default None
- operation¶
determines whether the
functiontakes the elementwise (Hadamard) sum or product of the arrays invariable.- Type:
SUM or PRODUCT : default SUM
- scale¶
value is applied multiplicatively to each element of the array after applying the
operation(seescalefor details); this done before applying theoffset(if it is specified).- Type:
float or np.ndarray : default None
- offset¶
value is added to each element of the array after applying the
operationandscale(if it is specified).- Type:
float or np.ndarray : default None
- 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
PreferenceSetfor function; if it is not specified in the prefs argument of the Function’s constructor, a default is assigned usingclassPreferencesdefined in __init__.py (see Preferences for details).- Type:
PreferenceSet or specification dict : Function.classPreferences
- _function(variable=None, context=None, params=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 (number) – the result of taking the means of each array in
variableand combining them.
- _validate_params(request_set, target_set=None, context=None)¶
Validate weights, exponents, scale and offset parameters
Check that WEIGHTS and EXPONENTS are lists or np.arrays of numbers with length equal to variable Check that SCALE and OFFSET are either scalars or np.arrays of numbers with length and shape equal to variable
- Note: the checks of compatibility with variable are only performed for validation calls during execution
(i.e., from check_args(), since during initialization or COMMAND_LINE assignment, a parameter may be re-assigned before variable assigned during is known
- _validate_variable(variable, context=None)¶
Insure that all items of variable are numeric
- class psyneulink.core.components.functions.transformfunctions.Rearrange(default_variable=None, scale=None, offset=None, arrangement=None, 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 ofvariablereferenced in the specification are included in the result; if arrangement is not specified, all of the items ofvariableare concatenated into a single 1d array (i.e., it functions identically toConcatenate).functionreturns a 2d array with the items ofvariablerearranged (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
variableand/or ones to concatenate. (see above for details).scale (float) – specifies a value by which to multiply each element of the output of
function(seescalefor details).offset (float) – specifies a value to add to each element of the output of
function(seeoffsetfor 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
PreferenceSetfor the Function (seeprefsfor details).
- default_variable¶
contains template of array(s) to be concatenated.
- Type:
list or np.array
- arrangement¶
determines ordering of items in
variableand/or ones to concatenate (see above for additional details).- Type:
list of one or more tuples
- scale¶
value is applied multiplicatively to each element of the concatenated, before applying the
offset(if it is specified).- Type:
float
- offset¶
value is added to each element of the concatentated array, after
scalehas been applied (if it is specified).- Type:
float
- 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
PreferenceSetfor function; if it is not specified in the prefs argument of the Function’s constructor, a default is assigned usingclassPreferencesdefined in __init__.py (see Preferences for details).- Type:
PreferenceSet or specification dict : Function.classPreferences
- _function(variable=None, context=None, params=None)¶
Rearrange items in outer dimension (axis 0) of variable according to
arrangement.- 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:
Rearranged items of outer dimension (axis 0) of **variable** (array) – in a 2d array.
- _instantiate_attributes_before_function(function=None, context=None)¶
Insure all items of arrangement are tuples and compatibility with default_variable
If arrangement is specified, convert all items to tuples If default_variable is NOT specified, assign with length in outer dimension = max index in arragnement If default_variable IS _user_specified, compatiblility with arrangement is checked in _validate_params
- _validate_params(request_set, target_set=None, context=None)¶
Validate arrangement, scale and offset parameters
- _validate_variable(variable, context=None)¶
Insure that all elements are numeric and that list or array is at least 2d
- class psyneulink.core.components.functions.transformfunctions.Reduce(weights=None, exponents=None, default_variable=None, operation=None, scale=None, offset=None, 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.
functionreturns 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(seeweightsfor 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(seeexponentsfor details)operation (SUM or PRODUCT : default SUM) – specifies whether to sum or multiply the elements in
variableoffunction.scale (float) – specifies a value by which to multiply each element of the output of
function(seescalefor details)offset (float) – specifies a value to add to each element of the output of
function(seeoffsetfor 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
PreferenceSetfor the Function (seeprefsfor details).
- default_variable¶
contains array(s) to be reduced.
- Type:
list or np.array
- operation¶
determines whether elements of each array in
variableoffunctionare summmed or multiplied.- Type:
SUM or PRODUCT
- scale¶
value is applied multiplicatively to each element of the array after applying the
operation(seescalefor details); this done before applying theoffset(if it is specified).- Type:
float
- offset¶
value is added to each element of the array after applying the
operationandscale(if it is specified).- Type:
float
- 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
PreferenceSetfor function; if it is not specified in the prefs argument of the Function’s constructor, a default is assigned usingclassPreferencesdefined in __init__.py (see Preferences for details).- Type:
PreferenceSet or specification dict : Function.classPreferences
- _function(variable=None, context=None, params=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 (array) – in an array that is one dimension less than
variable.
- _validate_params(request_set, target_set=None, context=None)¶
Validate weghts, exponents, scale and offset parameters
Check that WEIGHTS and EXPONENTS are lists or np.arrays of numbers with length equal to variable. Check that SCALE and OFFSET are scalars.
- Note: the checks of compatibility with variable are only performed for validation calls during execution
(i.e., from check_args(), since during initialization or COMMAND_LINE assignment, a parameter may be re-assigned before variable assigned during is known
- _validate_variable(variable, context=None)¶
Insure that list or array is 1d and that all elements are numeric
- Parameters:
variable
context
- class psyneulink.core.components.functions.transformfunctions.LinearCombination(default_variable=None, weights=None, exponents=None, operation=None, scale=None, offset=None, params=None, owner=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.
functioncombines the arrays in the outermost dimension (axis 0) ofvariableeither additively or multiplicatively (as specified byoperation), applyingweightsand/orexponents(if specified) to each array prior to combining them, and applyingscaleand/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(seeweightsfor 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(seeexponentsfor details of how exponents are applied).operation (SUM, PRODUCT or CROSS_ENTROPY : default SUM) – specifies whether the
functiontakes the elementwise (Hadamarad) sum, product or cross entropy 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(seescalefor details)offset (float or np.ndarray : default None) – specifies a value to add to each element of the result of
function(seeoffsetfor 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
PreferenceSetfor the Function (seeprefsfor details).
- variable¶
contains the arrays to be combined by function. If it is 1d, the array is simply linearly transformed by and
scaleandoffset. If it is 2d, the arrays (all of which must be of equal length) are weighted and/or exponentiated as specified byweightsand/orexponentsand then combined as specified byoperation.- Type:
1d or 2d np.array
- weights¶
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. Allweightsare applied before any exponentiation (if it is specified).- Type:
scalar or 1d or 2d np.array
- exponents¶
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).- Type:
scalar or 1d or 2d np.array
- operation¶
determines whether the
functiontakes the elementwise (Hadamard) sum, product, or cross entropy of the arrays invariable.- Type:
SUM or PRODUCT
- scale¶
value is applied multiplicatively to each element of the array after applying the
operation(seescalefor details); this done before applying theoffset(if it is specified).- Type:
float or np.ndarray
- offset¶
value is added to each element of the array after applying the
operationandscale(if it is specified).- Type:
float or np.ndarray
- 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
PreferenceSetfor function; if it is not specified in the prefs argument of the Function’s constructor, a default is assigned usingclassPreferencesdefined in __init__.py (see Preferences for details).- Type:
PreferenceSet or specification dict : Function.classPreferences
- _function(variable=None, context=None, params=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 (1d array) – the result of linearly combining the arrays in
variable.
- _validate_params(request_set, target_set=None, context=None)¶
Validate weghts, exponents, scale and offset parameters
Check that WEIGHTS and EXPONENTS are lists or np.arrays of numbers with length equal to variable Check that SCALE and OFFSET are either scalars or np.arrays of numbers with length and shape equal to variable
- Note: the checks of compatibility with variable are only performed for validation calls during execution
(i.e., from check_args(), since during initialization or COMMAND_LINE assignment, a parameter may be re-assigned before variable assigned during is known
- _validate_variable(variable, context=None)¶
Insure that all items of list or np.array in variable are of the same length
- Parameters:
variable
context
- derivative(input)¶
Derivative of
functionat input.- Parameters:
output (1d np.array : default class_defaults.variable[0]) –
value of the input to the Linear transform at which derivative is to be taken. a single numeric array or multiple arrays being combined, and at which derivative is to be taken.
output arg is used for consistency with other derivatives used by BackPropagation, and is ignored.
covariates (2d np.array : default class_defaults.variable[1:]) – the input(s) to the LinearCombination function other than the one for which the derivative is being computed; these are used to calculate the Jacobian of the LinearCombination function.
- Returns:
Scale (number (if input is 1d) or array (if input is 2d))
- class psyneulink.core.components.functions.transformfunctions.MatrixTransform(default_variable=None, matrix=None, operation=None, normalize=None, params=None, owner=None, prefs=None)¶
Matrix transform of
variable.operation = DOT_PRODUCT:
Returns the dot (inner) product of
variableandmatrix:\[{variable} \bullet |matrix|\]If normalize =True, the result is normalized by the product of the norms of the variable and matrix:
\[\frac{variable \bullet matrix}{\|variable\| \cdot \|matrix\|}\]Note
For normalize =True, the result is the same as the cosine of the angle between pairs of vectors.
operation = L0:
Returns the absolute value of the difference between
variableandmatrix:\[|variable - matrix|\]If normalize =True, the result is normalized by the norm of the sum of differences between the variable and matrix, which is then subtracted from 1:
\[1 - \frac{|variable - matrix|}{\|variable - matrix\|}\]Note
For normalize =True, the result has the same effect as the normalized DOT_PRODUCT operation, with more similar pairs of vectors producing larger values (closer to 1).
Warning
For normalize =False, the result is smaller (closer to 0) for more similar pairs of vectors, which is opposite the effect of the DOT_PRODUCT and normalized L0 operations. If the desired result is that more similar pairs of vectors produce larger values, set normalize =True or use the DOT_PRODUCT operation.
- Parameters:
variable (list or 1d array : default class_defaults.variable) – specifies a template for the value to be transformed; length must equal the number of rows of
matrix.matrix (number, list, 1d or 2d np.ndarray, function, or matrix keyword : default IDENTITY_MATRIX) –
specifies matrix used to transform
variable(seematrixfor specification details).When MatrixTransform is the
functionof a projection:When MatrixTransform is instantiated on its own, or as the function of a Mechanism or Port:
operation (DOT_PRODUCT or L0 : default DOT_PRODUCT) – specifies whether to take the dot product or difference of
variableandmatrix.normalize (bool : default False) – specifies whether to normalize the result of
functionby dividing it by the norm ofvariablex the norm ofmatrix; this cannot be used ifvariableis a scalar (i.e., has only one element), and operation is set to L0 (since it is not needed, and can produce a divide by zero error).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
PreferenceSetfor the Function (seeprefsfor details).
- variable¶
contains value to be transformed.
- Type:
1d array
- matrix¶
matrix used to transform
variable. Can be specified as any of the following:number - used as the filler value for all elements of the
matrix(call to np.fill);list of arrays, 2d array - assigned as the value of
matrix;matrix keyword - see
MatrixKeywordsfor list of options.
Rows correspond to elements of the input array (outer index), and columns correspond to elements of the output array (inner index).
- Type:
2d array
- operation¶
determines whether dot product or difference of
variableandmatrixis taken. If the length ofvariableis greater than 1 and L0 is specified, thevariablearray is subtracted from each array ofmatrixand the resulting array is summed, to produce the corresponding element of the array returned by the function.- Type:
DOT_PRODUCT or L0 : default DOT_PRODUCT
- normalize¶
determines whether the result of
functionis normalized, by dividing it by the norm ofvariablex the norm ofmatrix.- Type:
bool
- 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
PreferenceSetfor function; if it is not specified in the prefs argument of the Function’s constructor, a default is assigned usingclassPreferencesdefined in __init__.py (seePreferenceSetfor details).- Type:
PreferenceSet or specification dict : Function.classPreferences
- _function(variable=None, context=None, params=None)¶
- Parameters:
variable (list or 1d array) – array to be transformed; length must equal the number of rows of
matrix.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:
dot product of or difference between variable and matrix (1d array) – length of the array returned equals the number of columns of
matrix.
- _model_spec_generic_type_name = 'onnx::MatMul'¶
string describing this class’s generic type in universal model specification, if it exists and is different than the class name
- _validate_params(request_set, target_set=None, context=None)¶
Validate params and assign to targets
This overrides the class method, to perform more detailed type checking (see explanation in class method). Note: this method (or the class version) is called only if the parameter_validation attribute is
True- Parameters:
request_set – (dict) - params to be validated
target_set – (dict) - destination of validated params
context – (str)
- Return none:
- instantiate_matrix(specification, context=None)¶
Implements matrix indicated by specification
Specification is derived from MATRIX param (passed to self.__init__ or self._function)
- Specification (validated in _validate_params):
single number (used to fill self.matrix)
matrix keyword (see get_matrix)
2D list or np.ndarray of numbers
- Return matrix:
(2D list)
- class psyneulink.core.components.functions.transformfunctions.PredictionErrorDeltaFunction(default_variable=None, gamma=None, params=None, owner=None, prefs=None)¶
Calculate temporal difference prediction error.
functionreturns the prediction error using arrays invariable:\[\delta(t) = r(t) + \gamma sample(t) - sample(t - 1)\]- _function(variable=None, context=None, params=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
- _validate_params(request_set, target_set=None, context=None)¶
Checks that WEIGHTS is a list or np.array of numbers with length equal to variable.
Note: the checks of compatibility with variable are only performed for validation calls during execution (i.e. from
check_args()), since during initialization or COMMAND_LINE assignment, a parameter may be re-assigned before variable assigned during is known- Parameters:
request_set
target_set
context
- Return type:
None
- _validate_variable(variable, context=None)¶
Insure that all items of variable are numeric
- Parameters:
variable
context
- Return type:
variable if all items are numeric