# Processing Mechanisms¶

## 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). ProcessingMechanisms are always executed before all ModulatoryMechanisms in the Composition to which they belong, so that any modifications made by the ModulatoryMechanism are available to all ProcessingMechanisms in the next TRIAL.

## Creating a ProcessingMechanism¶

A ProcessingMechanism is created by calling its constructor.

Its function 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))


## 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¶

Three main tasks are completed each time a ProcessingMechanism executes:

1. The ProcessingMechanism updates its InputPort(s), and their values are used to assemble variable. Each InputPort value (often there is only one InputPort) is added to an outer array, such that each item of variable corresponds to an InputPort value.

2. The ProcessingMechanism’s variable is handed off as the input to the ProcessingMechanism’s function, and the function executes.

3. The result of the ProcessingMechanism’s function is placed in the Mechanism’s value attribute, and OutputPorts are generated based on value.

A ProcessingMechanism may be executed by calling its execute method directly:

>>> my_simple_processing_mechanism = pnl.ProcessingMechanism()
>>> my_simple_processing_mechanism.execute(1.0)


This option is intended for testing and debugging purposes. More commonly, a mechanism is executed when the Composition to which it belongs is run.

## Class Reference¶

class psyneulink.core.components.mechanisms.processing.processingmechanism.ProcessingMechanism(default_variable=None, size=None, input_ports: <typecheck.framework.optional object at 0x11e768390> = None, output_ports: <typecheck.framework.optional object at 0x11e768470> = None, function=<class 'psyneulink.core.components.functions.transferfunctions.Linear'>, params=None, name=None, prefs: <function is_pref_set at 0x11e2efae8> = 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[dict] – 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 the value of the OutputPort a quantity calculated over the elements of the first item in the outermost dimension (axis 0) of the Mechanisms value`. Subclasses of ProcessingMechanism may extend this list to include additional StandardOutputPorts.
MEAN : float
mean of the elements.
MEDIAN : float
median of the elements.
STANDARD_DEVIATION : float
standard deviation of the elements.
VARIANCE : float
variance of the elements.
MAX_VAL : float
greatest signed value of the elements.
MAX_ABS_VAL : float
greatest absolute value of the elements.
MAX_ONE_HOT : float
element with the greatest signed value is assigned that value, all others are assigned 0.
MAX_ABS_ONE_HOT : float
element with the greatest absolute value is assigned that value, all others are assigned 0.
MAX_INDICATOR : 1d array
element with the greatest signed value is assigned 1, all others are assigned 0.
MAX_ABS_INDICATOR : 1d array
element with the greatest absolute value is assigned 1, all others are assigned 0.
PROB : float
element chosen probabilistically based on softmax distribution is assigned its value, all others are assigned 0.