List does not work - keeps using the last response

Hi all (this is half linked to my previous topic; I have solved all other issues, apart from this one - see here Resources needed: Dynamic Image Presentation (Tracking, Storing & Randomizing) - #12 by Hans).

I have an effort discounting experiment and want to keep track of the participants’ choices. Currently, this works like a charm. But it has a problem executing the last choice (no matter the code I put in there). I think the problem stems from having to keep RewardLevel and EffortLevel as pairs (since they can’t be separated to do this or the choice is incorrect).

See the code below for more information.

Code from Routine Game_1 - end Routine

experiment_data = pandas.read_excel('decisionsTrials.xlsx')
thisExp.addData('RewardLev', RewardLevel) 
thisExp.addData('EffortLev', EffortLevel)

Code from Routine Game_1 - end Routine

if Choice.keys == '2':
    Comb = [RewardLevel, EffortLevel]
    thisExp.addData('Comb', Comb)
elif Choice.keys == '1':
    Comb = [1, 1]
    thisExp.addData('Comb', Comb)

I have tried multiple things (and I don’t want to bore you with them all, but it includes using an empty list, etc.), and this code works (but it doesn’t compare against all the choices previously made—only the most recent, which is problematic). As I said, it stores the choices perfectly (see my screenshot at the end of this post).

What I want to achieve: Currently, it stores choices, so I want it to take all the choices made in that routine (/round) and pick the ‘best choice’, the pair with the lowest effort and highest reward.

In my Routine - end Routine (called Routine since this was an attempt to fix the issue)

if Comb[0] == 6:
    rl = 't6.png'
elif Comb[0] == 5:
    rl = 't5.png'
elif Comb[0] == 4:
    rl = 't4.png'
elif Comb[0] == 3:
    rl = 't3.png'
elif Comb[0] == 2:
    rl = 't2.png'
elif Comb[0] == 1:
    rl = 't1.png'

In my Routine - end Routine (same as above)

if Comb[1] == 2:
    el = 'b2.png'
    selected_rows = '10:21'
elif Comb[1] == 3:
    el = 'b3.png'
    selected_rows = '22:30'
elif Comb[1] == 4:
    el = 'b4.png'
    selected_rows = '31:39'
elif Comb[1] == 5:
    el = 'b5.png'
    selected_rows = '40:51'
elif Comb[1] == 6:
    el = 'b6.png'
    selected_rows = '52:60'
elif Comb[1] == 1:
    el = 'b1.png'
    selected_rows = '0:9'


Any help would be greatly appreciated or any ideas. :slight_smile:

I’m not sure I quite understand the question, but here is an answer anyway. Maybe it answers your question.

Begin Experiment

Comb = []
all_selections = ['0:9',10:21',22:30','31:39','40:51','52:60']
#Do you really have a gap row in your spreadsheet between selections of different lenghts?

Game_1 End Routine

if Choice.keys == '2':
    Comb.append([RewardLevel, EffortLevel])
elif Choice.keys == '1':
    Comb.append([1, 1])
thisExp.addData('Comb', Comb[-1])

MyRoutine - End Routine

rl = 't' + str(Comb[-1][0]) + '.png'
el = 'b' + str(Comb[-1][1]) + '.png' 
selected_rows = all_selections[Comb[-1][1]-1]
1 Like

What do you mean do i have a gap row in my spreadsheet? I thought because I want to include some text (0-9) and others (10-21), but don’t want to overlap them. Does this not work? Thanks for your help, I’ll see if that works.

Would you mind explaining why you add Comb[-1]? What does this do?

Edit - oh i think i understand what you did. So you have almost added the next combination into the list? is that correct?

I am going to try this. Will doing it stop it from recalling and using the last combination? I don’t want it to use the last pair (instead, I want it to view all pairs and pick the best one). Can I also add additional code to pick the ‘best choice’?

For example, I want the system to weigh over decisions as better (so then it picks those) - so if six is chosen during that iteration, it should be executed and so on (until 1 is the only thing picked). Similarly, I want to do this for the other side of the effort (which is the opposite). If 2 is chosen during that iteration, it should executed, and so on (6 and then 1 is the last to be executed if picked).

Does that make sense now? Sorry trying to explain it so you understand.

I’m on my phone so I may reply in stages.

To present the first 10 rows of a spreadsheet select 0:10.

To present the second 10 rows select 10:20.

It took me a while to get this right. The first number is the first row (counting from 0 for what is actually labelled row 2 in Excel). The second number is the last row +1.

X[-1] means the final item in list X.

To save the biggest/smallest values you would need to do some form of comparison each time.

E.g. minEffort =7 in Begin Experiment.

If current effort< minEffort: minEffort= current Effort.

Does that help?

1 Like

Yes. It makes perfect sense, thank you.

This code works here. If anyone wants to do what i did above.

In began experiment,

Comb_list =

End routine

if Choice.keys == ‘2’:
Comb_list.append([RewardLevel, EffortLevel])
elif Choice.keys == ‘1’:
Comb_list.append([1, 1])

thisExp.addData(‘Comb_list’, str(Comb_list))

In end of routine for my routine (before the actual time i need it).

best_comb = None
best_reward = float(‘-inf’) # Initialize to the lowest possible value
best_effort = float(‘inf’) # Initialize to the highest possible value

Evaluate each combination in Comb_list

for comb in Comb_list:
reward = comb[0]
effort = comb[1]

Criteria for the best combination (high reward, low effort)

if reward > best_reward or (reward == best_reward and effort < best_effort):
best_comb = comb
best_reward = reward
best_effort = effort

Determine el and selected_rows based on the best_comb

if best_comb:
all_selections = [‘0:9’, ‘10:21’, ‘22:30’, ‘31:39’, ‘40:51’, ‘52:60’]
rl = ‘t’ + str(best_comb[0]) + ‘.png’
el = ‘b’ + str(best_comb[1]) + ‘.png’
selected_rows = all_selections[best_comb[1] - 1]

Then end of routine

Comb_list =

1 Like

Obviously need to update the row selection. :slight_smile: