LearningProjection¶
Contents¶
Overview¶
A LearningProjection is a type of ModulatoryProjection that projects from a LearningMechanism
to the MATRIX ParameterPort of a MappingProjection. It takes the value
of a
LearningSignal of a LearningMechanism, 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 Composition’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 ParameterPort 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 LearningMechanism 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 LearningMechanism 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 LearningMechanism,
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¶
The default function
of a LearningProjection is an identity function (Linear
with
slope=1 and intercept=0), that assigns the learning_signal
received
from its sender
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 ParameterPort 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 Projection.
As noted under Projection, they are
not normalized and thus their effects aggregate if a ParameterPort receives one or more LearningProjections with
non-default values of their weight
and exponent
attributes.
Receiver¶
The receiver
of a LearningProject is the MATRIX ParameterPort 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’s execution is determined by its learning_enabled
attribute. If that is False`, it is never executed. If it is True or
ONLINE, is executed when the MATRIX ParameterPort to which it projects is updated. This occurs when the
learned_projection
(the MappingProjection to which the MATRIX
ParameterPort 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). If learning_enabled
is AFTER, then LearningProjection is executed at the end of the TRIAL
of the Composition to which it belongs. When the LearningProjection is executed, its function
gets the learning_signal
from its sender
and conveys that to its receiver
.
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.core.components.projections.modulatory.learningprojection.DefaultTrainingMechanism¶
alias of
psyneulink.core.components.mechanisms.processing.objectivemechanism.ObjectiveMechanism
- class psyneulink.core.components.projections.modulatory.learningprojection.LearningProjection(sender=None, receiver=None, error_function=None, learning_function=None, learning_enabled=None, weight=None, exponent=None, params=None, name=None, prefs=None, **kwargs)¶
learning_enabled=None weight=None, exponent=None, params=None, name=None, prefs=None)
Subclass of ModulatoryProjection that modulates the value of a ParameterPort for the
matrix
parameter of a MappingProjection. See Projection for additional arguments and attributes.- 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 ParameterPort for matrix parameter of one]) – specifies the MATRIX ParameterPort (or the MappingProjection that owns it) for the
matrix
of thelearned_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 theweight_change_matrix
.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 avariable
with two items, that receives its values from the SAMPLE and TARGET InputPorts of the ComparatorMechanism.learning_function (Optional[LearningFunction or function] : default BackPropagation) –
specifies a function to be used for learning by the LearningMechanism 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_enabled (Optional[bool or Enum[ONLINE|AFTER]] : default : None) – determines whether or when the
value
of the LearningProjection is used to modify thelearned_projection
when the latter is executed (seelearning_enabled
for additional details).
- sender¶
source of
learning_signal
(see Sender for additional details).- Type
- receiver¶
MATRIX ParameterPort for the
matrix
parameter of thelearned_projection
(see Receiver for additional details).- Type
MATRIX ParameterPort of a MappingProjection
- learned_projection¶
the MappingProjection to which LearningProjection’s
receiver
belongs.- Type
- variable¶
same as
learning_signal
.- Type
2d np.array
- learning_enabled¶
determines whether or when the
value
of the LearningProjection is used to modify thelearned_projection
when the latter is executed; by default, its value is set to the value of thelearning_enabled
attribute of the LearningMechanism to which the LearningProjection’ssender
belongs; however it can be overridden using the learning_enabled argument of the LearningProjection’s constructor and/or by assignment after it is constructed (seelearning_enabled
for additional details).- Type
bool or Enum[ONLINE|AFTER]
- learning_signal¶
the
value
of the LearningProjection’ssender
: a matrix of weight changes calculated by the LearningMechanism to which thesender
belongs; rows correspond to thesender
of the learned_projection, and columns to itsreceiver
(i.e., the input and output of the learned_projection, respectively).- Type
2d np.array
- function¶
assigns the
learning_signal
received from thesender
to the LearningProjection’svalue
.- Type
Function
- weight_change_matrix¶
output of the LearningProjection’s
function
reflects the matrix of weight changes to be made to thematrix
parameter of thelearned_projection
(rows correspond to thesender
of thelearned_projection
, columns to itsreceiver
(i.e., the input and output of thelearned_projection
, respectively).- Type
2d np.array
- value¶
same as
weight_change_matrix
.- Type
2d np.array
- projection_sender¶
alias of
psyneulink.core.components.mechanisms.modulatory.learning.learningmechanism.LearningMechanism
- _validate_params(request_set, target_set=None, context=None)¶
Validate sender and receiver
Insure sender is a LearningMechanism or the OutputPort of one. Insure receiver is a MappingProjection or the matrix ParameterPort of one.
- _instantiate_sender(sender, context=None)¶
Instantiate LearningMechanism
- _instantiate_receiver(context=None)¶
Validate that receiver has been assigned and is compatible with the output of function
Set learning_enabled to value of receiver if it was not otherwise specified in the constructor
Notes: * _validate_params verifies that receiver is a parameterPort for the matrix parameter of a MappingProjection. * _super()._instantiate_receiver verifies that the projection has not already been assigned to the receiver.
- _execute(variable, context=None, runtime_params=None)¶
- Returns
(2D np.array) self.weight_change_matrix
- exception psyneulink.core.components.projections.modulatory.learningprojection.LearningProjectionError(message, component=None)¶