Howdy, Stranger!

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

Supported by

[solved] Randomizing conditions and trials using Python code

edited June 2013 in OpenSesame

Please help me figure out why my randomization script fails. The experiment consists of 3 blocks and each block includes 5 conditions with 12 files in each. I randomize blocks and conditions through open-sesame loop function, and I tried to randomize the files through Python script. It does all the randomization, but it only picks the first file from the list instead of going in order until it exhausts the list and switches to the next block. Please look over the script and tell me how I can patch this up.

Thanks!

This script is inserted at the first sequence with some commentary:

import random

global Conditions

global Blocks

Conditions is a dictionary in which the key is the specific condition and the values are the specifi stimuli pairs used in each trial

Conditions = {
'Far_Large_No': ['10-30', '10-40', '20-40', '20-50', '30-10', '30-50', '30-60', '40-10', '40-20', '40-60', '40-70', '50-20'],

'Far_Small_No' : ['1-3', '1-4', '2-4', '2-5', '3-1', '3-5', '3-6', '4-1', '4-2', '4-6', '4-7', '5-2'],

 'Close_Small_No' : ['1-2', '2-1', '2-3', '3-2', '3-4', '4-3', '4-5', '5-4', '5-6', '6-5', '6-7', '7-6'],

 'Close_Large_No' :['10-20', '20-10', '20-30', '30-20', '30-40', '40-30', '40-50', '50-40', '50-60', '60-50', '60-70', '70-60'], 

'Same_Same_Yes': ['1-1', '2-2', '3-3', '4-4', '5-5', '6-6', '7-7', '8-8', '10-10', '20-20', '30-30', '40-40', '50-50', '60-60', '70-70', '80-80']}

Blocks = ['Numbers', 'Dots', 'Mixed']

shuffle the pairs so they will be randomized during experiment

for cond in Conditions:

    random.shuffle(Conditions[cond])


This script is inserted at the trials loop which randomizes conditions and holds the trial sequence:

import string

global Conditions

global Blocks

global Stim

global theTrue

global cond

get information from the variables in the trial loop that indicate what type of trial comes next

print 'conditions', Conditions

distance = self.get('Distance')

size = self.get('Size')

block = self.get('Blocks')

catch = self.get('Catch')

print 'catch', catch

make a string that matches the filenames and store that name in Stim

cond = distance + '_' + size + '_' + catch

ctr1 = 0

ctr2 = 0

ctr3 = 0

ctr4 = 0

ctr5 = 0

Stim = ''

if cond == 'Far_Large_No':

    Stim = Conditions[cond][ctr1]; 

    val = Conditions[cond][ctr1];

    ctr1 = ctr1 + 1

if cond == 'Far_Small_No':

    Stim = Conditions[cond][ctr2]

    val = Conditions[cond][ctr2]

    ctr2 = ctr2 + 1

if cond == 'Close_Large_No':

    Stim = Conditions[cond][ctr3]

    val = Conditions[cond][ctr3]

    ctr3 = ctr3 + 1

if cond == 'Close_Small_No':

    Stim = Conditions[cond][ctr4]

    val = Conditions[cond][ctr4]

    ctr4 = ctr1 + 1

if cond == 'Same_Same_Yes':

    Stim = Conditions[cond][ctr5]

    val = Conditions[cond][ctr5]

    ctr5 = ctr5 + 1

Stim = block + '_' + cond + '_' + Stim

self.experiment.set('Stim', Stim)

print 'Stim', Stim

In the stimulus sketchpad set the inset image as '[Stim].png'
separate the values of the two numbers presented to decide what is the correct response

ind = val.find('-')

number1 = val[0:ind]

number2 = val[ind+1:]

number1 = int(number1)

number2 = int(number2)

if number1 > number2:

    theTrue = 'q'

elif number1 < number2:

    theTrue = 'p'

else:

    theTrue = 'space'

self.experiment.set('theTrue', theTrue)

Comments

  • edited 11:07PM

    Hi SillyNapalm,

    Could it be that you set the ctr[X] variables back to 0 at every trial? As I understand it, you want those to increment, right? So you might want to move the part where you set the ctr[X] variables to 0 to some place at the start of a block/ experiment (where exactly depends on what you want to do, of course).

    Hope this helps!

    Regards,
    Sebastiaan

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