-
Notifications
You must be signed in to change notification settings - Fork 4
Separate the lottery evaluation and trial selection + other improvements #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| % Want a function which, given an input argument of the block number, | ||
| % returns the condition of that block (medical or monetary) and the block's | ||
| % beneficiary (self or other). | ||
|
|
||
|
|
||
| function [ uniqueIdx ] = getOneBlockPerCondition(blocks) | ||
|
|
||
| % adding paths? | ||
| addpath(genpath('./lib')); | ||
| addpath(genpath('./tasks/SODM')); | ||
|
|
||
| % blocks and numBlocks | ||
| numBlocks = length(blocks); | ||
|
|
||
| payoffKinds = cell.empty; | ||
| beneficiaries = cell.empty; | ||
|
|
||
| % iterate through the blocks | ||
| for blockIdx = 1:numBlocks | ||
| subsetofblocs = blocks{blockIdx}; | ||
| conditions = subsetofblocs.conditions; | ||
|
|
||
| payoffKinds{blockIdx} = conditions.payoffKind; | ||
| beneficiaries{blockIdx} = conditions.beneficiary; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The way to generalize that for tasks with different kinds of conditions would be to a) poll fieldnames in |
||
| end | ||
|
|
||
| % make it into a table | ||
| blockTable = table(payoffKinds', beneficiaries'); | ||
|
|
||
| % grab the unique indices to uniqueIdx | ||
| [~, uniqueIdx, ~] = unique(blockTable); | ||
|
|
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| function [outcomeKind, outcomeLevel] = showTrialEvaluation(trial, config) | ||
| % Allow users to call this function from wherever they want | ||
| % Be able to receive the trial specification, block configuration. | ||
|
|
||
| % Evaluate the trial: adapted lines 92-end of pickAndEvaluateTrial. | ||
| %% 2. Evaluate the trial | ||
| % summary = experimentSummary(block, blockIdx, trialIdx); | ||
| [ outcomeKind, outcomeLevel, outcomeColorIdx, trueProb, randDraw ] = evaluateTrial(trial); | ||
|
|
||
| %% 3. Draw the trial | ||
| % 0. Open PTB window if it isn't yet opened (`isempty(Screen('Windows'))`) | ||
| standalone = false; | ||
| if isempty(Screen('Windows')) | ||
| standalone = true; | ||
| config = loadPTB(config); | ||
| config.runSetup.textures = loadTexturesFromConfig(config); | ||
| end | ||
|
|
||
|
|
||
| % 1. Use drawLotto and drawRef to show the lotto | ||
| config.task.fnHandles.bgrDrawFn(config, trial); | ||
| drawLotto(trial, config); | ||
| config.task.fnHandles.referenceDrawFn(config, trial); | ||
| Screen(config.device.windowPtr, 'Flip'); | ||
| % 2. Disappear the non-picked choice | ||
| WaitSecs(5); | ||
| switch trial.choseLottery | ||
| case 0 | ||
| config.task.fnHandles.referenceDrawFn(config, trial); | ||
| msg = 'You chose the certain option.'; | ||
|
|
||
| case 1 | ||
| windowPtr = config.device.windowPtr; | ||
| % Determine message to display | ||
|
|
||
| % For monetary gamble | ||
| if strcmp(config.runSetup.blockName, "Monetary") == 1 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will not work on Matlab versions prior to 2016b be — don't ask me why, but Matlab was very strict that strings are denoted by apostrophes, not by quotes. Also, note that this code doesn't create a basecase for a block whose name is neither monetary nor medical, which means that it will fail hard in those cases. |
||
| lookupTbl = config.runSetup.lookups.txt; | ||
| message = textLookup(outcomeLevel, lookupTbl, windowPtr); | ||
| msg = 'You chose the gamble. Random draw got you '; | ||
| msg = [msg message]; | ||
| end | ||
|
|
||
| % For medical gamble | ||
| if strcmp(config.runSetup.blockName, "Medical") == 1 | ||
| lookupTbl = config.runSetup.lookups.txt; | ||
| message = textLookup(outcomeLevel, lookupTbl, windowPtr); | ||
| msg = 'You chose the experimental treatment. The final result was '; | ||
| msg = [msg message]; | ||
| end | ||
|
|
||
| % (3. Re-paint lottery with true probability layout | ||
|
|
||
| if trial.ambigs > 0 | ||
| trial.ambigs = 0; | ||
| trial.probs = trueProb; | ||
| end | ||
| drawLotto(trial, config); | ||
| % 4. Draw a line through the chosen random number | ||
| % 5. Highlight the winning amount) | ||
| otherwise | ||
| msg = 'No choice made in this trial.'; | ||
| end | ||
| Screen(config.device.windowPtr, 'Flip'); | ||
|
|
||
| % 6. Display the final outcome | ||
| WaitSecs(1); | ||
| if trial.choseLottery == 0 | ||
| config.task.fnHandles.referenceDrawFn(config, trial); | ||
| elseif trial.choseLottery == 1 | ||
| drawLotto(trial, config); | ||
| end | ||
| txtDims = getTextDims(config.device.windowPtr, msg); | ||
| xDim = config.device.screenDims(3)/2 - txtDims(1)/2; | ||
| yDim = config.device.screenDims(4) - 100; %moved text up from bottom of screen | ||
| DrawFormattedText(config.device.windowPtr, msg, xDim, yDim, [200 200 200]); | ||
| Screen(config.device.windowPtr, 'Flip'); | ||
| disp(randDraw); | ||
|
|
||
| % 7. Wait for keypress | ||
| waitForKey(config.device.breakKeys, 5); | ||
|
|
||
| % 8. If this was a one-off show, close screen | ||
| if standalone | ||
| unloadPTB(config); | ||
| end | ||
| end | ||
|
|
||
| function [ outcomeKind, outcomeLevel, outcomeColorIdx, trueLotteryProb, randomDraw ] = evaluateTrial(trial) | ||
| % EvaluateTrial Given a trial row, evaluates it. | ||
| if trial.choseLottery == 0 | ||
| outcomeKind = 'Reference'; | ||
| outcomeLevel = trial.reference; | ||
| trueLotteryProb = NaN; | ||
| randomDraw = NaN; | ||
| outcomeColorIdx = []; | ||
| else | ||
| % Conduct lottery | ||
| ambig = trial.ambigs; | ||
| if ambig > 0 | ||
| minProb = (1 - ambig) / 2; | ||
| trueLotteryProb = round(minProb + ambig * rand, 2); | ||
| else | ||
| trueLotteryProb = trial.probs; | ||
| end | ||
|
|
||
| randomDraw = rand; | ||
| if randomDraw <= trueLotteryProb | ||
| outcomeKind = 'Win'; | ||
| outcomeLevel = trial.stakes; | ||
| outcomeColorIdx = trial.colors; | ||
| else | ||
| outcomeKind = 'Loss'; | ||
| outcomeLevel = trial.stakes_loss; | ||
| outcomeColorIdx = 2 - (trial.colors - 1); % FIXME: Ugly hack, assumes only two colors indexed 1 and 2 | ||
| end | ||
| randomDraw = round(randomDraw, 2); | ||
| end | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| function [trial, config] = SODM_pickTrials(data) | ||
|
|
||
| % ugly hack? | ||
| config = data.blocks{end}.config; | ||
|
|
||
| % Show that trials have ended and lottery evaluations are about to begin | ||
| msg = 'Trials have ended. Please wait for the experimenter.'; | ||
|
|
||
| windowPtr = config.device.windowPtr; | ||
| txtDims = getTextDims(config.device.windowPtr, msg); | ||
| xDim = config.device.screenDims(3)/2 - txtDims(1)/2; | ||
| yDim = config.device.screenDims(4) - 20; | ||
|
|
||
| DrawFormattedText(config.device.windowPtr, msg, xDim, yDim, [200 200 200]); | ||
| Screen('flip', windowPtr); | ||
|
|
||
| waitForKey(config.device.breakKeys); %experimenter presses 5 to continue | ||
|
|
||
| % go thru indices, pick trial and config | ||
| for index_block = getOneBlockPerCondition(data.blocks)' | ||
| block = data.blocks{index_block}; | ||
| trialIdx = randi(height(block.data)); | ||
| trial = block.data(trialIdx, :); | ||
| trial.refSide = 1; | ||
|
|
||
| config = block.config; | ||
|
|
||
| % want to evaluate showLotteryEvaluation for each of the four trials | ||
| showTrialEvaluation(trial, config) | ||
|
|
||
| % After receiving prompt, begin (next) lottery: | ||
| waitForKey(config.device.breakKeys); | ||
|
|
||
| end | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, just noticed this — this does not describe the function at all. (Or rather, it describes lines 23 and 24 of the function.)