Skip to content

Commit

Permalink
Feat multiple gating projs per signal (#323)
Browse files Browse the repository at this point in the history
* • Multilayer Learning Test Script [WITH GATING]
  - added cases for multiple GatingProjections per GatingSignal

* • Gating Signal
  - _parse_gating_signal_spec():  allow NAME entry of GatingSignal specification dictionary
       to override use of key as name of GatingSignal
       (examples in Multilayer Learning Test Script [WITH GATING])
  • Loading branch information
jdcpni authored Jun 16, 2017
1 parent d5216c3 commit 41bbfcf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ def _parse_gating_signal_spec(owner, state_spec):
# Specification is a dict that could be for a single state state_spec or a list of ones
elif isinstance(state_spec, dict):

# FIX: IS THIS NECESSARY? (GIVEN THE FUNCTIONALITY UNDER 'ELSE': USE KEY AS NAME AND VALUE AS LIST OF STATES)
# If it has a STATES entry, it must be for a list
if STATES in state_spec:
# Validate that the STATES entry has a list
Expand All @@ -481,10 +482,15 @@ def _parse_gating_signal_spec(owner, state_spec):
# If there is a non-keyword key, treat as the name to be used for the GatingSignal,
# and the value a state spec or list of ones
state_name = next((key for key in state_spec if not key in gating_signal_keywords), None)
key_as_name = explicit_name = None
if state_name:
gating_signal_name = state_name
spec_dict = _parse_gating_signal_spec(owner, state_spec[gating_signal_name])
key_as_name = state_name
spec_dict = _parse_gating_signal_spec(owner, state_spec[key_as_name])
states = spec_dict[STATES]
# If there *IS* a NAME entry, then use that (i.e., override key as the name)
if NAME in state_spec:
explicit_name = state_spec[NAME]
gating_signal_name = explicit_name or key_as_name
# Otherwise, it must be for a single state state_spec,
# which means it must have a NAME and a MECHANISM entry:
else:
Expand All @@ -503,9 +509,9 @@ def _parse_gating_signal_spec(owner, state_spec):
mech = state_spec[MECHANISM]

# Check that all of the other entries in the dict are for valid GatingSignal params
# - skip any entries specifying gating signal
# - skip any entries specifying gating signal (i.e., non-keyword keys being used as the GatingSignal name
# - place others in params
for param_entry in [entry for entry in state_spec if not entry in {gating_signal_name, MECHANISM}]:
for param_entry in [entry for entry in state_spec if not entry in {gating_signal_name, key_as_name, MECHANISM}]:
if not param_entry in gating_signal_keywords:
raise GatingSignalError("Entry in specification dictionary for {} arg of {} ({}) "
"is not a valid {} parameter".
Expand Down
1 change: 1 addition & 0 deletions PsyNeuLink/Globals/Keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ def _names(self):
GATING_SIGNAL = 'gating_signal'
GATING_SIGNALS = 'gating_signals'
GATING_SIGNAL_SPECS = 'GATING_SIGNAL_SPECS'
GATE = 'GATE'
GATED_STATE = "gated_state"
GATING_PROJECTIONS = 'GatingProjections'
GATING_POLICY = 'gating_policy'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@

Gating_Mechanism = GatingMechanism(default_gating_policy=1.0,
gating_signals=[
Hidden_Layer_1,
Hidden_Layer_2,
Output_Layer
# THIS GENERATES ONE GATING SIGNAL WITH THREE PROJECTIONS:
{
# NAME: 'GATING SIGNAL EXPLICIT NAME',
'GATE_ALL': [Hidden_Layer_1,
Hidden_Layer_2,
Output_Layer]
},
# THIS GENERATES THREE GATING SIGNALS EACH WITH ONE PROJECTION:
# Hidden_Layer_1,
# Hidden_Layer_2,
# Output_Layer
])


Expand Down Expand Up @@ -66,17 +74,17 @@
# matrix=FULL_CONNECTIVITY_MATRIX
# matrix=RANDOM_CONNECTIVITY_MATRIX
# # MODIFIED 6/11/17 OLD:
matrix=Middle_Weights_matrix
# matrix=Middle_Weights_matrix
# # MODIFIED 6/11/17 NEW:
# matrix={VALUE:Middle_Weights_matrix,
# # FUNCTION:Linear,
# FUNCTION:ConstantIntegrator,
# FUNCTION_PARAMS:{
# INITIALIZER:Middle_Weights_matrix,
# RATE:Middle_Weights_matrix},
# # FUNCTION:ConstantIntegrator(rate=Middle_Weights_matrix)
# # MODULATION:ADDITIVE_PARAM
# }
matrix={VALUE:Middle_Weights_matrix,
FUNCTION:Linear,
# FUNCTION:ConstantIntegrator,
# FUNCTION_PARAMS:{
# INITIALIZER:Middle_Weights_matrix,
# RATE:Middle_Weights_matrix},
# FUNCTION:ConstantIntegrator(rate=Middle_Weights_matrix)
# MODULATION:ADDITIVE_PARAM
}
# MODIFIED 6/11/17 END:
)

Expand Down

0 comments on commit 41bbfcf

Please sign in to comment.