Skip to content

Commit

Permalink
study3 upload
Browse files Browse the repository at this point in the history
Matlab scripts of study 3 of my PhD thesis. Refer to main and main_f for no feedback and feedback experiments.
  • Loading branch information
chri4354 authored Oct 31, 2017
1 parent f738ecf commit 7cdd2c7
Show file tree
Hide file tree
Showing 32 changed files with 2,129 additions and 0 deletions.
4 changes: 4 additions & 0 deletions add_responseinstr.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
%add response istructions
Screen('TextSize', Sc.window, 13);Screen('TextFont', Sc.window, 'Myriad Pro');
DrawFormattedText(Sc.window, instr{1}, 'center', (Sc.size(2)).*cfg.bar.positiony+80, 0);
DrawFormattedText(Sc.window, instr{2}, 'center', (Sc.size(2)).*cfg.bar.positiony+110, 0);
9 changes: 9 additions & 0 deletions add_responseinstr_.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
% This script was executed in study3 under the name of add_responseinstr.m
% I changed the name in order to run study3f so that the main script could
% run the add_responseintr.m script in /myfunctions
% 17.04.2015

%add response istructions
Screen('TextSize', Sc.window, 13);Screen('TextFont', Sc.window, 'Myriad Pro');
DrawFormattedText(Sc.window, instr{1}, 'center', (Sc.size(2)).*cfg.bar.positiony+80, 0);
DrawFormattedText(Sc.window, instr{2}, 'center', (Sc.size(2)).*cfg.bar.positiony+110, 0);
38 changes: 38 additions & 0 deletions agreement_functions.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
clear all
close all

addpath(genpath('C:\Users\npescetelli\Documents\Paris\toolboxes'));

%% plot confidence distribution
clf
x1=[0:1:1000];
z = zscore(x1);
C = normpdf(z,0,1);

plot(z,C,'LineWidth',3)
xlim([-10 10])
ylim([0 1])

set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.

%% plot conditional probability
hold on
Y1=sigmoid(z,1,2)*.5+.5; % agreeing in confidence
Y2=sigmoid(z,1,-2)*.5+.5; % agreeing in uncertainty
Y3=sigmoid(z,1,2)*.5+.5;% accurate agreeing
Y4=sigmoid(z,1,-2)*.5+.5;% accurate agreeing

h1 = line([0 0],[1 0],'LineWidth',2,'LineStyle','--','color','b');

h2 = plot(z,Y1,'LineWidth',3,'color','r')
h3 = plot(z,Y2,'LineWidth',3,'color','b')
h4 = plot(z,Y3,'LineWidth',3,'color','r','LineStyle','--')
h5 = plot(z,Y4,'LineWidth',3,'color','b','LineStyle','--')

set(gca,'FontSize',24)
xlim([-10 10]),xlabel('confidence')
ylim([0 1]),ylabel('p(agree)')

legend([h2 h3 h4 h5], 'high agreement in confidence','high agreement in uncertainty',...
'low agreement in confidence','low agreement in uncertainty','Location','SouthWest')

110 changes: 110 additions & 0 deletions agreementf.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
function [agree, step] = agreementf(rawx,type,distribution,funct)
% use : [agree step] = agreementf(raw-x,obstype,distribution,function type)
%
% agree: logical
% step: -1-left tail, 0-central mass, 1-right tail of the distribution
% raw-x : current confidence judgment
% obstype: 1-agree in confidence, 2-agree in uncertainty, 0- baseline 70%
% distribution: vector containing (correct) confidence judgments so far
% function: one among 'semilinear' 'sigmoid' 'stepwise'
x =abs(rawx);
b = quantile(distribution,[.3 .7]); % boundaries (30% and 70% of the mass)

switch funct
case 'sigmoid'
% define sigmoid function parameters
sat = .5; % lower saturation at 50%
phase = 1;
slope1 = 2; % obstype 1
slope2 = -2; % obstype 2

step = NaN;
switch type
case 1 % agreement under confidence
pagree= sigmoid(x,phase,slope1)*.5 + sat; % agreeing in confidence
case 2 % agreement under uncertainty
pagree = sigmoid(x,phase,slope2)*.5 + sat; % agreeing in uncertainty
case 0 % baseline type
pagree = .7;
end

