OS Ubuntu
PsychoPy version v1.83.04
What are you trying to achieve?: I have a list of words that belong to either category “A” or category “B”. I would like to present them in a pseudo-randomized fashion, constrained to having no more than four words belonging to the same category being presented in a row. I would like to keep this in the Builder, with some additional code which I assume will be necessary to achieve this presentation order.
What did you try to make it work?: I have been working on this problem for a few days now and I kind of lost track of all my attempts, but basically I played around with the loops and conditions files looking for a way to make the program sample either “A” or “B” words according to a predefined order that already met the no-more-than-four-in-a-row criterion.
I created a pseudo-random “abstract order” (i.e., a stimulus category order) that met the constraint, and put it into an outer loop that my main trial loop could refer to. Therefore, I had something like $itemType
as input in the “Conditions” field of my trial loop, and also "itemType as a header in my “trialList.csv” file in the outer loop. The “itemType” column in the “trialList.csv” file contained repetitions of either the “listA.csv” or “listB.csv” filenames as trials, thus pointing to separate files containing the words that belong to either the “A” or the “B” category.
My first (and naive) difficulty was that the program would go through either the whole “A” or “B” lists, rather than picking just one word/trial. Because I could not find a way to independently assign a “weight” or “repetition” parameter to specific trials in a list, in Builder mode, I added a “rowSelect” column to the “trialList.csv”, and I used it as a way to select only a specific row on each trials, under the “Selected rows” field of my trial loop.
Now in principle this kind of solved my problem, however in a not-so-elegant way. Indeed, I´d rather randomize which word is presented, because I fear that having both the “abstract order” (i.e., the stimulus condition order) and the actual order of the stimuli (i.e., which word is displayed) pre-specified may introduce excessive order effects in my procedure.
Other users here already suggested a “brute force” approach to similar problems, i.e., shuffling the list, checking it, repeat until the desired constraint is met, then feed it to the loop that presents the trials. This would be a great solution to me, as it would both randomize the “abstract” and the actual order of words, however my limited knowledge of python could use some directions on how to implement this with code snippets prior to the loops that manage trial presentation.