# How to change the correct answer based on position of stimuli

Hi everyone! I’m trying to set up an experiment for my research project and have been stuck on something for a while. I’ll explain a bit here…

Basically the premise is that participants are presented with a picture of fruit (e.g., apple), then can press either L or R, with one key being rewarded (they are shown a same or different fruit) and the other not (they are shown an empty box). The different types of fruit are in a conditions file so they are looped through randomly and there are two different outcome loops (one for outcome and one for no outcome). This is working fine and was achieved as shown in the screenshots below.

• e.g., apple → presses L → watermelon + “Reward = 5 points!”
apple → presses R → empty box + “No reward!”

For the next stage, at the beginning of each block, the participants are presented with a screen containing all of the fruit outcomes (note the outcomes, not the stimuli, as I’m trying to see whether they have learnt the outcomes too), but two of the fruits are circled. The positions of the outcome fruits are set on the screen in this part of every block, but the circles loop randomly through combinations of positions, as decided by the conditions file labelled “circlepositions” (screenshot of this below) with one circle being assigned to a position in the “position1” column and the other “position2”. This is working fine.

The circles indicate that if, in this block, they respond to the stimuli fruit that correspond to the circled outcome fruit, with the previously incorrect key, they will be rewarded double. If the corresponding outcome fruit was not circled, the outcome is the same as in the first part of the experiment.
-e.g., if the apple is circled…
apple → presses L → watermelon + “Reward = 5 points!”
apple → presses R → watermelon + “Reward = 10 points!”

• e.g., if the apple is not circled…
apple → presses L → watermelon + “Reward = 5 points!”
apple → presses R → empty box + “No reward!”

I therefore have three different outcomes: standard outcome, upvaluation (double) outcome and no outcome. I can’t seem to work out how to make it so that the key labelled as incorrect in the conditions file can lead to the upvaluation reward outcome only for the fruit that are circled.

One thing I tried was the following code that used the equivalence of positions of outcome fruit and circles, repeated for all outcomes (and therefore stimuli).

if response.corr:
reward = ‘Reward = 10 points!’
upvaluationoutcome = 0
yesstandardoutcome = 1
nostandardoutcome = 0
elif response.corr == 0 and watermelon_upvaluation.pos == circle.pos in upvaluation_values and upvaluation_image == apple.png:
reward = ‘Reward = 20 points!’
upvaluationoutcome = 1
yesstandardoutcome = 0
nostandardoutcome = 0
elif response.corr == 0 and watermelon_upvaluation.pos == circle2.pos in upvaluation_values and upvaluation_image == apple.png:
reward = ‘Reward = 20 points!’
upvaluationoutcome = 1
yesstandardoutcome = 0
nostandardoutcome = 0
elif response.corr == 0 and watermelon_upvaluation.pos != circle.pos in upvaluation_values and watermelon_upvaluation.pos == circle2.pos in upvaluation_values and upvaluation_image == apple.png:
reward = ‘No reward!’
upvaluationoutcome = 0
yesstandardoutcome = 0
nostandardoutcome = 1
elif response.corr == 0 and response.corr != None:
reward = ‘Too slow!’
upvaluationoutcome = 0
yesstandardoutcome = 0
nostandardoutcome = 1

But this came back with the error… “ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()”.

One thought I had was, in the initial screen with all the outcome fruit, to open a file and write something in it if the position of the outcome fruit is equal to one of the circles, then read this file in each trial to change the change the outcome. However, I wasn’t sure how to form an IF statement relating the positions of the two stimuli together as using “watermelon_upvaluation.pos == circle.pos” doesn’t work (the images of the watermelon and circle and labelled as “watermelon_upvaluation” and “circle” in builder).

If anyone has any ideas to help it would be much appreciated!!

Hi @sofiepro,

This sounds like a neat paradigm!

This looks like part of the if-statements are accessing an array/list, which means it can’t determine if the if-statment is true or false.

``````elif response.corr == 0 and watermelon_upvaluation.pos != circle.pos in upvaluation_values and watermelon_upvaluation.pos == circle2.pos in upvaluation_values and upvaluation_image == apple.png
``````

`object.pos` variables such as `circle.pos` are arrays in the form of [x,y] so == and != won’t work.
For ==, try:

``````np.all(object_1.pos == object_2.pos)
``````

For !=, try:

``````np.all(object_1.pos != object_2.pos)
``````

np.all() is a function that comes from the numpy library and lets you check if all elements in an array/list are matching.

Also, the `in upvaluation_values` parts of the if-statments might not be necessary, but I’m not too sure.

Hope that helps,
-shabkr

see Stack Overflow’s thread on a.any() or a.all() for more details

P.S. You can make “code blocks” by surrounding text with three back-ticks ```. It makes long code a little easier to read.
E.g.
```
for i in range(0,10):
do x
```
becomes

``````for i in range(0,10):
do x
``````

Hi @shabkr ,

I realised that I never thanked you for your response which I am very grateful for! It managed to fix some of the coding so that the experiment no longer quit when I tried to run it :))

I found that I had some other problems within the experiment that meant the trials weren’t running as hoped, so I ended up finding a way to make it more concise in the process. I thought you might be interested in how I achieved that (and it may also help others who have a similar problem) so I’ll put the coding below.

``````# set of mappings
upval_stim_pairings = {"apple.png": watermelon_upvaluation, "grapes.png": cherry_upvaluation, "pear.png": pear_upvaluation, "banana.png": banana_upvaluation, "orange.png": pineapple_upvaluation, "pineapple.png": orange_upvaluation }

# look up the mapping corresponding to Stimulus
upval_fruit = upval_stim_pairings[ Stimulus ]
circle1_matches = np.all( circle1.pos  == upval_fruit.pos )
circle2_matches = np.all( circle2.pos == upval_fruit.pos )

if upvaluation_response_2.corr:
reward = 'Reward = 10 points!'
upvaluationoutcome = 0
yesstandardoutcome = 1
nostandardoutcome = 0

elif (upvaluation_response_2.corr == 0 and upvaluation_response_2.keys == None  ):
reward = 'Too slow!'
upvaluationoutcome = 0
yesstandardoutcome = 0
nostandardoutcome = 1

elif (circle1_matches and upvaluation_response_2.corr == 0 and upvaluation_response_2.keys != None):
reward = 'Reward = 20 points!'
upvaluationoutcome = 1
yesstandardoutcome = 0
nostandardoutcome = 0

elif (circle2_matches and upvaluation_response_2.corr == 0 and upvaluation_response_2.keys != None):
reward = 'Reward = 20 points!'
upvaluationoutcome = 1
yesstandardoutcome = 0
nostandardoutcome = 0

elif (circle1_matches == 0 and circle2_matches == 0 and upvaluation_response_2.corr == 0 and upvaluation_response_2.keys != None):
reward = 'No reward!'
upvaluationoutcome = 0
yesstandardoutcome = 0
nostandardoutcome = 1
``````
1 Like