case 'semilinear'
switch type
case 1 % agreement under confidence
if x > b(1) && x <= b(2) % around 60% of the mass is between -.52 and +.52 sigmas
pagree = .7;
step = 0;
elseif x <= b(1)
minv = min(distribution); % minimum value of the distribution corresponds to 60%
beta = -.1 / (b(2) + minv);
intercept = .7 + beta * b(2);
pagree = intercept + beta * x;
step = -1;
elseif x > b(2)
maxv = max(distribution);
beta = .1 / (b(1) + maxv);
intercept = .7 - beta * b(2);
pagree = intercept + beta * x;
step = 1;
end
case 2 % agreement under uncertainty
if x > b(1) && x <= b(2)
pagree = .7;
step = 0;
elseif x <= b(1)
minv = min(distribution); % minimum value of the distribution corresponds to 60%
beta = .1 / (b(2) + minv);
intercept = .8 - beta * (minv);
pagree = intercept + beta * x;
step = -1;
elseif x > b(2)
maxv = max(distribution);
beta = -.1 / (b(1) + maxv);
intercept = .7 - beta * b(2);
pagree = intercept + beta * x;
step = 1;
end
case 0 % baseline type
pagree = .7;
step = 0;
end
case 'stepwise'
switch type
case 1 % agreement under confidence
if x > b(1) && x <= b(2)
pagree = .7;
step = 0;
elseif x <= b(1)
pagree = .6;
step = -1;
elseif x > b(2)
pagree = .8;
step = 1;
end
case 2 % agreement under uncertainty
if x > b(1) && x <= b(2)
pagree = .7;
step = 0;
elseif x <= b(1)
pagree = .8;
step = -1;
elseif x > b(2)
pagree = .6;
step = 1;
end
case 0 % baseline type
if x > b(1) && x <= b(2)
pagree = .7;
step = 0;
elseif x <= b(1)
pagree = .7;
step = -1;
elseif x > b(2)
pagree = .7;
step = 1;
end
end
end

agree = rand<pagree;

130 changes: 130 additions & 0 deletions build_trials.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
trials = [];
trialid = 0;
index=1;
[block_trials0, block_trials1] =deal([]); %initialize as empty vectors


% practice trials
for b = 1: cfg.nblocksprac
block_trials0 = []; %clear vector
for t = 1:cfg.ntrialsprac
trialid = trialid+1;
block_trials0(end+1).trialid = trialid;
block_trials0(end).estim_obsacc = [];
block_trials0(end).block = b;
block_trials0(end).feedback = true;
block_trials0(end).cj1 = [];
block_trials0(end).obsacc = NaN;
block_trials0(end).qanswers = [];
if b > 1
block_trials0(end).obstype = 0; % practice
block_trials0(end).pic = cfg.observer.pic(4); % practice picture
block_trials0(end).voice = cfg.observer.voice(4); % practice voice
else
block_trials0(end).obstype = NaN;
block_trials0(end).pic = NaN;
block_trials0(end).voice = NaN;
end
end
block_trials0 = block_trials0(randperm(length(block_trials0))); % randomize trials within block
trials = cat(2,trials,block_trials0); % concatenate practice block
end

% experimental trials
for b = b+1 : cfg.nblocks+cfg.nblocksprac
block_trials1 = [];
for o = 1:cfg.nobs
for t = 1:((cfg.ntrials - cfg.nullt) ./ 3) % 10 presentations of observers/block
trialid = trialid+1;
block_trials1(end+1).trialid = trialid;
block_trials1(end).estim_obsacc = [];
block_trials1(end).block = b;
block_trials1(end).feedback = false;
block_trials1(end).cj1 = [];
block_trials1(end).obsacc = NaN; % conditional on subjects confidence
block_trials1(end).obstype = o-1;
block_trials1(end).pic = cfg.observer.pic(o);
block_trials1(end).voice = cfg.observer.voice(o);
block_trials1(end).qanswers = [];
end
end
for t = 1:cfg.nullt % 5 null trials per block
trialid = trialid+1;
block_trials1(end+1).trialid = trialid;
block_trials1(end).estim_obsacc = [];
block_trials1(end).block = b;
block_trials1(end).feedback = false;
block_trials1(end).cj1 = [];
block_trials1(end).obsacc = NaN;
block_trials1(end).obstype = NaN;
block_trials1(end).pic = NaN;
block_trials1(end).voice = NaN;
block_trials1(end).qanswers = [];
end
block_trials1 = block_trials1(randperm(length(block_trials1))); % randomize trials within a block
trials = cat(2,trials,block_trials1); % concatenate to main trial vector
end
clear block_trial*;

