Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Pseudorandomization: how to impose a minimum distance constraint on a particular stimulus?

Hello!

I am creating a Sustained Attention to Response Task where I present a series of numbers from 1 to 9. The participant is supposed to respond to all the numbers except number 3. I have 225 trials in one block, which means that each number occurs 25 times. The problem is that I need the order to be pseudorandomized, in a way that number 3 occurances are seperated by at least 5 other numbers (to make sure that 3s are dispersed throughout the whole task).

I have a loop item with a table of all the numbers and correct responses. I have applied a minimum distance constraint in the loop item, but it constrains the entire variable (entire column 'number' in my table). I want to enforce this constraint only for number 3 though. How can I do that?


Comments

  • Hi,

    You could add a variable to the loop table, in which you have only two values, e.g. target and distractor. Fill the table such that all the 3s have one value, and all other numbers have a different value. Then you can use the mindist constrain on the new column.

    Would that work?

    Eduard

    Buy Me A Coffee

  • Did you mean a table like this? If so, it does not work. When I constrain the new column ('type') it still encompasses all the numbers, and since I have only two values in that column, it's not even possible for the mindist=5 constraint to work.


  • edited April 2023

    True, for this use case I wouldn't use the loop table, but implement it directly in an inline_script. For example:

    import numpy as np
    def invalid_reps(numbers):
        three_idx = np.where(numbers == 3)[0]
        three_dist = np.diff(three_idx)
        if any(three_dist < 5):
            return True
        return False
    # generate a sorted list with all trials you need
    numbers = np.tile(np.arange(1, 10), 25)
    # shuffle it
    np.random.shuffle(numbers)
    # check whether your rules are violated, and if so, keep on shuffling, until it works
    while invalid_reps(numbers):
         np.random.shuffle(numbers)
    # now numbers is shuffled and your constrains fulfilled
    

    Something like this should do. The numbers list you can then loop over, essentially generating trials.

    Eduard

    ps. I haven't tested the code, so there might be a few silly mistakes present. The general idea should check out though

    Buy Me A Coffee

  • I'm sorry it took me so long to respond.

    I tested your code outside OpenSesame and it does what it's supposed to do, but the process is time-consuming. I run the code a few times and every time it took 1-3 minutes to get a correct list of numbers, so I guess it's not really applicable to my OS experiment. Do you have any idea how to make it work faster and more suited for the experiment?

    Also, I don't really know how I should implement the code in OS. I assume I need to get rid of the loop table and insert the inline_script item inside my sequence instead. I guess I don't need to set any repetitions number since the length of my numbers list equals the number of trials. But how should I loop over the numbers list to generate trials and how do I assign correct responses to the numbers? Do I need to use the var object?

    I would be grateful for any further suggestions.

  • Hi,

    I run the code a few times and every time it took 1-3 minutes to get a correct list of numbers

    That is probably because your restrictions are too strict. Like that, the while loop needs many iterations before it got a solution that works. You could either loosen the restrictions (mindist=4 should already help quite a bit, or adding more distractor digits). You could also prerun the trial generator before the experiment, so that you can amortize the run time of it, such that, in the experiment you can simply load the trials for an excel sheet or something like that.

    Also, I don't really know how I should implement the code in OS

    The inline script must occur before the trial loop (like once early in the block), then you have to empty the loop table, and add a trial counter if you want. In the trial loop itself, you can add another inline_script and extract the variables that you need. For example:

    var.stimulus = var.numbers[var.trial_counter]

    Then you can use the variable var.stimulus as if it was defined in a loop table.

    how do I assign correct responses to the numbers

    In the same script as where you generate the numbers, you could loop (for loop) over the numbers, check whether it is a three, set correct_response to whatever the correct response is, and to the incorrect response otherwise (all in a list). Then in the second inline_script, you can extract the correct response for each trial the same way as the stimulus.

    Hope this helps,

    Eduard

    Buy Me A Coffee

  • Yes, it did help! I implemented the code according to your instructions and it works perfectly fine. Thanks a lot!

    I have two more questions unrelated to the above issues.

    1. I looked at the csv log file and it seems like OS logs response times even if there was no response (for example if one trial lasts 1150 ms, I can see in the log file response times such as 1135, 1133, etc., and the response is 'None'). Should it be like that? It's quite confusing.
    2. I wanted to use psycho back-end since it's recommended for experiments requiring good timing (and with xpyriment I get huge delays). But when I use the psycho back-end, the text I display is not fully sharp (you can see that on the screenshot below). When I switch to the legacy back-end, it's all fine, so I might stick with it (interestingly, it seems like it might have even slightly better timing in my case). But I'm wondering what the issue with psycho back-end text could be. Any ideas? (the resolution in OS is set to 1920x1080, and I'm using 60Hz laptop screen, Win10).


  • Nice to hear!

    1

    That is rather normal. When you compute mean reaction times, you should exclude those trials that don't have a response. Opensesame just returns the maximal time that the trial lasted. It is a bit confusing, I agree, but a lot more robust to do it that way.

    2

    No idea! You could check out the psychopy forum to ask whether there are known issues with text rendering.

    Hope this helps,

    Eduard

    Buy Me A Coffee

  • Okay. Thank you for your help, Eduard!

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games