# LearningProjection¶

## Overview¶

A LearningProjection is a type of ModulatoryProjection that projects from a Learning Mechanism to the MATRIX ParameterState of a MappingProjection. It takes the value of a LearningSignal of a Learning Mechanism, and uses it to modify the value of the matrix parameter of that MappingProjection. All of the LearningProjections in a System, along with its other learning components, can be displayed using the System’s show_graph method with its show_learning argument assigned as True.

## Creating a LearningProjection¶

A LearningProjection can be created using any of the standard ways to create a Projection, or by including it in a tuple that specifies the matrix parameter of a MappingProjection. LearningProjections are also created automatically, along with the other Components required for learning, when learning is specified for a Process or a System.

If a LearningProjection is created explicitly (using its constructor), and its receiver argument is not specified, its initialization is deferred. If it is included in the matrix specification for a MappingProjection, the MATRIX ParameterState for the MappingProjection will be assigned as the LearningProjection’s receiver. If its sender argument is not specified, its assignment depends on the receiver. If the receiver belongs to a MappingProjection that projects between two Mechanisms that are both in the same Process or System, then the LearningProjection’s sender is assigned to a LearningSignal of the Learning Mechanism for the MappingProjection. If there is none, it is created along with any other components needed to implement learning for the MappingProjection (see Learning Configurations). Otherwise, the LearningProjection’s initialization is deferred.

### Deferred Initialization¶

When a LearningProjection is created, its full initialization is deferred until its sender and receiver have been fully specified. This allows a LearningProjection to be created before its sender and/or receiver have been created (e.g., before them in a script), by calling its constructor without specifying its sender or receiver arguments. However, for the LearningProjection to be operational, initialization must be completed by calling its deferred_init method. This is not necessary if the LearningProjection is included in a tuple specification for the matrix parameter of a MappingProjection, in which case deferred initialization is completed automatically when the Learning Mechanism associated with that MappingProjection is created for the Process or System to which it belongs (see Creating a LearningMechanism).

## Structure¶

### Sender¶

The sender of a LearningProjection is a LearningSignal of a Learning Mechanism, The value of the sender – a matrix of weight changes – is used by the LearningProjection as its variable; this is also assigned to its learning_signal attribute, and serves as the input to the LearningProjection’s function.

### Function and learning_rate¶

The default function of a LearningProjection is an identity function (Linear with slope=1 and intercept=0). However, its result can be modified by the LearningProjection’s learning_rate parameter (specified in the learning_rate argument of its constructor). If specified, it is applied multiplicatively to the output of the LearningProjection’s function, and the result is assigned to the LearningProjection’s value and weight_change_matrix attributes. Thus, the LearningProjection’s learning_rate parameter can be used to modulate the the learning_signal it receives, in addition to (and on top of) the effects of the learning_rate for the Learning Mechanism from which it receives the learning_signal. Specification of the learning_rate for a LearningProjection supersedes any specification(s) of the learning_rate for any Process and/or System to which the Projection belongs (see learning_rate for additional details). However, its learning_rate can be specified by the LearningSignal that is its sender; that specification takes precedence over the direct specification of the learning_rate for the LearningProjection (i.e., in the learning_rate argument of its constructor, or by direct assignment of a value to the attribute). If a learning_rate is not specified for the LearningProjection, then the result of its function is assigned unmodified as the LearningProjection’s value (and weight_change_matrix attributes.

### Weight and Exponent¶

Every LearningProjection has a weight and exponent attribute that are applied to its value before it is combined with other LearningProjections that modify the ParameterState for the matrix parameter of the MappingProjection to which they project (see description under Projection for additional details).

Note

The weight and exponent attributes of a LearningProjection are not commonly used, and are implemented largely for generality and compatibility with other types of Projections. They are distinct from, and are applied in addition to the LearningProjection’s learning_rate attribute. As noted under Projection, they are not normalized and thus their effects aggregate if a ParameterState receives one or more LearningProjections with non-default values of their weight and exponent attributes.

The receiver of a LearningProject is the MATRIX ParameterState of a MappingProjection, that uses the weight_change_matrix provided by the LearningProjection to modify the matrix parameter of the MappingProjection being learned.

## Execution¶

A LearningProjection cannot be executed directly. It is executed when the MATRIX ParameterState to which it projects is updated. This occurs when the learned_projection (the MappingProjection to which the MATRIX ParameterState belongs) is updated. Note that these events occur only when the ProcessingMechanism that receives the learned_projection is executed (see Lazy Evaluation for an explanation of “lazy” updating). When the LearningProjection is executed, its function gets the learning_signal from its sender and conveys that to its receiver, possibly modified by a learning_rate if that is specified for it or its sender (see above).

Note

The changes to the matrix parameter of a MappingProjection in response to the execution of a LearningProjection are not applied until the Mechanism that receives MappingProjection are next executed; see Lazy Evaluation for an explanation of “lazy” updating).

## Class Reference¶

psyneulink.components.projections.modulatory.learningprojection.DefaultTrainingMechanism

alias of ObjectiveMechanism

