Welcome!

Sign in with your CogSci, Facebook, Google, or Twitter account.

Or register to create a new account.

We'll use your information only for signing in to this forum.

Supported by

Multiple blocks

Hello,

I want to divide an experiment into multiple blocks.
As visual stimuli from image file or csv file are imported into the program at first, they’re shuffled randomly. Then I want to divide them into multiple blocks such as 10 blocks keeping it the same number of stimulus in each block (20 stimuli in block1, 20 stimuli in block2...).

I found the function of design.block allows us to make a number of blocks we need, but Does Expyriment have any better way?

Thanks!

Comments

  • fladdfladd Posts: 69
    edited December 2016

    Hi rrr,

    maybe like this?

    import expyriment as xpy
    
    exp = xpy.design.Experiment()
    
    # Let's assume there is a variable 'stimuli' that is a list of 200 trials
    
    xpy.design.randomize.shuffle_list(stimuli)
    
    for counter, stim in enumerate(stimuli):
        if counter % 20 == 0:
            b = xpy.design.Block()
        t = xpy.design.Trial()
        t.add_stimulus(stim)
        b.add_trial(t)
        if counter % 20 == 19:
            exp.add_block(b)
    
    # 'exp.blocks' should now contain 10 blocks with 20 trials, each holding a single stimulus.
    

    Florian Krause (Developer)
    http://www.expyriment.org

  • rrrrrr Posts: 78

    Hello,

    It goes well, but how can I randomize completely all of trials throughout an experiment in the case of multiple factorial designs?
    When we want to have a two-way factorial design, the program as below runs without any errors but the order of trial is completely separated into two. The first half of trial results in factor 1, and the latter half does in factor 2.

    import expyriment
    
    exp = design.Experiment()
    
    # importing a list of 200 trials
    Factor1 = [s_list]
    design.randomize.shuffle_list(stimuli)
    
    Factor2 = [100, 200]
    
    for duration in Factor2:
        for counter, stim in enumerate(stimuli):
            if counter % 20 == 0:
                b = design.Block()
            t = design.Trial()
            t.set_factor("Factor1", stim)
            t.set_factor("Factor2", duration)
            t.add_stimulus(stim)
            b.add_trial(t)
            if counter % 20 == 19:
                block.shuffle_trials()
                exp.add_block(b)
    
  • rrrrrr Posts: 78

    I was able to divide an experiment into the multiple blocks with all shuffled trials as below, referring to your suggestion and the number classification task example of Expyriment.

    def run_trial(cnt, trial):
       #define a trial
    
    control.start(exp)
    
    for block in exp.blocks:
        for cnt, trial in enumerate(block.trials):
            if cnt % 20 == 0:
                instruction.present()
                exp.keyboard.wait()
            run_trial(cnt, trial)
    

    In this case, the blocks are divided just by inserting an instruction every 20 trial, so the data of block id are not saved in the file.

    Is there any way to save the block id?

Sign In or Register to comment.