Skip to content

Commit

Permalink
Refactor/state and projection/names and docs (#500)
Browse files Browse the repository at this point in the history
* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* Merge branch 'TEMP' into refactor/State_and_Projection/specification

# Conflicts:
#	PsyNeuLink/Components/States/State.py

* Merge branch 'TEMP' into refactor/State_and_Projection/specification

# Conflicts:
#	PsyNeuLink/Components/States/State.py

* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* • GatingMechanism
  - refactor _instantiate_gating_signal to use _parse_state_spec

* • GatingMechanism
  - refactor _instantiate_gating_signal to use _parse_state_spec

* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* • States and Projections
  - implemented _assign_default_name that reinstates context-sensitive naming
  - docstring revisions
  - bug fixes
  • Loading branch information
jdcpni committed Oct 30, 2017
1 parent bf5a6b5 commit b152401
Show file tree
Hide file tree
Showing 20 changed files with 1,123 additions and 772 deletions.
2 changes: 1 addition & 1 deletion Scripts/Models/GilzenratModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
threshold_FHN=0.5, #Parameter describing shape of the FitzHugh–Nagumo cubic nullcline for the fast excitation variable v
objective_mechanism=ObjectiveMechanism(
function=Linear,
monitored_output_states=[(decision_layer, None, None, np.array([[0.3],[0.0]]))],
# monitored_output_states=[(decision_layer, None, None, np.array([[0.3],[0.0]]))],
# monitored_output_states=[{PROJECTION_TYPE: MappingProjection,
# SENDER: decision_layer,
# MATRIX: np.array([[0.3],[0.0]])}],
Expand Down
420 changes: 302 additions & 118 deletions Scripts/Scratch Pad.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Scripts/TEST SCRIPTS/Multilayer Learning Test Script.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def show_target():
x.reportOutputPref = True
composition = x

x.show_graph(show_learning=ALL)
# x.show_graph(show_learning=ALL)
# x.show_graph()
results = x.run(
num_trials=10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<ControlSignal_Specification>`;
* where the `parameter is specified <ParameterState_Specification>`, by including a `ControlProjection` or
`ControlSignal` in a `tuple specification for the parameter.
`ControlSignal` in a `tuple specification <ParameterState_Tuple_Specification>` for the parameter.
When a ControlMechanism is created as part of a System, a `ControlSignal` is created and assigned to the
ControlMechanism for every parameter of any `Component <Component>` in the System that has been specified for control
Expand Down Expand Up @@ -848,10 +848,10 @@ def add_monitored_output_states(self, monitored_output_states, context=None):
"""Instantiate OutputStates to be monitored by ControlMechanism's `objective_mechanism
<ControlMechanism.objective_mechanism>`.
**monitored_output_states** can be a `Mechanism`, `OutputState`, `monitored_output_states tuple
<ObjectiveMechanism_OutputState_Tuple>`, or list with any of these. If item is a Mechanism, its `primary
OutputState <OutputState_Primary>` is used. OutputStates must belong to Mechanisms in the same `System` as
the ControlMechanism.
**monitored_output_states** can be a `Mechanism`, `OutputState`, `tuple specification
<InputState_Tuple_Specification>`, a `State specification dicionary <InputState_Specification_Dictionary>`,
or list with any of these. If item is a Mechanism, its `primary OutputState <OutputState_Primary>` is used.
OutputStates must belong to Mechanisms in the same `System` as the ControlMechanism.
"""
output_states = self.objective_mechanism.add_monitored_output_states(
monitored_output_states_specs=monitored_output_states,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@
from psyneulink.components.functions.function import ModulationParam, _is_modulation_param
from psyneulink.components.mechanisms.adaptive.adaptivemechanism import AdaptiveMechanism_Base
from psyneulink.components.mechanisms.mechanism import Mechanism_Base
from psyneulink.components.shellclasses import Mechanism
from psyneulink.components.states.modulatorysignals.gatingsignal import GatingSignal
from psyneulink.components.states.state import State_Base, _parse_state_spec
from psyneulink.globals.defaults import defaultGatingPolicy
from psyneulink.globals.keywords import GATING_POLICY, GATING_PROJECTION, GATING_PROJECTIONS, GATING_SIGNAL, GATING_SIGNALS, GATING_SIGNAL_SPECS, INIT__EXECUTE__METHOD_ONLY, MAKE_DEFAULT_GATING_MECHANISM, NAME, OWNER, PARAMS, REFERENCE_VALUE, STATES
from psyneulink.globals.keywords import \
GATING_POLICY, GATING_PROJECTIONS, GATING_SIGNAL, GATING_SIGNALS, GATING_SIGNAL_SPECS, \
INIT__EXECUTE__METHOD_ONLY, MAKE_DEFAULT_GATING_MECHANISM
from psyneulink.globals.preferences.componentpreferenceset import is_pref_set
from psyneulink.globals.preferences.preferenceset import PreferenceLevel
from psyneulink.globals.utilities import ContentAddressableList
from psyneulink.scheduling.timescale import CentralClock, TimeScale

__all__ = [
Expand Down
218 changes: 145 additions & 73 deletions psyneulink/components/mechanisms/mechanism.py

Large diffs are not rendered by default.

450 changes: 165 additions & 285 deletions psyneulink/components/mechanisms/processing/objectivemechanism.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@

from psyneulink.components.component import Component, function_type, method_type
from psyneulink.components.functions.function import AdaptiveIntegrator, Linear
from psyneulink.components.mechanisms.mechanism import MechanismError
from psyneulink.components.mechanisms.mechanism import MechanismError, Mechanism
from psyneulink.components.mechanisms.processing.processingmechanism import ProcessingMechanism_Base
from psyneulink.components.states.outputstate import PRIMARY_OUTPUT_STATE, StandardOutputStates, standard_output_states
from psyneulink.components.states.inputstate import InputState
from psyneulink.components.states.outputstate import \
OutputState, PRIMARY_OUTPUT_STATE, StandardOutputStates, standard_output_states
from psyneulink.globals.keywords import FUNCTION, INITIALIZER, INITIALIZING, MEAN, MEDIAN, NOISE, RATE, RESULT, STANDARD_DEVIATION, TRANSFER_FUNCTION_TYPE, TRANSFER_MECHANISM, VARIANCE, kwPreferenceSetName
from psyneulink.globals.preferences.componentpreferenceset import is_pref_set, kpReportOutputPref, kpRuntimeParamStickyAssignmentPref
from psyneulink.globals.preferences.preferenceset import PreferenceEntry, PreferenceLevel
Expand Down Expand Up @@ -406,7 +408,7 @@ class ClassDefaults(ProcessingMechanism_Base.ClassDefaults):
def __init__(self,
default_variable=None,
size=None,
input_states:tc.optional(tc.any(list, dict))=None,
input_states:tc.optional(tc.any(list, dict, Mechanism, OutputState, InputState))=None,
function=Linear,
initial_value=None,
noise=0.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"""

from psyneulink.components.projections.projection import Projection_Base
from psyneulink.globals.keywords import PATHWAY_PROJECTION, NAME
from psyneulink.globals.keywords import PATHWAY_PROJECTION, NAME, RECEIVER
from psyneulink.components.component import InitStatus

__all__ = []
Expand Down Expand Up @@ -98,6 +98,10 @@ def _assign_default_projection_name(self, state, sender_name=None, receiver_name
self.receiver.owner.name

elif self.init_status is InitStatus.DEFERRED_INITIALIZATION:
if self.init_args[RECEIVER]:
receiver = self.init_args[RECEIVER]
if receiver.owner:
receiver_name = "{}[{}]".format(receiver.owner.name, receiver_name)
projection_name = self.className + " from " + sender_name + " to " + receiver_name
self.init_args[NAME] = self.init_args[NAME] or projection_name

Expand Down
8 changes: 5 additions & 3 deletions psyneulink/components/projections/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@
* *MAPPING_PROJECTION* -- if the `sender <MappingProjection.sender>` and/or its `receiver
<MappingProjection.receiver>` cannot be inferred from the context in which this specification occurs, then its
`initialization is deferred <MappingProjection_Deferred_Initialization>` until both of those have been
determined (e.g., it is used in the specification of a `pathway <Process.pathway>` for a `Process`).
determined (e.g., it is used in the specification of a `pathway <Process.pathway>` for a `Process`). For
MappingProjections, a `matrix specification <Mapping_Matrix_Specification>` can also be used to specify the
projection.
|
* *LEARNING_PROJECTION* (or *LEARNING*) -- this can only be used in the specification of a `MappingProjection`
(see `tuple <Mapping_Matrix_Specification>` format). If the `receiver <MappingProjection.receiver>` of the
Expand Down Expand Up @@ -148,7 +150,7 @@
manner as described above for keyword specifications.
COMMENT:
WHAT ABOUT SPECIFICATION USING OutputState/ModulatorySignal OR Mechanism?
WHAT ABOUT SPECIFICATION USING OutputState/ModulatorySignal OR Mechanism? OR Matrix OR Matrix keyword
COMMENT
COMMENT: ??IMPLEMENTED FOR PROJECTION PARAMS??
Expand All @@ -170,7 +172,7 @@
when :keyword:`learning` is specified for a `Process <Process_Learning_Sequence>` or `System
<System_Execution_Learning>`).
.. _MappingProjection_Deferred_Initialization:
.. _Projection_Deferred_Initialization:
Deferred Initialization
~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
Loading

0 comments on commit b152401

Please sign in to comment.