Howdy, Stranger!

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

Supported by

[open] Cumultative Chance for a random event

edited June 2013 in OpenSesame

Hello Henrik again,

I wanted to know if there is a possibility to get a cumultative chance that a random event occurs.

Like the first time its 10% that the event during a trial occurs. If it doesnt occur the chance raises by 10%. So the second time the chance that it occurs is 20%.
If it doesnt occur again it goes up to 30% and so on. If it occurs the chance drops down to 10% for the next time trial.

So lets give an example:

Any time you make a choice, there is the chance that a random event happens. If you decide to take the car to get to a certain location, there is the chance to get in a traffic jam. Each time you choice the car i want it to get more likely that you end up in a traffic jam. Is there any chance to modul that?

Best regards,

Henrik

Comments

  • edited June 2013

    Hi Henrik,

    Sure, with a bit of scripting this type of thing can be implemented quite easily. However, it seems that you're describing two different scenarios:

    • The probability of an event is contingent on whether the event occurred before. (First example.)
    • The probability of an event is contingent on how often another (non-random) event has occurred before. (Traffic-jam example.)

    What exactly do you want to do?

    Cheers,
    Sebastiaan

  • edited 10:14PM

    Hi sebastiaan,

    Oh I see the problem, my bad. I want the first example. A random event that occurs with increasing chances depending on wether or not it has occured before.

    Best regards,

    Henrik

  • edited 10:14PM

    Ah, I see. Basically, you will want to maintain a variable, let's called it [prob], that specifies the probability that an event occurs. Each time that you determine (randomly) whether the event actually occurs, [prob] decreases when it does, and increases when it doesn't, as in the script below:

    from random import random
    
    # random() returns a number between 0 and 1
    # so this sets `event_occurs` to True or False
    # with a probability of [prob].
    prob = self.get('prob')
    event_occurs = random() < prob
    
    # If the event does not occur, increase the
    # probability for the next time, but not
    # higher than 1.
    if not event_occurs:
        prob += .1
        if prob > 1:
            prob = 1
    # If the event does occur, decrease the probability,
    # but not below 0.
    else:
        prob -= .1
        if prob < 0:
            prob = 0
    
    # Store [prob] and [event_occurs]
    exp.set('prob', prob)
    exp.set('event_occurs', event_occurs) # Will be set to 'yes' or 'no'
    

    This script assumes that [prob] has some kind of starting value. And, of course, it depends on the experiment what the logic will be, and how the variable [event_occurs] is used. But in general, this should get you started.

    Here you see the script in the context of a working dummy experiment:

    Cheers!
    Sebastiaan

Sign In or Register to comment.