#### Howdy, Stranger!

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

Supported by

edited February 2014

Firstly, I would like to say Thank you for this awesome software.

Please bare with me, I am absolutely newbie for Opensesame. I have adapted python code from a technician at my uni. to suit my project (2- and 3- back tasks). The syntax for 2- and 3-back tasks are as follow.

from numpy.random import randint, shuffle
from itertools import chain
from copy import copy

# generate stimulus list
# 1: create list of target letters (equal target prob each letter)
n = 2 # 2-back
Ntargets = 24
letters = ['K','B','C','D','T','F','G','H']
SLt = letters*(Ntargets/8)
for i in range(10000):
shuffle(SLt)

# 2: create sequence & place target letters in it
listStimType = [ [['Standard'] + ['Target']] for i in range(Ntargets) ]
listStimType = list(chain(*listStimType))

listStim = [ [[''] + [t]] for t in SLt ]
listStim = list(chain(*listStim))

# 3: expand standards according to ITI
SLs = [randint(3,9) for i in range(Ntargets) ]
listStimType = [ [listStimType[i][0]]*SLs[i] + [listStimType[i][1]] for i in range(Ntargets) ]
listStimType = list(chain(*listStimType))

listStim = [ [listStim[i][0]]*SLs[i] + [listStim[i][1]] for i in range(Ntargets) ]
listStim = list(chain(*listStim))

# 4: expand targets according to n in n-back
for i in range(len(listStim)-n):
if listStimType[i+n] == 'Target':
listStim[i] = listStim[i+n]

# 5: assign remaining letters according to degrees of freedom
# do first couple

def sample(letters, listStim, n, i):
global randint, copy
x = copy(letters)
for takeOut in range(1,n+1):
try:
x.remove( listStim[i+takeOut] )
except ValueError: pass
return x[ randint(0, len(x)) ]

for i in reversed(range(len(listStim)-n)):
if listStim[i] == '':
listStim[i] = sample(letters, listStim, n, i)
else: continue

# export variables
self.experiment.items['trial_loop'].repeat = len(listStimType)
self.experiment.id = 0
self.experiment.listStimType = listStimType
self.experiment.listStim = listStim
self.experiment.isPrac = 1

from numpy.random import randint, shuffle
from itertools import chain
from copy import copy

# generate stimulus list
# 1: create list of target letters (equal target prob each letter)
n = 3 # 3-back
Ntargets = 24
letters = ['Q','B','C','D','N','F','G','H']
SLt = letters*(Ntargets/8)
for i in range(10000):
shuffle(SLt)

# 2: create sequence & place target letters in it
listStimType = [ [['Standard'] + ['Target']] for i in range(Ntargets) ]
listStimType = list(chain(*listStimType))

listStim = [ [[''] + [t]] for t in SLt ]
listStim = list(chain(*listStim))

# 3: expand standards according to ITI
SLs = [randint(3,9) for i in range(Ntargets) ]
listStimType = [ [listStimType[i][0]]*SLs[i] + [listStimType[i][1]] for i in range(Ntargets) ]
listStimType = list(chain(*listStimType))

listStim = [ [listStim[i][0]]*SLs[i] + [listStim[i][1]] for i in range(Ntargets) ]
listStim = list(chain(*listStim))

# 4: expand targets according to n in n-back
for i in range(len(listStim)-n):
if listStimType[i+n] == 'Target':
listStim[i] = listStim[i+n]

# 5: assign remaining letters according to degrees of freedom
# do first couple

def sample(letters, listStim, n, i):
global randint, copy
x = copy(letters)
for takeOut in range(1,n+1):
try:
x.remove( listStim[i+takeOut] )
except ValueError: pass
return x[ randint(0, len(x)) ]

for i in reversed(range(len(listStim)-n)):
if listStim[i] == '':
listStim[i] = sample(letters, listStim, n, i)
else: continue

# export variables
self.experiment.items['trial_loop'].repeat = len(listStimType)
self.experiment.id = 0
self.experiment.listStimType = listStimType
self.experiment.listStim = listStim
self.experiment.isPrac = 1

It has been working quite well - However, I have found two problems that I could not change proportion of target to stimuli from 15.48% to 25% and importantly, one letter disappears on the screen and output for 2-back task, also two letter disappears on the screen and output for 3-back.

It would be very appreciated if you could shed some light on these issues.

Cheers!!

• edited 11:55AM

Hi Bentley,

These scripts are so complicated that they inspire me, or probably anyone else, with very little desire to try to understand them! I think if you want to modify them, you're better off asking the technician who wrote them initially.

Alternatively, we could take a step back and see whether the paradigm can be implemented in a more straightforward way. In principle, there is nothing terribly complicated about an N-back task, and it's something that a lot of other people would be interested in as well.

Could you provide some details about what kind of paradigm you're trying to implement exactly?

Cheers,
Sebastiaan

• Hey guys, has anyone in the meantime been able to implement the N-back task?

• I have a sketchpad-target element, displaying a digit (variable name: target_digit)and a response_key element for correcting the right response. I need to write a line in the correct response field (set correct_response) which tells OpenSesame to press a key (e.g. Enter or "s") if and only if the same digit appeared N times ago. I am not very familiar with Python and since I have to run an experiment employing N back next week, I'd be extremely grateful if anyone could help!

• Hi all,

I also need to use the n-back task for my study, but I'm not sure how to even begin to build it.

If anyone has a working version of it and would be willing to share, I would greatly appreciate it.

@bentley @Daxide --maybe your efforts have been successful?

Kyriaki

• Hi Kyriaki,

You can check other discussion and the experiments that are linked there.

For example:

Those versions won't work out of the box as they were written for older versions of Opensesame, but at least they should give you an idea about how to approach the problem.

Hope this helps,

Eduard

ps. if you are still unfamiliar with Opensesame, I recommend you do one or more of our tutorials. That's the best way to understand the software and by doing so getting inspiration for your own paradigm.

• Hi Eduard,

Looking back through those discussions helped.

Many thanks,

Kyriaki