Howdy, Stranger!

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

Supported by

Constrain Loop Randomization

Hi all,
I am programming an experiment in which i need to applied 2 different constrains to Loop randomization.
Specifically I want

1) Make repetitions of the same Condition(Joint or Solo) are separated by at least 5 cycles. I did it following the instructions here http://osdoc.cogsci.nl/3.1/manual/structure/loop/ and it works.
2) At the same time, I want make that the loop always start with a Condition = Joint cycle.

How do I implement the second constrain?

Thank you!

Comments

  • Hi Eris,

    The easiest way to accomplish this would be to simply start with loop of length 1 in which Condition is 'joint'. And then you have a second loop in which you have more trials, and in which you use pseudorandomization. Does that work?

    Cheers!
    Sebastiaan

  • Hi Sebastian,
    Let's say that yes in general it works, but not in my specific case.

    I am looking for a solution in python. I f I find it i will post it

  • Hi Sebastian,

    I've tried to use the contrain comand with mindist

    constrain Condition mindist=5.

    But it doesn't work. It could be to the fact that i am using phyton 3?

    Cheers

  • Hi Eris,

    The constrain command is not Python code, but OpenSesame script, which you need to add to the script of the loop item. You can see how this works (but with another command) in this screencast:

    Does that clear things up?

    Cheers!
    Sebastiaan


  • Hi Sebastian,
    Thanks for the video. But This is not what I need.
    I need the constrain command, which are explain in the manual

    I've tried both commands, here is what happens:
    1) with constrain Condition mindist=5 -> the experiment run, but it get stucked at the first item of the sequence. Note that it doesn't crush but it stucks

    2) with constrain Condition maxrep=5 -> the experiment run well but it doesn't constrain the randomization.So basically it's like the command is ignored.

    Here is a copy of my loop script. I can't upload the program 'cause there is an external device integrated.

    Thanks,
    Francesca

  • Hi Francesca,

    With two conditions (joint and solo) it is not logically possible to have a minimum distance of 5 between repetitions! That's why OpenSesame hangs: it's trying to figure out a solution, which doesn't exist, and it takes a while before a timeout occurs. (So it won't crash indefinitely.)

    So I would take a step back and formulate clearly for yourself what you're trying to accomplish exactly. Can you give an example of a loop table that meets your criteria?

    Cheers!
    Sebastiaan

  • Hi @sebastiaan,

    I'm posting here because that's exactly what I'm trying to accomplish in my experiment, too: I have 10 blocks as loops with items of different conditions, the order of which I constrained with mindist and maxrep. This works fine. Now I need to add another constrained, namely the same as the @Eris posted as constrain 2) above: Each block should start with condition = filler. And then proceed through the rest of the item list.

    You suggested to add another 1-item filler loop before the actual loop, right? But then I wouldn't be able to pick this first item randomly from the fillers, and my experimental structure is quite heavy already. Is there another way, maybe using the constrain command or a bit of code in the loop?

    I'd be happy for any advice!

    Best,

    Christin

  • Hi @schuetzin ,

    This is an interesting scenario. You cannot directly constrain the value of the first row, so you need some kind of workaround. What I would do is add an inline_script just before the loop that needs to be constrained. In the prepare phase of the script, do something like the code below. Basically, it adds a maxrep constraint programmatically and ensures that the first value for the condition column is 'A'. (The specific values and constraints of course depend on the experiment.)

    To make this work, you need to set the order of the loop to sequential and don't add any constraints or other operations to the loop itself.

    Do you see the logic?

    from pseudorandom import Enforce, MaxRep
    
    
    # Get the datamatrix from the to-be-constrained loop
    dm = items['constrained_loop'].dm
    # Create an Enforce object, and contrain the minimum distance for condition
    while True:
        ef = Enforce(dm)
        ef.add_constraint(MaxRep, cols=[dm.condition], maxrep=1)
        dm = ef.enforce()
        # To make sure the first condition is A, check it explicitly here, because
        # there is no corresponding costraint to implement this
        if dm.condition[0] == 'A':
            break
    print(dm)
    # Set the datamatrix from the to-be-constrained loop
    items['constrained_loop'].dm = dm
    

    — Sebastiaan

  • Great, this does the trick! I added some MinDist constraints after the MaxRep constraint and got the pseudorandomised order I need. Thank you so much.

Sign In or Register to comment.