Howdy, Stranger!

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

Supported by

[open] Simultaneously storing two Pseudo-probabilities

edited August 2014 in OpenSesame

Hello all, first of all thank you Sebastiaan & Co. for this wonderful nifty program and the community that comes with it :)>- . I have recently began to build experiments with probabilities and am stumped on how to keep two pseudo-probabilities at the same time. I will try to be as clear as possible, using a cat example.

There are two buttons, when clicking on the left button a picture of either a Male or Female cat will appear, the same for the right button.

-However, the left button has a .75 probability of displaying the same gender of cat on subsequent trials as the previous trial (if male -> .75 it is male once left button is selected again and .25 it is female, if next trial is female(.25) then -> .75 female, .25 male for next trial etc. repeating throughout depending on which gender cat is [pseudo]randomly selected)

-Simultaneously, the right button has a .25 probability of displaying the same gender of cat on subsequent trials as the previous trial (if male -> .25 it is male once right button selected again and .75 it is female. following the same pattern as the other button but with inverted probabilities)

The trouble I am having: Having the male or female cats being selected from the picture pool with the (2)probabilities changing. I assume I have to create a list and store the previous probability and then retrieve that specific probability (either 1 or 2) corresponding to the buttons.

Let me know if I am not being clear, or if I am going about the methods all wrong. I appreciate feedback, thank you for reading.

-Felix

Comments

  • edited 6:43PM

    Hi Felix,

    That's an interesting problem, with many possible solutions. Here's one:

    First, at the start of the experiment, you assign a starting probability of a male cat. You can do this with a simple inline_script like this (in the prepare phase):

    # Starting probability of showing a male cat
    p_male = .5
    

    Next, at the start of each trial, you choose a male or a female, based on this probability. If you have chosen a male, you set p_male to 1 (i.e. a male for sure), otherwise to 0 (i.e. certainly no male). You also set the experimental variable gender, which you can use to select the appropriate pictures from the file pool (e.g. cat_[gender]_1.png in OpenSesame script). This should be in the prepare phase of an inline_script at the start of a trial.

    import random
    # random.random() gives a random float between 0 and 1
    if random.random() <= p_male:
        p_male = 1
        exp.set('gender', 'male')
    else:
        p_male = 0
        exp.set('gender', 'female')
    

    Finally, after you have collected a response, you re-determine p_male, based on whether a switch is likely or not. This should be in the run phase of an inline_script at the end of a trial.

    # In this example, a left response means probably switch and a right
    # response means probably stay. This should be changed depending
    # on what kind of responses you collect.
    if self.get('response') == 'left':
        switch_likely = True
    elif self.get('response') == 'right':
        switch_likely = False
    else:
        raise Exception('Invalid response!')
    
    # If a switch is like, we subtract the current p_male, which is always 0 or 1
    # from .75, and take the absolute value. This works, because
    # abs(.75-0) == .75 -> From certainly no male to probably male
    # abs(.75-1) == .25 -> From certainly male to probably no male
    if switch_likely:
        p_male = abs(.75-p_male)
    # ... and analogously for a probable stay...
    else:
        p_male = abs(.25-p_male)
    
    # Some debugging output to make sure that things work as expected
    print '%s, %f' % (switch_likely, p_male)
    

    Does that make sense? If think (something like) this should work.

    Cheers!
    Sebastiaan

  • edited 6:43PM

    Yes! that does indeed make sense, I will implement it asap.

    Thank you for the help

Sign In or Register to comment.