Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/ddm/threshold #760

Merged
merged 2 commits into from
Apr 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion psyneulink/components/functions/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -5928,8 +5928,10 @@ def function(self,

if np.all(abs(value) < threshold):
adjusted_value = value + offset
else:
elif np.all(value >= threshold):
adjusted_value = np.atleast_2d(threshold)
elif np.all(value <= -threshold):
adjusted_value = np.atleast_2d(-threshold)

# If this NOT an initialization run, update the old value and time
# If it IS an initialization run, leave as is
Expand Down
14 changes: 8 additions & 6 deletions psyneulink/library/mechanisms/processing/integrator/ddm.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,13 +822,19 @@ def plot(self, stimulus=1.0, threshold=10.0):
"""
Generate a dynamic plot of the DDM integrating over time towards a threshold.

NOTE: plot is only available `integration mode <DDM_Integration_Mode>` (with the Integrator function).
.. note::
The plot method is only available when the DriftDiffusionIntegrator function is in use. The plot method does
not represent the results of this DDM mechanism in particular, and does not affect the current state of this
mechanism's DriftDiffusionIntegrator. The plot method is only meant to visualize a possible path of a DDM
mechanism with these function parameters.

Arguments
---------
stimulus: float: default 1.0
specify a stimulus value for the AdaptiveIntegrator function

threshold: float: default 10.0
specify the threshold at which the DDM will stop integrating
specify the threshold at which the DDM will stop integrating

Returns
-------
Expand Down Expand Up @@ -1002,10 +1008,6 @@ def _execute(self,
:rtype self.outputState.value: (number)
"""

# PLACEHOLDER for a time_step_size parameter when time_step_mode/Scheduling is implemented:
time_step_size = 1.0


# FIX: 2/5/18: PUT CODE HERE FOR input_format = ARRAY/VECTOR, TO SUBTRACT variable[1] from variable[0]

if variable is None or np.isnan(variable):
Expand Down
16 changes: 16 additions & 0 deletions tests/mechanisms/test_ddm_mechanism.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ def test_threshold_stops_accumulation(self):
# time accumulation does not stop
assert np.allclose(time_points, [1.0, 2.0, 3.0, 4.0, 5.0])

def test_threshold_stops_accumulation_negative(self):
D = DDM(name='DDM',
function=DriftDiffusionIntegrator(threshold=5.0))
decision_variables = []
time_points = []
for i in range(5):
output = D.execute(-2.0)
decision_variables.append(output[0][0][0])
time_points.append(output[1][0][0])

# decision variable accumulation stops
assert np.allclose(decision_variables, [-2.0, -4.0, -5.0, -5.0, -5.0])

# time accumulation does not stop
assert np.allclose(time_points, [1.0, 2.0, 3.0, 4.0, 5.0])

# def test_threshold_stops_accumulation_multiple_variables(self):
# D = IntegratorMechanism(name='DDM',
# default_variable=[[0,0,0]],
Expand Down