ProcessingMechanism¶
Contents¶
Overview¶
A ProcessingMechanism is a type of Mechanism that transforms its input in some way. A ProcessingMechanism always receives its input either from another Mechanism, or from the input to a Composition when it is executed. Similarly, its output is generally conveyed to another Mechanism or used as the output for a Composition.
The ProcessingMechanism is the simplest mechanism in PsyNeuLink. It does not have any extra arguments or specialized
validation. Almost any PsyNeuLink Function, including the UserDefinedFunction, may be the function of a
ProcessingMechanism. Currently, the only exception is BackPropagation
. Subtypes of ProcessingMechanism have more
specialized features, and often have restrictions on which Functions are allowed.
The output of a ProcessingMechanism may also be used by a ModulatoryMechanism to modify the parameters of other components (or its own parameters), as in the case of an Objective Mechanism that is specialized for this purpose.
Creating a ProcessingMechanism¶
A ProcessingMechanism is created by calling its constructor. By default, a ProcessingMechanism is assigned:
a single InputPort, that receives (and sums the
value
) of any Projections to it;a single OutputPort, the
value
of which is the result of the linear transformation of its input (which, if no parameters are assigned to it function, is the same as its input).
However, it can be configured otherwise, for various forms of processing, as described below.
Configuring a ProcessingMechanism¶
As with any Mechanism, the number of InputPorts can be specified using the input_ports, default_variable or input_shapes arguments of the constructor (see InputPorts), and OutputPorts can be specified using the output_ports argument (see OutputPorts). These can be used to configure processing in a variety of ways. Some common ones are described below (also see Examples).
Note
All of the configurations below assume that:
the ProcessingMechanism’s
function
is aTransferFunction
any specified InputPorts and/or OutputPorts use their default
function
,the
variable
of OutputPorts is not specified.If any of these is not the case, then the results may differ from those described below.
Parallel Processing¶
Multiple InputPorts and either no or an equal number of OutputPorts: one OutputPort is created for (and given the same name as) each InputPort; the
value
of each is assigned the result of the transformation of thevalue
of its corresponding InputPort. This exploits the property of a TransferFunction, which preserves the shape of its input, implementing parallel processing streams in which the samefunction
is used to process the input to each InputPort independently of the others (including during learning)
Divergent Processing¶
Custom Processing¶
Multiple but an unequal number of InputPorts and OutputPorts:
if there are fewer OutputPorts than InputPorts, each OutputPort is assigned a name and
value
corresponding to the name and result of processing of the input to the corresponding InputPort. In this case, the inputs to the additional InputPorts are ignored; however, this can be modified by explicitly specifying thevariable
for the OutputPort(s) (see OutputPort variable).if there are more OutputPorts than Inputports, then all are assigned a
default name
, and avalue
that is the result of processing the input to the first (primary) InputPort`; this can be modified by explicitly specifying the variable for the OutputPort(s) (see OutputPort variable).
Warning
An unequal number of InputPorts and OutputPorts is not supported for learning
Structure¶
A ProcessingMechanism has the same structure as a Mechanism, with the addition of several
StandardOutputPorts to its standard_output_ports
attribute.
See documentation for individual subtypes of ProcessingMechanism for more specific information about their structure.
Execution¶
The execution of a ProcessingMechanism follows the same sequence of actions as a standard Mechanism (see Execution).
See Parallel Processing above for a description of how processing is affect by the number of InputPorts and OutputPorts.
Examples
The function
of a ProcessingMechanism is specified in the function argument,
which may be the name of a Function class:
>>> import psyneulink as pnl
>>> my_linear_processing_mechanism = pnl.ProcessingMechanism(function=pnl.Linear)
in which case all of the function’s parameters will be set to their default values.
Alternatively, the function argument may be a call to a Function constructor, in which case values may be specified for the Function’s parameters:
>>> my_logistic_processing_mechanism = pnl.ProcessingMechanism(function=pnl.Logistic(gain=1.0, bias=-4))
Class Reference¶
- class psyneulink.core.components.mechanisms.processing.processingmechanism.ProcessingMechanism(default_variable=None, input_shapes=None, input_ports=None, output_ports=None, function=None, params=None, name=None, prefs=None, **kwargs)¶
Implements instance of ProcessingMechanism_Base subclass of Mechanism. See Mechanism and subclasses of ProcessingMechanism for arguments and additional attributes.
- standard_output_ports¶
list of the dictionary specifications for StandardOutputPorts that can be assigned as OutputPorts, in addition to the
standard_output_ports
of a Mechanism; each assigns as thevalue
of the OutputPort a quantity calculated over the elements of the first item in the outermost dimension (axis 0) of the Mechanism`svalue
. Subclasses of ProcessingMechanism may extend this list to include additional StandardOutputPorts.- MEANfloat
mean of the elements.
- MEDIANfloat
median of the elements.
- STANDARD_DEVIATIONfloat
standard deviation of the elements.
- VARIANCEfloat
variance of the elements.
- MAX_VALfloat
greatest signed value of the elements.
- MAX_ABS_VALfloat
greatest absolute value of the elements.
- MAX_ONE_HOTfloat
element with the greatest signed value is assigned that value, all others are assigned 0.
- MAX_ABS_ONE_HOTfloat
element with the greatest absolute value is assigned that value, all others are assigned 0.
- MAX_INDICATOR1d array
element with the greatest signed value is assigned 1, all others are assigned 0.
- MAX_ABS_INDICATOR1d array
element with the greatest absolute value is assigned 1, all others are assigned 0.
- PROBfloat
element chosen probabilistically based on softmax distribution is assigned its value, all others are assigned 0.
- Type
list[dict]
- _instantiate_output_ports(context=None)¶
If no OutputPorts have been specified, len(variable) >1 and function is TransferFunction, create an OutputPort for each item of variable
- exception psyneulink.core.components.mechanisms.processing.processingmechanism.ProcessingMechanismError(message, component=None)¶