Howdy, Stranger!

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

Supported by

[solved] How Can I do CPT(Continuous Performance Test) as semi randomy?

edited February 2015 in OpenSesame

Hi,

I try to conduct CPT test. İt have to be semi random. In this test, letters are presented 160 ms(there are 800 ms interval between letters).The participants should press the spacebar when see each"A"s following "Z"s. I want to present 250 stimuli, 50 of them must be A following Z, 50 of them any letter following Z. But they must be random. How can I set two lists which one of them will be picked up first letter and the other will be picked up second letter?

Thank you :)

Comments

  • edited December 2014

    Hi,

    I suggest following procedure:

    1) Create a list with 250 letters, 100 of which are "Z"s and the residual ones don't contain any "A"s (unless you want also to have "A"s in the sequence that don't follow "Z"s. If so, it gets a bit more complicated...)

    import random
    
    letters = [B...Y] # a list with all letters you want to pick from,
    # you probably have to  hardcode this
    
    sequence = [Z]* 100 # get your 100 Zs
    for letter in range(150):
        sequence.append(random.choice(letters) # fill the sequence 
    # with random letters
    random.shuffle(sequence) # randomize list
    
    

    2) Now pick random occurrences of "Z"s in the sequence and replace the following letter with an "A". Here some caution is appropriate, to avoid errors, like excluding the last element, don't change successive Zs, and so on

    counter = 0  # keep track of how many "A"s you've already included
    while counter != 50:
        index = random.randint(0,248) # exclude the last element in the list
        if sequence[index] == 'Z' and sequence[index+1] != 'Z': 
            # find a random Z, if the next letter is also a Z, there is a chance 
            # that you might destroy a Z-A configuration 
            # you had already established. Therefore, you pick 
            # only those Zs that are followed by another letter
            sequence[index+1] = 'A'
        counter += 1 # increment counter by one
    

    I think this should give you a list with 250 elements, of which 100 are Zs, of which 50 are followed by As, in a random order. Additionally, you could add another variable to store the information about what kind of type the current letter has (e.g., something followed by something, Z followed by something, Z followed by A). In doing so you are in full control of what every important information.

    Good luck and if you need more help don't hesitate to ask again.

    Eduard

    Buy Me A Coffee

  • edited 6:33PM

    Thank you very much for your answer.

    But I don't understand, I am sorry. I am very new at using opensesame. Should I set two list (one including letters from B to Y, the other including 100 Z )? I can't read the codes which you write. And I also need to"A"s don't follow "Z"s, but their amount is not important.

  • edited 6:33PM

    One list includes all letters which you want to appear potentially in the sequence, so change that in [A,...,Y] then, if you don't mind for random As.

    The other list is already the sequence with all stimuli you want. You can initialize it with the 100 Zs, because this what you already know about the sequence (It has to have 100 Zs). Then you have to add as many random "filler" letters as you need. So in the for loop you append (sequence.append) these letters that you randomly choose from the letter list(random.choice) until the entire list has 250 elements (100Zs and 150 other letters).
    To randomize the order in which the letters are presented, you have to shuffle the list (random.shuffle(sequence)).
    Then it is time to add the As. To do so, you have to select random Zs and replace the letter in the position after it with an A. When doing this, you have to watch out not to do something that destroys the order of the list. So for example if you randomly pick a Z that is in the last position of the sequence, you can't replace the next element with an A, because there is no other element. Also, let be there part of a sequence (Z-Z-A), where the Z-A part is one that you already created. If you now pick the first Z in another iteration, you would change the second Z to an A, so that you would end up with (Z-A-A) and one target pair less then you were heading for. You see?

    I hope the code gets clearer now. If not, you can still run it step by step and see what happens.

    Eduard

    Buy Me A Coffee

  • edited 6:33PM

    Thank you Eduard :)

    İs it possible to present full randomy? I mean , Can I do the randomization without adding As as manuel? I have an idea but I couldn't. I set two list in sequence. fist list included A-Z, (50 letters (one A, 20 Zs and filler letters), the other list included 20 letters 10As and 10 any letter (except A and Z). I want to present one letter from first list, one letter from second list respectively. I added response variable in the sequence and I write correct response (SPACE) accross to Z-A . But when one list is 50, the other is 20, I see blanks.

    image

  • edited January 2015

    Hi,

    Well, of course you can present fully random. All you have to do then is simply picking as many letters as you want randomly from a list with all letters you want to include. Just like so:

    import random
    letter_list = [ 'a','b','c']
    stimuli_list = []
    for letter in range(no_reps):
        stimuli_list.append(random.choice(letter_list))
    

    But of course, if you do this you have absolutely no control over the letter sequence whatsoever, that is, it is possible (though unlikely) that you even had no As at all.

    I am not entirely sure whether I get your idea. If you intend to end up with a list of 100 letters 20 of which are Zs, 10 of which are followed by As, it is a bit more work than what you suggest.
    In this case, I would recommend you create pairs of letters separately, merge them all into one list, shuffle this list and as a last step, you take the 2nd dimension out of it. Sounds complicated, but is actually rather easy. Here a guideline:


    import random letter_list = [b,c,d,...] excluding A and Z stimuli = [] target = ['Z','A'] for i in range(no_targets): stimuli.append(target) for i in range(no_z_without_A): Z_distractors = ['Z', random.choice(letter_list)] stimuli.append(Z_distractors) for i in range(rest_distractors): rest = [random.choice(letters),random.choice(letters)] stimuli.append(rest) random.shuffle(stimuli)

    Now stimuli is a list containing lists with letter pairs. Since you want only one flat sequence, you have to strip the inner lists. The way this works is by means of the itertools module. Have a look on this description.

    I hope this answers your question.

    Eduard

    Buy Me A Coffee

  • edited December 2014

    Thank You.
    I tought 20 Zs in one list and 10As, 10 other letters, because ı want to an balance. But your suggestion is excellent. I'm trying to learn inline script. I wrote the codes by looking yours and in the website which be your suggestion. But I think I couldn't, because the program is giving errors like that "code: list(chain(*(letter_list))
    exception type: IndentationError
    exception message:
    item: inline_script
    phase: prepare
    line: 14

    The codes that I wrote:

    import random
    
    letter_list = ['B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'İ', 'J', 'K', 'L', 'M', 'N', 'O', 'Ö', 'P', 'R', 'S','Ş', 'T', 'U', 'V', 'Y']*10
    
    stimuli = []
    
    target = ['Z','A']*60
    
    for i in range(240):
        stimuli.append(target) 
    
    for i in range(240):
        Z_distractors = ['Z', random.choice(letter_list)]
        stimuli.append(Z_distractors)
    
    for i in range(240):
       rest = [random.choice(letter_list),random.choice(letter_list)]
       stimuli.append(rest)
    from itertools import chain
       list(chain(*(letter_list))
       chain = itertools.chain.from_iterable([[Z_distractors],[letter_list],[target])
    random.shuffle(chain)
    
  • edited December 2014

    Hi,

    Change the lines

    from itertools import chain
       list(chain(*(letter_list))
       chain = itertools.chain.from_iterable([[Z_distractors],[letter_list],[target])
    

    into

    from itertools import chain
    list(chain(*(letter_list))
    chain = itertools.chain.from_iterable([[Z_distractors],[letter_list],[target])
    

    and the indentationError should be gone. Aside of this I recommend you browse for some conventions and rules how to organize your code. This will make it easier for you to read other people's code and see better why some errors occurred.

    Btw. I don't want to spoil all the "figuring it out by yourself" fun, but just that you know, your first for loop is running now 240 times adding each time 60 elements to your stimuli list, so 14400 targets in total, if I am not mistaken. This is probably not what you want.

    Good luck,

    Eduard

    Buy Me A Coffee

  • edited 6:33PM

    Okey, thank you for all of your help.

    The forums are for figuring all things out by ourselves ;)

    Best regards,

    Mine.

  • edited 6:33PM

    Me again :\">

    I couldn't achieve, asked for basic codes but these were told they are basic. I wrote this prepare side in inline script . But it didin't work. I decide 240 letter list in total which included 30 Z-A, 30 Z- any letter matches. The codes I wrote:

    import random
    letters = ['B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'Ç', 'Ş', 'V', 'Y', 'Ö', 'Ü', 'B', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'Ç', 'Ş', 'V', 'Y', 'Ö', 'Ü', 'B', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'Ç', 'Ş', 'V', 'Y', 'Ö', 'Ü', 'B','B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'Ç', 'Ş', 'V', 'Y', 'Ö', 'Ü', 'B','B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'Ç', 'Ş', 'V', 'Y', 'Ö', 'Ü', 'B','B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'Ç', 'Ş', 'V', 'Y', 'Ö', 'Ü', 'B', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'Ç', 'Ş', 'V', 'Y', 'Ö', 'Ü', 'B','I', 'K', 'L', 'M', 'N'] ---I WROTE ALL LİST (180 LETTER)

    sequence = ['Z']* 60--------30 FOR As, 30 FOR other letters except A
    for letter in range(180):
    sequence.append(random.choice(letters)---------I ADD SEQUENCE TO LETTERS
    random.shuffle(letters)

    counter = 0
    while counter != 30:
    index = random.randint(0,238)
    if sequence[index] == 'Z' and sequence[index+1] != 'Z':
    sequence[index+1] = 'A'
    counter += 1
    self.experiment.set("sequence", sequence)
    self.experiment.run()

    Thank you.

  • edited 6:33PM

    Hi,

    Would you mind, rephrasing what your actual problem is again? It is hard to see where on the way from your first post to the last one, you got stuck.

    Also, it would be great if you could use Markdown extra syntax to post code. This makes it a lot easier to understand what your code is actually doing.

    Thanks,

    Eduard

    Buy Me A Coffee

  • edited 6:33PM

    I'm so sorry, I wrote but didn't control. I tried to make your first suggestion. I want to realize continuous performance test, which included 240 letter, 30 of them must be As which follow Zs, 30 of them any letters except A which follow Zs. I realized that my other questions are just my confusion. I wrote this codes to prepare phase in inline script, but it didn't work.
    Could you correct my errors?

    Thank You.

    import random
    

    letters = ['B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'Ç', 'Ş', 'V', 'Y', 'Ö', 'Ü', 'B', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'Ç', 'Ş', 'V', 'Y', 'Ö', 'Ü', 'B', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'Ç', 'Ş', 'V', 'Y', 'Ö', 'Ü', 'B','B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'Ç', 'Ş', 'V', 'Y', 'Ö', 'Ü', 'B','B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'Ç', 'Ş', 'V', 'Y', 'Ö', 'Ü', 'B','B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'Ç', 'Ş', 'V', 'Y', 'Ö', 'Ü', 'B', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'Ç', 'Ş', 'V', 'Y', 'Ö', 'Ü', 'B','I', 'K', 'L', 'M', 'N'] ( # I WROTE ALL LİST (180 LETTER))

    sequence = ['Z']* 60
    for letter in range(180): 
        sequence.append(random.choice(letters)
        random.shuffle(letters)
    

    **(# 30 Zs FOR As, 30 Zs FOR other letters except A and I ADD THE Zs to letters, so they will be 240 letter in total)

    counter = 0 
    while counter != 30:
        index = random.randint(0,238)
        if sequence[index] == 'Z' and sequence[index+1] != 'Z': 
           sequence[index+1] = 'A' 
        counter += 1
    self.experiment.set("sequence", sequence)
    self.experiment.run()
    
  • edited 6:33PM

    Hey,

    As a general remark, being to debug your code is just as important as creating it (and mostly quite a bit more difficult). Therefore it is wise, to spend some time on learning on how you can track errors, understand and in best case fix them. Have a look on this small tutorial. There are many others out there, in case you need more/different information.

    Okay let's give it another try. You are pretty close already, but there is still a bug in your code:

    counter = 0 
    while counter != 30:
        index = random.randint(0,238)
        if sequence[index] == 'Z' and sequence[index+1] != 'Z': 
           sequence[index+1] = 'A' 
        counter += 1
    

    The variable counter in this setting is just counting the iterations of the while-loop, which is certainly not what you want. You want it to count how many 'A's have already been added. So, you have to move it into the if statement:


    counter = 0 while counter != 30: index = random.randint(0,238) if sequence[index] == 'Z' and sequence[index+1] != 'Z': sequence[index+1] = 'A' counter += 1 # ONE INDENTATION LEVEL DEEPER

    Next I assume you want to save the list. However, it is not necessary to do it explicitly, because saving a variable in an inline_script will automatically save the variable for later. Aside of this, using exp.set is only working, if the type of the variable is not a compound object. So it is working for integers, floats or strings, but will mess things up, if you pass it a list, dictionary, canvas object, etc...

    Finally, self.experiment.run() will start the current experiment object. However, this already happens by default, when you press the run button. Therefore, calling it again, will just restart it. What you want to do instead is adding a sequence that is repeated 240 times (the number of elements of your letter list) and in which each letter is presented and the response of the subjects is logged. Have a look on the step-by-step tutorial to learn how this is done.

    In the end, your experiment should have a similar structure like this one here:

    image

    I hope this clears things up.

    Good luck,

    Eduard

    Buy Me A Coffee

  • edited 6:33PM

    Thank you,

    When I tried to write the codes one by one, I noticed that after I wrote "for letter in range(180):" and I pressed the enter button it gives error. Could you explain me why it happens?

  • edited 6:33PM

    The reason for that is that for letter in range(180): is by itself no valid python command. A for statement always needs information concerning How often it has to do something, and what exactly something is. This is nothing you couldn't have found in the python documentation. Your programming would benefit a lot, if you tried to find the solution to your issues by yourself. Python is one of the best documented languages out there. It is hard to have an issue, that no one else has ever encountered

    What you have to basically, you have to add some action to perform, e.g.:

    for letter in range(180):
        print letter
    

    Best,

    Eduard

    Buy Me A Coffee

  • edited 6:33PM

    You'r right, believe me I really tired to find the solution from the forum. But these issues that I think they are related with my questions, are very complicated and don't include basic rules. I feel my questions too basic to you or questions in the forum. I'm studying programing but I'm in elementary. So, I can just write codes what you can write. When you give blanks I can't realize and beacuse of this reason I can't fill the blanks, I'm sorry.

    I write the codes that you suggested. İt works but when I execute the experiment I figured out that there is no Zs and As. Then I change the sequence, but I think it is ridiculous.

    sequence = ['Z', 'Z', 'Z', 'Z', 'Z','Z', 'Z', 'Z', 'Z', 'Z','Z', 'Z', 'Z', 'Z', 'Z','Z', 'Z', 'Z', 'Z', 'Z','Z', 'Z', 'Z', 'Z', 'Z','Z', 'Z', 'Z', 'Z', 'Z','Z', 'Z', 'Z', 'Z', 'Z','Z', 'Z', 'Z', 'Z', 'Z','Z', 'Z', 'Z', 'Z', 'Z','Z', 'Z', 'Z', 'Z', 'Z','Z', 'Z', 'Z', 'Z', 'Z','Z', 'Z', 'Z', 'Z', 'Z', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A','A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A','A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A']
    

    I also add the codes for the interval. For the stimulus duration I use sketchpad. I set the order as "inline script".

    interval = 795
    N = 240
    

    My trial part include structured list (15 letter). So, Should I put the inline script only to the experimantal phase. And the sketchpad in the experimantal phase must be empty.

  • edited 6:33PM

    Hi

    I feel my questions too basic to you or questions in the forum.

    Well, this doesn't really matter. If you have super basic questions, they're probably python specific, not opensesame. In this case, the forum is not the right place to look for information. Like I mentioned earlier the python documentation or google will serve you right. Don't feel bad, there is no shame in being a programming beginner, but the first thing that every programmer has to learn, is that it is very likely that someone already posted your question somewhere in the web. The trick is to find it.

    Regarding your new questions. I don't understand what the issue is now. However, you don't need to define N or interval in an inline_script. N is set in the loop item, and interval is set in sketchpad. This part of the tutorial explains quite thoroughly how to set the elements to draw.

    You can always play a bit with the various options to draw stuff and so on, i.e. pick one of the template experiments and try to vary settings and see how they'll effect the experiments. In this way, you can learn quite a lot.

    Good luck,

    Eduard

    Buy Me A Coffee

  • edited 6:33PM

    You'r right, I should wait until I learn programming. But my thesis don't wait any more, then I'll use a way without inline script. But, I'll go on learning pyhton untill I achieve to be a programmer. Unfourtunately, I'm not inborn :) Who knows, maybe all of you are so ;)

    Thank you, good by.

  • edited 6:33PM

    Actually, it's wasn't my intention to recommend stopping working on your paradigm.

    Good luck with your thesis.

    Eduard

    Buy Me A Coffee

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