Skip to content

Commit

Permalink
Name/project/replace assign index calculate (#711)
Browse files Browse the repository at this point in the history
* • ControlMechanism
  assign_as_controller:  fixed bug (assignment of self.allocation)

* • Project
  - Delete ASSIGN everywhere except in OutputState and Keywords

* • LearningMechanism failing

* • LearningMechanism
  _validate_params:
      replaced try and except for learning_signal[PARAMS][PROJECTIONS]
      with if-else

• OutputState:
  _parse_state_specific_specs:
      refactored for VARIABLE in place of INDEX in 3-item tuple

* • LearningMechanism
  _validate_params:
      replaced try and except for learning_signal[PARAMS][PROJECTIONS]
      with if-else

• OutputState:
  _parse_state_specific_specs:
      refactored for VARIABLE in place of INDEX in 3-item tuple
  docstring revised per above

* -

* -
  • Loading branch information
jdcpni authored Mar 9, 2018
1 parent 3fbb4b8 commit 0241e93
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 158 deletions.
6 changes: 2 additions & 4 deletions Scripts/Examples/EVC-Gratton.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@
pnl.PROBABILITY_UPPER_THRESHOLD,
{
pnl.NAME: 'OFFSET RT',
pnl.INDEX: 2,
pnl.ASSIGN: pnl.Linear(0, slope=0.3, intercept=1)
# pnl.VARIABLE:[(pnl.OWNER_VALUE,2)],
# pnl.FUNCTION: pnl.Linear(0, slope=0.3, intercept=1)
pnl.VARIABLE: (pnl.OWNER_VALUE, 2),
pnl.FUNCTION: pnl.Linear(0, slope=0.3, intercept=1)
}
],
)
Expand Down
4 changes: 2 additions & 2 deletions Scripts/Examples/EVC_MARKUS_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
pnl.PROBABILITY_UPPER_THRESHOLD,
{
pnl.NAME: 'OFFSET RT',
pnl.INDEX: 2,
pnl.ASSIGN: pnl.Linear(0, slope=1.0, intercept=1)
pnl.VARIABLE: (pnl.OWNER_VALUE, 2),
pnl.FUNCTION: pnl.Linear(0, slope=1.0, intercept=1)
}
],) #drift_rate=(1.0),threshold=(0.2645),noise=(0.5),starting_point=(0), t0=0.15
Decision.set_log_conditions('DECISION_VARIABLE')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
from psyneulink.components.mechanisms.mechanism import Mechanism_Base
from psyneulink.components.shellclasses import System_Base
from psyneulink.components.states.modulatorysignals.controlsignal import ControlSignal
from psyneulink.components.states.outputstate import INDEX, SEQUENTIAL
from psyneulink.components.states.outputstate import SEQUENTIAL
from psyneulink.globals.defaults import defaultControlAllocation
from psyneulink.globals.keywords import AUTO_ASSIGN_MATRIX, COMMAND_LINE, CONTROL, CONTROLLER, CONTROL_PROJECTION, \
CONTROL_PROJECTIONS, CONTROL_SIGNAL, CONTROL_SIGNALS, EXPONENT, INIT__EXECUTE__METHOD_ONLY, NAME, \
Expand Down Expand Up @@ -886,19 +886,14 @@ def _instantiate_control_signal(self, control_signal, context=None):
self.value = self.instance_defaults.value

# Assign ControlSignal's variable to appended item of owner's value
# control_signal._variable = (OWNER_VALUE, len(self.instance_defaults.value) - 1)
if control_signal.owner_value_index is None:
control_signal._variable = [(OWNER_VALUE, len(self.instance_defaults.value) - 1)]
if not isinstance(control_signal.owner_value_index, int):
raise ControlMechanismError(
"PROGRAM ERROR: {} attribute of {} for {} is not {} or an int".format(
INDEX, ControlSignal.__name__, SEQUENTIAL, self.name
)
)

"PROGRAM ERROR: The \'owner_value_index\' attribute for {} of {} ({})is not an int."
.format(control_signal.name, self.name, control_signal.owner_value_index))
# Validate index
try:

