psychopy.org | Reference | Downloads | Github

Remove trials from a wrong_list after correct answer

Dear All,
I am trying to build an Audio-visual paired association test. In the training block, I want to repeat incorrect trials until receiving a correct response. To do that, I created an outer loop with the name trials_9 and wrote the codes to create a list of wrong trials (wrong_list) after the first loop based on the instruction in How to repeat incorrect trials only .
in the first and second loops, everything is okay but the wrong_list that has been created from the first loop is repeated in other loops. Now, I want to remove row_IDs that receive correct answers in the next loops and finish the loop after the wrong_list becomes empty.
my codes in "Begin Routine:

if testing_block9_loop.thisN == 0:
    number_correct = 0

if trials_9.thisN == 0 and testing_block9_loop.thisN ==0:
    wrong_list = []

if trials_9.thisN >= 1:
    if row_ID not in wrong_list:
        continueRoutine = False

the codes in ‘End Routine’:

if trials_9.thisN >= 1 and row_ID not in wrong_list:
        pass
elif mouse_9.clicked_name[0] == CorrAns:
    number_correct = number_correct + 1
    msg = "Correct"
    msgcolor='green'
    mycorrAns = 1
else:
        msg = "Incorrect! Try again" 
        msgcolor='red'
        mycorrAns = 0

if testing_block9_loop.thisN + 1 == testing_block9_loop.nTotal:
    if number_correct/(testing_block9_loop.nTotal) >= 1:
        trials_9.finished = True
    else:
        trials_9.finished = False

if trials_9.thisN ==0 and mycorrAns == 0:
    wrong_list.append(row_ID)

if trials_9.thisN ==1 and mycorrAns == 1:
    wrong_list.remove(row_ID)

print(mouse_9.clicked_name) # DEBUG
print(type(mouse_9.clicked_name)) # DEBUG
print(CorrAns) # DEBUG
print(TrialType)
print(mycorrAns)

I need your help to find the right code for removing trials that receive the correct answers in the second loop and finish the loop when the wrong_list is empty.

Thank you in advance for your help and support.
m.hamzeloo

I’m not 100% certain I understand what’s going on in your code, but I think instead of having one list, you could have two: trials you need to run (let’s call it running_list) and wrong_list. You can then go through the trials in running_list (I’m assuming you’re already doing this in a way) and add incorrect trials to wrong_list. Then at the end of the loop, empty running_list, make running_list = wrong_list, clear wrong_list, and start over. So then you don’t have to remove anything from wrong_list as you go along, only add to a new blank array every loop repeat.

1 Like

Dear @sal ,
I changed my code in this way at End Routine:

if trials_9.thisN >=1:
    running_list = wrong_list
    wrong_list.clear()
if trials_9.thisN >= 1 and row_ID not in running_list:
        pass
elif mouse_9.clicked_name[0] == CorrAns:
    number_correct = number_correct + 1
    msg = "Correct"
    msgcolor='green'
    mycorrAns = 1
else:
        msg = "Incorrect! Try again" 
        msgcolor='red'
        mycorrAns = 0

if testing_block9_loop.thisN + 1 == testing_block9_loop.nTotal:
    if number_correct/(testing_block9_loop.nTotal + 1) >= 1:
        trials_9.finished = True
    else:
        trials_9.finished = False

if trials_9.thisN >=0 and mycorrAns == 0:
    wrong_list.append(row_ID)

print(mouse_9.clicked_name) # DEBUG
print(type(mouse_9.clicked_name)) # DEBUG
print(CorrAns) # DEBUG
print(TrialType)
print(mycorrAns)

But as I wrong_list.clear() to clear the wrong_list after the first loop, there isn’t any trial to repeat in the second loop, and the experiment finishes after one round. I don’t know how can I fix this!
Thank you in advance for your help.

Can you send me a key for your variables and break down the routines in your loop? You are going to want to use running_list, not wrong_list, to run the trials and only add to wrong_list if they were incorrect on a particular trial. You seem to be putting too many things in this one routine, which is why it’s not looping. So seeing your routines will be helpful.

Thank you @sal for your response.
As you can see in the picture below, in each trial 4 pictures and a sound are presented simultaneously and participants must select the correct picture which previously associated with the sound. There are 8 trials (rows) in the excel file (inner loop) and I want to put incorrect trials in the wrong_list for the outer loop. I also found that I insert too many things in the End Routine code. How can I break down them?


I would appreciate your help.

I personally never use excel files for conditions, so I’m not sure exactly how to call to trials that way. I usually just set up my own conditions/trials manually at the beginning of the experiment. Do you call to them by row number? That’s how I was assuming you would do it, so that you can save the incorrect trial numbers and cycle through those numbers every time, rather than the whole excel file. The inner loop should run through all of the trial number you have in your running list, and you would grab trial information with, for example, currentSound = soundsList[running_trials[loop.thisN]]. This will loop through your running list (which will be all trials for the first loop) and will call to the trial information for each trial in that list. Then if their response was incorrect, add that trial number to the wrong_list. Then outside the inner loop, clear the running_list and add the trials from the wrong_list to the running_list, and clear the wrong_list. Then the next inner loop run will still run through all of the trials from the running_list, but this time there will only be the incorrect trials. That’s how I would do it, anyway. I’m not sure if I explained this super well, but I hope it helped a bit.

Dear @Michael, @TParsons, and @jon,

I would appreciate it if you could help me to solve the problem.

Best regards