psychopy.org | Reference | Downloads | Github

Inconsistent rounding issues in stop signal task when using += or -= to adjust stop signal delay

OS (Windows 10):
PsychoPy version (v2021.1.0):
Standard Standalone? (y)

What are you trying to achieve?:
A simple staircase algorithm for a stop signal task.

What did you try to make it work?:
The following piece of code is used change the stop signal delay, contingent upon the participant’s performance in the previous trial:

if (RightStopRespL.keys is not None) and (RightStopRespR.keys is None):

msg="Good!"
   RespCrct = 1
   if (SSDright < 0.35):
       SSDright += .05
       
else:
   msg="Wrong response"
   RespCrct = 0
   if (SSDright > 0.05):
      SSDright -= .05

What specifically went wrong when you tried that?:
Upon examination of the data sheet it is apparent that occasionally (but not always), if a participant makes an incorrect response when SSDright is set to 0.05 SSDright drops to 0.0000000000014.
This is strange on two accounts: at that moment SSDright is set to 0.05, so the code used to change the SSD should not be read, and secondly, the number that results is not zero (quite), as it would be if 0.05 was subtracted from it.
Also, every now and then SSDright is set to 0.04999999999 (instead of 0.5). It seems there is something slightly strange going on with the way this variable is changing… There is no particular pattern to it, and so no obvious cause that I have been able to identify. I suppose ultimately I am wondering if this is a known issue with psychopy? Or if anyone else has had any similar issues.
Thanks a lot,
Simon

Hi @simonweber,

The issue likely is that floating point numbers in Python have limited precision. You can read more about this issue in the Python docs or in this stackoverflow post.

Jan

Thanks @jderrfuss,
I hadn’t realised that this is how floating points are represented in computer hardware… I think this is the source of the issue, and it’s easy to work around now.
Cheers,
Simon