Howdy, Stranger!

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

Supported by

[solved] Selective sampling... with a ratio!?!? Help please!

edited June 2013 in OpenSesame

Whilst I dislike melodrama such as I have typed in the title, I do need help (and this is not one that I will find the answer to in few minutes time...).

So here's the situation:

I have a collective resource of 100 word-pairs (split is: 60 not rhyming to 40 rhyming pairs), which I am aiming to use as an ongoing task. However I only want to use 50 of these per session, with pairs being 'randomly' selected every 2-3 seconds, whilst maintaining a 3:2 ratio for not rhyming to rhyming pairs. Oh, and individual pairs cannot be reused within a session (there will be 6 sessions overall, but this is somewhat irrelevant as the loop can be copied once written).

So essentially a session will consist of 50 word pairs (drawn from 100); 30 not rhyming and 20 rhyming. Being presented every 2/3 seconds. Psuedo-randomly of course!

At the moment I have: Loop --> sequence.... not very far at all.

Any help would be greatly appreciated - Please bear in mind I am oblivious to the world of programming languages...

Thanks!

Comments

  • edited 9:37AM

    ... Just as a postscript: I also realise that I will need to put the solution in a sketchpad item...

  • edited June 2013

    Hi Lee,

    To randomly draw samples containing only half of the 60 non-rhyming and 40 rhyming word pairs, and to combine the two into one randomised block list, you will need some Python inline scripting.

    For more info on the use Python inline code in OpenSesame, see:

    More specifically:

    1.) Append an inline_script item at the very beginning of your experiment where you define the complete list of non-rhyming and rhyming word pairs, for example by reading them from a .csv file. The two .csv files have to placed either in the file pool or in the same folder as your experiment.

    Place something like the following code in the Prepare-phase tab of the inline_script item (see comments for more information):

    # Read the lists of the 40 rhyming pairs and the 60
    # non-rhyming pairs from two separate .csv files.
    
    # Specify the paths to the files containing the pairs
    # by using the built-in OpenSesame function exp.get_file.
    # For more info, see:
    # http://osdoc.cogsci.nl/python-inline-code/experiment-functions/#experiment.get_file
    path_rhymes = exp.get_file("rhyme_pairs.csv")
    path_non_rhymes = exp.get_file("non_rhyme_pairs.csv")
    # We'll use the built-in Python module numpy to read our .csv file:
    # Import the module:
    import numpy as np
    
    # And load the text file.
    # For more info, see:
    # http://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html
    list_rhymes = np.loadtxt(path_rhymes, dtype = str)
    list_non_rhymes = np.loadtxt(path_non_rhymes, dtype = str)
    
    # Make the two lists global for future use:
    global list_rhymes, list_non_rhymes
    

    2.) Append an inline_script item at the very beginning of your block_sequence, where you will randomly draw two samples containing only half of the word-pairs from the original lists. Use something like the following code (in the Prepare-phase tab) to do so:

    # Randomise the from-the-csv-files-read lists
    # and draw two samples containing the necessary numbers of
    # rhymes and non-rhymes, respectively.
    
    # First, we randomise the lists using the function random.shuffle() from 
    # the built-in Python module random:
    # For more info, see:
    # http://docs.python.org/2/library/random.html#random.shuffle
    
    import random
    random.shuffle(list_rhymes)
    random.shuffle(list_non_rhymes)
    
    # We use the function random.sample()t to obtain two lists containing 
    # the desired number of rhyme-pairs and non-rhyme pairs.
    
    # The number of pairs per list list is equal to half of the 
    # number of pairs in the original list (i.e. 20 rhyme-pairs and
    # 30 non-rhyme-pairs).
    
    # For more info, see: 
    # http://docs.python.org/2/library/random.html#random.sample
    
    samples_rhymes = random.sample(list_rhymes,len(list_rhymes)/2)
    samples_non_rhymes = random.sample(list_non_rhymes,len(list_non_rhymes)/2)
    
    # Next, we merge the two lists to obtain one block list:
    block_list = samples_rhymes + samples_non_rhymes
    
    # Shuffle the new list:
    random.shuffle(block_list)
    
    # Finally, we make the block_list global for future use:
    global block_list
    

    3.) Append an inline_script item to the beginning of your trial_sequence to draw one word pair from the block list, without replacement (again, place the code in the Prepare-phase tab):

    # Determine the word pair of the current trial by drawing one word
    # pair from the previously-defined block list.
    
    # To avoid that some pairs are shown twice, and others never, we draw
    # the pairs without replacement by using the built-in Python function
    # pop():
    # For more info, see:
    # http://docs.python.org/2/tutorial/datastructures.html
    
    stim_pair = block_list.pop()
    
    # The pair is separated by a comma (because they come from a .csv
    # file). We split them by using the built-in Python function split():
    # For more info, see:
    # http://docs.python.org/2/library/stdtypes.html#str.split
    word1, word2 = stim_pair.split(",")
    
    # Finally, to make the variables word1 and word2 available in the GUI
    # (e.g. a sketchpad item), we use the built-in OpenSesame function
    # exp.set():
    
    # Now, we can use the square-bracket method to display the values of those
    # two variables in the sketchphad item.
    # For more info, see:
    # http://osdoc.cogsci.nl/usage/variables-and-conditional-qifq-statements/
    
    exp.set("word1", word1)
    exp.set("word2", word2)
    

    4.) Finally, set the appropriate number of cyles (in your case 50) in the block_loop and use the square-bracket method to display word1 and word2 in a sketchpad item.

    After applying this, your overview area should look something like this:

    image

    A working example experiment can be downloaded here (rename the extension from .txt into .opensesame.tar.gz and open as normally). Note that two .csv files with the appropriate names are assumed to be placed either in the file pool or in the same folder as your experiment.

    Please bear in mind I am oblivious to the world of programming languages...

    In order to program experiments like the one you're building now, I would strongly advise you to learn some Python. A good start:

    Best,

    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • edited 9:37AM

    Lotje,

    That is amazingly helpful, and I really appreciate you taking the time to reply.
    My Python-less-ness is because I'm quite new to this sort of thing (3rd year undergraduate 'mature' student) - it's actually for a final project for next year.

    Whilst I fully intend to become intimately acquainted with Python at some point, at the moment I find myself with more to do than time to do it in!

    Dank je wel,

    Lee

  • edited 9:37AM

    Hi Lotje,

    I've written the inline scripts and my program is identical to the code in your example.... only difference is that your example file works and mine tells me that I have AttributeError: 'numpy.ndarray' object has not attribute 'split'. Having read Byte I now get the terminology of the error but I have tried to find the root of the problem with no luck (after all the split happens in the trial script!) - the only thing that mine has that your doesn't is the rest of my experiment (i.e. instruction screens, countdown timers, 5 further experimental stages). They are all GUI objects and I don't believe that they should affect the inline script.

    Hopefully you have some thoughts? Or anyone?

    Thanks
    Lee

  • edited 9:37AM

    Hi Lee,

    Would it be possible to upload the spreadsheet you're using (for example on Dropbox or Filedropper, or simply by making a screenshot of it)?

    Also, could you either upload the full code of your experiment (via pastebin, for example) or paste the Python code from your inline_script items here?

    I'm sure we can figure out what's going on.

    Best,

    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • edited 9:37AM

    I have dropped you an email with the files in a .zip (I'm at work so it was the only way!)

    Thanks!

    Lee

  • edited 9:37AM

    Hi Lee,

    Thanks for your email! I can't see why this is going wrong either. However, when I simply open your .csv files in a text editor, resave them with the extension .txt, and change the corresponding piece of coding accordingly:

    path_rhymes = exp.get_file("rhyming_pairs.txt")
    path_non_rhymes = exp.get_file("non_rhyme_pairs.txt")
    

    everything works.

    If I find out why this is the case, I'll let you know. :)

    Best,

    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • edited 9:37AM

    Interesting! I was worried about a knock-on effect from one of the other elements. Hopefully this means that I can get it all working tonight.
    Just as an off topic query, you don't know where I might find 'spatial rotation resources' for experiments by any chance? I am fully prepared to make some, but it would be easier if there is some kind of cognitive-library-of-resources somewhere!

    Thanks!

    Lee

  • edited June 2013

    Hi Lee,

    No, sorry, I don't know about such a stimulus set...
    Good luck and let us know if you have more questions!

    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • edited 9:37AM

    Thanks Lotje, I certainly will :)

    Lee

  • edited June 2013

    It didn't take long :)

    I'm trying to relate the keyboard response 'm' to rhyming pairs and the keyboard response 'z' to non-rhyming pairs (as in the instructions for the block), here's what I have so far:

    http://pastebin.com/JmW4yH3Z

    Full code is here:

    http://pastebin.com/PbeekeyB

    This is probably simple fix but I'm not seeing the wood for the trees!

    Thanks,

    Lee

  • edited June 2013

    Hi Lee,

    Firstly, you should separate the allowed responses in the keyboard_response with a semicolon instead of a comma. So: m;z.

    Secondly, to determine whether a given stimulus pair comes from the rhyming or the non-rhyming list, and to define the corresponding correct response, you could use something like the following Python inline code:

    # Determine correct response, depending on whether the words come from 
    # the rhyming or the non-rhyming list:
    
    if stim_pair in list_rhymes:
        correct_keyboard_response = 'm'
    else:
        correct_keyboard_response = 'z'
    
    # Set the correct response by giving the built-in OpenSesame variable 
    # 'correct_response' a value:
    exp.set("correct_response", correct_keyboard_response)
    

    Good luck!

    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • edited 9:37AM

    It's amazing how clear things become after they are explained by an 'expert other' :)

    I did actually continue with my own efforts after posting, but it was fruitless as I tried to set 'list_rhymes' as a range and search for the stimulus in it... didn't work....

    However I am learning a lot through your helpful guidance! :D

    Thanks once more!

    Lee

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