class psyneulink.components.projections.modulatory.learningprojection.LearningProjection(sender=None, receiver=None, error_function, learning_function, learning_rate=None, weight=None, exponent=None, params=None, name=None, prefs=None)

Subclass of ModulatoryProjection that modulates the value of a ParameterState for the matrix parameter of a MappingProjection.

Parameters: sender (Optional[LearningMechanism or LearningSignal]) – specifies the source of the learning_signal for the LearningProjection; if it is not specified, and cannot be inferred from context, initialization is deferred. receiver (Optional[MappingProjection or ParameterState for matrix parameter of one]) – specifies the MATRIX ParameterState (or the MappingProjection that owns it) for the matrix of the learned_projection to be modified by the LearningProjection; if it is not specified, and cannot be inferred from context, initialization is deferred. function (TransferFunction : default Linear(slope=1, intercept=0)) – specifies the function used to convert the learning_signal to the weight_change_matrix, prior to applying the learning_rate. error_function (Optional[Function or function] : default LinearCombination(weights=[[-1], [1]])) – specifies a function to be used by the TARGET Mechanism to compute the error used for learning. Since the TARGET Mechanism is a ComparatorMechanism, its function must have a variable with two items, that receives its values from the SAMPLE and TARGET InputStates of the ComparatorMechanism. learning_function (Optional[LearningFunction or function] : default BackPropagation) – specifies a function to be used for learning by the Learning Mechanism to which the LearningProjection’s sender belongs. Note the learning_function argument is implemented to preserve backward compatibility with previous versions; its use is not advised. learning_rate (Optional[float or int]) – if specified, it is applied multiplicatively to the learning_signal received from the sender; specification of the learning_rate for a LearningProjection supersedes any specification(s) of the learning_rate for any Process and/or System to which the LearningProjection belongs, and is applied in addition to any effects of the learning_rate for the Learning Mechanism from which the LearningProjection receives its learning_signal (see Function and learning_rate for additional details). weight (number : default None) – specifies the value by which to multiply the LearningProjection’s value before combining it with others (see weight for additional details). exponent (number : default None) – specifies the value by which to exponentiate the LearningProjection’s value before combining it with others (see exponent for additional details). params (Dict[param keyword: param value] : default None) – a parameter dictionary that specifies the parameters for the Projection, its function, and/or a custom function and its parameters. By default, it contains an entry for the Projection’s default function and parameter assignments. Values specified for parameters in the dictionary override any assigned to those parameters in arguments of the constructor. name (str : default see ModulatoryProjection name) – specifies the name of the LearningProjection. prefs (PreferenceSet or specification dict : default Projection.classPreferences) – specifies the PreferenceSet for the LearningProjection; see prefs for details.
componentType

LEARNING_PROJECTION

sender

LearningSignal – source of learning_signal (see Sender for additional details).

receiver

MATRIX ParameterState of a MappingProjectionMATRIX ParameterState for the matrix parameter of the learned_projection (see Receiver for additional details).

learned_projection

MappingProjection – the MappingProjection to which LearningProjection’s receiver belongs.

variable

2d np.array – same as learning_signal.

learning_enabled

bool : default True – determines whether the value of the LearningProjection is used to modify the learned_projection when the latter is executed; its value is set by the value of the learning_enabled attribute of the Learning Mechanism to which the LearningProjection’s sender belongs.

learning_signal

2d np.array – the value of the LearningProjection’s sender: a matrix of weight changes calculated by the Learning Mechanism to which the sender belongs; rows correspond to the sender of the learned_projection, and columns to its receiver (i.e., the input and output of the learned_projection, respectively).

function

Function – assigns the learning_signal received from the sender to the LearningProjection’s value, possibly modified by its learning_rate; the default in an identity function.

learning_rate

float or None – determines the learning_rate for the LearningProjection. If specified, it is applied multiplicatively to the learning_signal; its specification may be superseded by the learning_rate of its sender (see Function and learning_rate for additional details);

weight_change_matrix

2d np.array – output of the LearningProjection’s function, possibly modified by its learning_rate; reflects the matrix of weight changes to be made to the matrix parameter of the learned_projection (rows correspond to the sender of the learned_projection, columns to its receiver (i.e., the input and output of the learned_projection, respectively).

value

2d np.array – same as weight_change_matrix.

weight

number – multiplies the value of the LearningProjection after applying exponent, and before combining it with any others that project to the ParameterState for the matrix parameter of the same MappingProjection to determine how that MappingProjection’s matrix is modified (see description above for additional details, including relationship to learning_rate).

exponent
number – exponentiates the value of the LearningProjection, before applying weight
<ControlProjection.weight>, and before combining it with any others that project to the ParameterState

for the matrix parameter of the same MappingProjection to determine how that MappingProjection’s matrix is modified (see description above for additional details, including relationship to learning_rate).

name

str – name of the LearningProjection; if it is not specified in the name argument of its constructor, a default name is assigned (see ModulatoryProjection name; also see Naming for conventions regarding duplicate names).

prefs

PreferenceSet or specification dict – the PreferenceSet for the LearningProjection; if it is not specified in the prefs argument of the constructor, a default is assigned using classPreferences defined in __init__.py (see PreferenceSet for details).