wl0 = repmat([1 2],1,(cfg.ntrialsprac/2) * cfg.nblocksprac);

% this method for where larger computation has been implemented only for
% study3f. Check previous versions of the study!
wl1 = repmat([1 2],1,(cfg.ntrials./2) * cfg.nblocks);
%% WARNING! Massive problem detected.
% This way of assigning wherelarger is imbalanced!
% wl1 = repmat([1 2],1,(cfg.ntrials./2 +cfg.nullt) * cfg.nblocks);
% Has this method been implemented for study3???
%
%%
wl0 = wl0(randperm(length(wl0)));
wl1 = wl1(randperm(length(wl1)));
wl = cat(2,wl0,wl1);
for t = 1 : length(trials)
trials(t).wherelarger = wl(t);
trials(t).wheredots = zeros(2,400);
end
clear wl

%-- extra information at each trial
for t = 1:length(trials)
%-- add breaks and instruction points
if t == 1
trials(t).break = false;
trials(t).instr = true;
trials(t).questionnaire = false;
elseif ...
trials(t-1).block ~= trials(t).block
trials(t).break = true;
trials(t).feedback = true;
if trials(t).block <= cfg.nblocksprac+1
trials(t).instr = true;
else trials(t).instr = false;
end
if ismember(trials(t).block,[3:2:cfg.nblocks+cfg.nblocksprac]), % questionnaires every 2 blocks
trials(t).questionnaire = true;
else trials(t).questionnaire = false;
end
else
trials(t).break = false;
trials(t).instr = false;
trials(t).questionnaire = false;
end
end

%-- check fields: none should be empty
fields = fieldnames(trials);
for f= 1:length(fields)
if eval(['length({trials.' fields{f} '})']) ~= length(trials)
disp(['Empty fields in ' fields{f} '!']);
end
end
clear f
if 0
% check the design manually
% after randomization
img_dsg(trials,{'block', 'feedback', 'obstype', 'instr' 'wherelarger'})
figure(gcf+1);
[z index] = sort([trials.trialid]);clear z;
img_dsg(trials(index),{'block', 'feedback', 'obstype','instr' 'wherelarger'})
end
12 changes: 12 additions & 0 deletions check_agreementf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
for c=1:1000
% generate confidence judgement
conf(c)=25+5*randn;
agree1(c) = agreementf(1,conf,'sigmoid');
agree2(c) = agreementf(2,conf,'sigmoid');
end

mean([agree1(conf>40); agree2(conf>40)],2)

figure(1),hold on
X1 = normpdf([-2:.01:2],0,1);
plot([-2:.01:2],X1)
43 changes: 43 additions & 0 deletions check_agreementf.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
%%
addpath(genpath('/home/niccolo/Dropbox/Oxford/myfunctions'));
addpath(genpath('/media/niccolo/Yupi/Paris/toolboxes/JR_toolbox'));


%%
clear all
figure(1)
% generate confidence judgement
conf=25+5*randn(50,1);

for c=1:5000
cj(c) = 25+5*randn;
agree1(c) = agreementf(cj(c),1,conf,'stepwise');
agree2(c) = agreementf(cj(c),2,conf,'stepwise');
agree0(c) = agreementf(cj(c),0,conf,'stepwise');
end

hist(conf)

%%
clear X*
figure(2),clf
bins = [0 22 28 50];
for i =1:length(bins)-1
hold on
clear toi
toi = cj>bins(i) & cj<bins(i+1);
X1(i) = mean(agree1(toi));
X2(i) = mean(agree2(toi));
X0(i) = mean(agree0(toi));
plot(i,X1(i),'rd')
plot(i,X2(i),'s')
plot(i,X0(i),'gs')
end
plot(X1,'r')
plot(X2,'b')
plot(X0,'g')

% glmfit([0:5:45]',X1','binomial','link','logit')



Loading

0 comments on commit 7cdd2c7

Please sign in to comment.