diff --git a/PsyNeuLink/Components/Mechanisms/AdaptiveMechanisms/GatingMechanisms/GatingSignal.py b/PsyNeuLink/Components/Mechanisms/AdaptiveMechanisms/GatingMechanisms/GatingSignal.py index d2e77d8d678..ee254ddeb1e 100644 --- a/PsyNeuLink/Components/Mechanisms/AdaptiveMechanisms/GatingMechanisms/GatingSignal.py +++ b/PsyNeuLink/Components/Mechanisms/AdaptiveMechanisms/GatingMechanisms/GatingSignal.py @@ -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 @@ -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: @@ -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". diff --git a/PsyNeuLink/Globals/Keywords.py b/PsyNeuLink/Globals/Keywords.py index 167b9e49874..0f05e15efc7 100644 --- a/PsyNeuLink/Globals/Keywords.py +++ b/PsyNeuLink/Globals/Keywords.py @@ -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' diff --git a/Scripts/DEBUGGING SCRIPTS/Multilayer Learning Test Script [WITH GATING].py b/Scripts/DEBUGGING SCRIPTS/Multilayer Learning Test Script [WITH GATING].py index ca89161e836..15d52470ff6 100644 --- a/Scripts/DEBUGGING SCRIPTS/Multilayer Learning Test Script [WITH GATING].py +++ b/Scripts/DEBUGGING SCRIPTS/Multilayer Learning Test Script [WITH GATING].py @@ -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 ]) @@ -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: )