Skip to content

Commit

Permalink
Fix/output states (#536)
Browse files Browse the repository at this point in the history
* -

* Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeuLink into CURRENT

# Conflicts:
#	tests/mechanisms/test_transfer_mechanism.py

* Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeuLink into CURRENT

# Conflicts:
#	tests/mechanisms/test_transfer_mechanism.py

* -

* -

* • State
  - docstring: STATE NAME ENTRY, MECHANISM/STATE and State constructor examples

* -

* • TransferMechanism
  - instantiate one OutputState for each item of variable

* -

* • TransferMechanism
  - _instantiate_output_states:  added to implement one standard OutputState for each InputState
• OutputState
  - fixed bug in assigning params to standard OutputStates

* • Mechanism subclasses
  - removed specification of output_states as list (replaced with string or tuple
    (to avoid mutable default assignment)
• TransferMechanism
  - __init__: assigned output_states to RESULT rather than [RESULT] to avoid default "gotcha"
  - _instantiate_output_states:  added to implement one standard OutputState for each InputState
• OutputState
  - fixed bug in assigning params to standard OutputStates

* • Mechanism subclasses
  - removed specification of output_states as list (replaced with string or tuple
    (to avoid mutable default assignment)
• TransferMechanism
  - __init__: assigned output_states to RESULT rather than [RESULT] to avoid default "gotcha"
  - _instantiate_output_states:  added to implement one standard OutputState for each InputState
• OutputState
  - fixed bug in assigning params to standard OutputStates

* • Mechanism subclasses
  - removed specification of output_states as list (replaced with string or tuple
    (to avoid mutable default assignment)
• TransferMechanism
  - __init__: assigned output_states to RESULT rather than [RESULT] to avoid default "gotcha"
  - _instantiate_output_states:  added to implement one standard OutputState for each InputState
• OutputState
  - fixed bug in assigning params to standard OutputStates

* • Minor cleanup of output_states arg assignment
  • Loading branch information
jdcpni authored Nov 17, 2017
1 parent ac2c9f0 commit 9e3ddd4
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions psyneulink/components/mechanisms/mechanism.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,8 @@ def __init__(self,
context=context)

variable = self._handle_default_variable(variable, size, input_states, params)
if isinstance(output_states, tuple):
output_states = list(output_states)

# Mark initialization in context
if not context or isinstance(context, object) or inspect.isclass(context):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,16 +531,16 @@ def __init__(self,
default_variable=None,
size=None,
function=LinearCombination,
output_states:tc.optional(tc.any(str, list, dict))=OUTCOME,
output_states:tc.optional(tc.any(str, Iterable))=OUTCOME,
params=None,
name=None,
prefs:is_pref_set=None,
context=None,
**kwargs):

input_states = monitored_output_states
if isinstance(output_states, str):
output_states = list(output_states)
if output_states is None or output_states is OUTCOME:
output_states = [OUTCOME]

# Assign args to params and functionParams dicts (kwConstants must == arg names)
params = self._assign_args_to_param_dicts(input_states=input_states,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def __init__(self,
time_constant=1.0,
integrator_mode=False,
clip=None,
output_states:tc.optional(tc.any(str, list, dict))=RESULT,
output_states:tc.optional(tc.any(str, Iterable))=RESULT,
time_scale=TimeScale.TRIAL,
params=None,
name=None,
Expand Down
5 changes: 4 additions & 1 deletion psyneulink/library/mechanisms/processing/transfer/kwta.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,16 @@ def __init__(self,
inhibition_only=True,
clip=None,
input_states:tc.optional(tc.any(list, dict)) = None,
output_states:tc.optional(tc.any(list, dict))=None,
output_states:tc.optional(tc.any(str, Iterable))=RESULT,
time_scale=TimeScale.TRIAL,
params=None,
name=None,
prefs: is_pref_set = None,
context=componentType + INITIALIZING,
):
# Default output_states is specified in constructor as a string rather than a list
# to avoid "gotcha" associated with mutable default arguments
# (see: bit.ly/2uID3s3 and http://docs.python-guide.org/en/latest/writing/gotchas/)
if output_states is None:
output_states = [RESULT]

Expand Down
2 changes: 1 addition & 1 deletion psyneulink/library/mechanisms/processing/transfer/lca.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def __init__(self,
integrator_mode=True,
time_step_size=0.1,
clip=None,
output_states:tc.optional(tc.any(str, list, dict))=RESULT,
output_states:tc.optional(tc.any(str, Iterable))=RESULT,
time_scale=TimeScale.TRIAL,
params=None,
name=None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def __init__(self,
enable_learning:bool=False,
learning_rate:tc.optional(tc.any(parameter_spec, bool))=None,
learning_function: tc.any(is_function_type) = Hebbian,
output_states:tc.optional(tc.any(str, list, dict))=RESULT,
output_states:tc.optional(tc.any(str, Iterable))=RESULT,
time_scale=TimeScale.TRIAL,
params=None,
name=None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import numpy as np
import typecheck as tc
from collections import Iterable

from psyneulink.components.functions.function import Hebbian, Linear, is_function_type, LCAIntegrator
from psyneulink.components.mechanisms.adaptive.learning.learningmechanism import LearningMechanism
Expand Down Expand Up @@ -368,7 +369,7 @@ def __init__(self,
enable_learning:bool=False,
learning_rate:tc.optional(tc.any(parameter_spec, bool))=None,
learning_function:tc.any(is_function_type) = Hebbian,
output_states:tc.optional(tc.any(str, list, dict))=RESULT,
output_states:tc.optional(tc.any(str, Iterable))=RESULT,
time_scale=TimeScale.TRIAL,
params=None,
name=None,
Expand Down

0 comments on commit 9e3ddd4

Please sign in to comment.