self.value[control_signal.owner_value_index]
except IndexError:
raise ControlMechanismError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,10 @@
from psyneulink.components.states.inputstate import InputState
from psyneulink.components.states.parameterstate import ParameterState
from psyneulink.components.states.modulatorysignals.learningsignal import LearningSignal
from psyneulink.globals.keywords import ASSERT, CONTROL_PROJECTIONS, ENABLED, IDENTITY_MATRIX, INDEX, INITIALIZING, \
from psyneulink.globals.keywords import ASSERT, CONTROL_PROJECTIONS, ENABLED, IDENTITY_MATRIX, INITIALIZING, \
INPUT_STATES, LEARNED_PARAM, LEARNING, LEARNING_MECHANISM, LEARNING_PROJECTION, LEARNING_SIGNAL, LEARNING_SIGNALS, \
MATRIX, MATRIX_KEYWORD_SET, NAME, OUTPUT_STATE, OUTPUT_STATES, OWNER_VALUE, PARAMS, \
PROJECTIONS, SAMPLE, STATE_TYPE, TARGET
PROJECTIONS, SAMPLE, STATE_TYPE, TARGET, VARIABLE
from psyneulink.globals.preferences.componentpreferenceset import is_pref_set
from psyneulink.globals.preferences.preferenceset import PreferenceLevel
from psyneulink.globals.utilities import ContentAddressableList, is_numeric, parameter_spec
Expand Down Expand Up @@ -893,9 +893,9 @@ class LearningMechanism(AdaptiveMechanism_Base):
INPUT_STATES:input_state_names,
OUTPUT_STATES:[{NAME:ERROR_SIGNAL,
STATE_TYPE:OUTPUT_STATE,
INDEX:1},
VARIABLE: (OWNER_VALUE, 1)},
{NAME:LEARNING_SIGNAL, # NOTE: This is the default, but is overridden by any LearningSignal arg
INDEX:0}
VARIABLE: (OWNER_VALUE, 0)}
]})

@tc.typecheck
Expand Down Expand Up @@ -1017,17 +1017,16 @@ def _validate_params(self, request_set, target_set=None, context=None):
for spec in target_set[LEARNING_SIGNALS]:
learning_signal = _parse_state_spec(state_type=LearningSignal, owner=self, state_spec=spec)


# Validate that the receiver of the LearningProjection (if specified)
# is a MappingProjection and in the same System as self (if specified)
try:
if learning_signal[PARAMS] and PROJECTIONS in learning_signal[PARAMS]:
for learning_projection in learning_signal[PARAMS][PROJECTIONS]:
_validate_receiver(sender_mech=self,
projection=learning_projection,
expected_owner_type=MappingProjection,
spec_type=LEARNING_SIGNAL,
context=context)
except KeyError:
else:
pass

def _instantiate_attributes_before_function(self, context=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@
from psyneulink.components.mechanisms.processing.processingmechanism import ProcessingMechanism_Base
from psyneulink.components.states.inputstate import InputState
from psyneulink.components.states.outputstate import OutputState, PRIMARY, StandardOutputStates, standard_output_states
from psyneulink.globals.keywords import FUNCTION, INDEX, INITIALIZER, INITIALIZING, \
from psyneulink.globals.keywords import FUNCTION, INITIALIZER, INITIALIZING, OWNER_VALUE, \
MAX_VAL, MAX_ABS_VAL, MAX_INDICATOR, MAX_ABS_INDICATOR, MEAN, MEDIAN, NAME, NOISE, NORMALIZING_FUNCTION_TYPE, \
PROB,RATE, RESULT, RESULTS, STANDARD_DEVIATION, TRANSFER_FUNCTION_TYPE, TRANSFER_MECHANISM, VARIANCE, \
PROB,RATE, RESULT, RESULTS, STANDARD_DEVIATION, TRANSFER_FUNCTION_TYPE, TRANSFER_MECHANISM, VARIABLE, VARIANCE, \
kwPreferenceSetName
from psyneulink.globals.preferences.componentpreferenceset import is_pref_set, \
kpReportOutputPref, kpRuntimeParamStickyAssignmentPref
Expand Down Expand Up @@ -871,7 +871,7 @@ def _instantiate_output_states(self, context=None):
if len(self.instance_defaults.variable) > 1 and len(self.output_states) == 1 and self.output_states[0] == RESULTS:
self.output_states = []
for i, item in enumerate(self.instance_defaults.variable):
self.output_states.append({NAME: RESULT, INDEX: i})
self.output_states.append({NAME: RESULT, VARIABLE: (OWNER_VALUE, i)})
super()._instantiate_output_states(context=context)

def _execute(self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
The dictionary can also contain entries for any other GatingSignal attributes to be specified
(e.g., a *MODULATION* entry, the value of which determines how the GatingSignal modulates the
`value <State_Base.value>` of the State(s) that it gates; or an *INDEX* entry specifying which item
`value <State_Base.value>` of the State(s) that it gates; or a *VARIABLE* entry specifying which item
of the GatingMechanism's `gating_policy <GatingMechanism.gating_policy>` it should use as its `value
<GatingSignal,value>`).
<GatingSignal,value>`; see `OutputState_Customization`).
..
* **2-item tuple** -- the 1st item must be the name of the State (or list of State names), and the 2nd item the
Mechanism to which it (they) belong(s); this is a convenience format, which is simpler to use than a specification
Expand Down
Loading

0 comments on commit 0241e93

Please sign in to comment.