Permalink
Browse files

BF, TEST: Fix handling of nReversals in data.StairHandler

`StairHandler.nReversals` should never be `None`, but be set to a
value equal to or greater than the length of the `stepSizes` parameter.
Otherwise, we will finish prematurely during `calculateNextIntensity()`.

This closes #1342.
  • Loading branch information...
hoechenberger authored and peircej committed Apr 12, 2017
1 parent f753140 commit 7148cad00ef155fb532c62fc38656057d32e2786
Showing with 25 additions and 7 deletions.
  1. +6 −5 psychopy/data.py
  2. +19 −2 psychopy/tests/test_data/test_StairHandlers.py
@@ -2936,11 +2936,12 @@ def __init__(self,
self._variableStep = True if len(self.stepSizes) > 1 else False
self.stepSizeCurrent = self.stepSizes[0]
if nReversals is not None and len(self.stepSizes) > nReversals:
logging.warn(
"Increasing number of minimum required reversals to "
"the number of step sizes (%i)." % len(self.stepSizes)
)
if nReversals is None:
self.nReversals = len(self.stepSizes)
elif len(self.stepSizes) > nReversals:
msg = ('Increasing number of minimum required reversals to the '
'number of step sizes, (%i).' % len(self.stepSizes))
logging.warn(msg)
self.nReversals = len(self.stepSizes)
else:
self.nReversals = nReversals
@@ -73,8 +73,8 @@ def checkSimulationResults(self):
# The first trial can never be a reversal.
assert stairs.nReversals <= len(stairs.data) - 1
assert stairs.nReversals == len(stairs.reversalPoints)
assert stairs.nReversals == len(stairs.reversalIntensities)
assert len(stairs.reversalPoints) >= stairs.nReversals
assert len(stairs.reversalIntensities) >= stairs.nReversals
if stairs.reversalPoints:
assert stairs.reversalIntensities
@@ -307,6 +307,21 @@ def test_StairHandlerLinearScalarStepSizeReveralsNone(self):
self.simulate()
self.checkSimulationResults()
def test_nReversals(self):
start_val = 1
step_sizes = range(5)
staircase = data.StairHandler(startVal=start_val, stepSizes=step_sizes,
nReversals=None)
assert staircase.nReversals == len(step_sizes)
staircase = data.StairHandler(startVal=start_val, stepSizes=step_sizes,
nReversals=1)
assert staircase.nReversals == len(step_sizes)
staircase = data.StairHandler(startVal=start_val, stepSizes=step_sizes,
nReversals=10)
assert staircase.nReversals == 10
class TestQuestHandler(_BaseTestStairHandler):
"""
@@ -330,6 +345,8 @@ def test_QuestHandler(self):
minVal=minVal, maxVal=maxVal
)
self.stairs.nReversals = None
self.responses = makeBasicResponseCycles(
cycles=3, nCorrect=2, nIncorrect=2, length=10
)

0 comments on commit 7148cad

Please sign in to comment.