Randomization problem: No error message, yet still repeating rows no matter what i do

OS: Windows 11
PsychoPy version v2023.2.3
Standard Standalone? (y/n) Y

What are you trying to achieve?:
My experiment ran smoothly, and I was happy until I noticed repeats. It’s a little complicated, but it involves making many decisions, and then it randomly breaks into an ‘execution trial’, meaning it picks one of the rows (and thereby a text) to display. The reason it is complicated is that it involves assigning an Excel sheet based on ExpInfo and then selecting rows based on their choices.

if R_Level < 8:
groupFile = ‘below.xlsx’
elif R_Level > 9:
groupFile = ‘above.xlsx’
else:
groupFile = ‘same.xlsx’

if Effort.contains(mouse) or Reward1_2.contains(mouse):
Comb_list = [1, 1]
Reject += 1
elif image_7.contains(mouse) or image_8.contains(mouse):
Comb_list = [RewardLevel, EffortLevel]
Accept += 1

if Comb_list:
all_selections = [‘0:9’, ‘10:19’, ‘20:29’, ‘30:39’, ‘40:49’, ‘50:58’]
rl = ‘t’ + str(Comb_list[0]) + ‘.jpeg’
el = ‘b’ + str(Comb_list[1]) + ‘.jpeg’
selected_rows_range = all_selections[Comb_list[1] - 1]

I have figured out how to do this with the help of this community. However, no matter what i do, repeats are still happening.

it involves 3 loops, 1 outer loop and 2 inner loops.

What did you try to make it work?:

  • Searched and tried multiple ways of fixing through this forum, even took suggestions from AI :face_with_peeking_eye:
  • made the outer loop sequential (it was original random too).
  • Tried creating a new column in all the excel sheets, which assigns a unique number to each row/text (called TextNum). And then adding in code, which stores used_TextNums and then if repeats happen (by comparing current TextNum to used_textNum), it replaces it with a new row/TextNum (selected_textNum)
  • Tried purely doing it via selected rows, and saying if this row repeats, then find a new row.

What specifically went wrong when you tried that?:
There were no errors messages. It did it’s job, but repeats happened basically and then excel sheet indicated it wasn’t working. :frowning:

I have now gone back to basic and my old code. I was wondering if anyone has unique solutions or some ways of fixing this or any suggestions (no matter how simple)? Perhaps something else is causing this issue? Please let me know if you want any more information. I didn’t want to make this too long. :slight_smile:

Hello @Hans

Did you copy and paste the code? This has “smart” quotes. Make them dumb ones, like ’ or ".

Do you plan to run the experiment online?

This does not translate to PsychoJS. What do try to achieve here?

You could add some print(variable) commands to check the value of your variables and see if they take the values you expect. And yes, it is probably best to turn off all randomisation for debugging purposes.

Best wishes Jens

1 Like

Hiya. I don’t plan to run it online and I am not using PsychoJS. In terms of the all_selections quotes, I realised that, and changed them.

all_selections = [‘0:9’, ‘10:19’, ‘20:29’, ‘30:39’, ‘40:49’, ‘50:58’]

In terms of the debugging, the funny thing is that is it working in all ways apart from repeats. How far should I strip back to see where the problem is happening? For example, have all loops be sequential?

This list is missing several of your rows. Try

all_selections = ['0:10', '10:20', '20:30', '30:40', '40:50', '50:59']

assuming you have five sets of 10 rows and one set of 9.

1 Like

Okay. Thanks. I had this original, but thought this might be the reason for the repeats (obviously wasn’t). I attempted your complicated randomization thing on the blog page, but it really didn’t like me (i think it probably doesn’t work in my case due to all the constrictions). Any hep would be appreciated. Been working on this for weeks with no progress, just 1 step forward and then 2 back.

Please could you explain what you mean by repeats in terms of your loops and routines?

1 Like

Okay, so in my groupFile, I have rows of ‘texts’ (corresponding to a path to a png file containing a short story). I don’t want them to repeat. So, for example, I just ran my experiment. And I have a column that tracks TextNum (allowing me to check for any repeats), resulting in 9,4, 24, 5, 23, 1, 9, 1,1, 10, 6. As you can see, 1 repeated 3 and 9 twice. Meaning that text 1 repeats 3 times and text 9 repeats twice. I don’t want this to happen. It has no reason to happen (since I have roughly 10 texts), yet it keeps happening. Hopefully, this makes sense.

@wakecarter Here is an example of my excel sheet

If you have “roughly” 10 texts then how were texts 23 and 24 presented?

I suspect that the issue is that you keep restarting the loop using selected_rows_range. If you restart a loop it has no knowledge of what was previously presented.

1 Like

Okay, so, all_selections = [‘0:10’, ‘10:20’, ‘20:30’, ‘30:40’, ‘40:50’, ‘50:59’]. Each of these row ranges includes 10 texts. So, in total, there are 59 texts.

One Loop includes the code in Game_1 End Routine, while the texts are executed in Two Loop (via the loop, selected_rows = selected_row_range). Then Loop 3, makes it go back to One Loop. Do you think loop two is re-starting? If so, why?

Perhaps this idea has some merit to it. Since my Two Loop index is all messed up unlike Three Loop and One Loop. For example, Two.thisIndex is 8, 3, 3, 4, 2, 0, 8, 0, 0, 9, 5 (note that this does not correlate with TextNum, meaning that the thisIndex repeating does not mean the text themselves repeat). Hopefully, this makes sense.