-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Konstantinos Tsetsos
authored and
Konstantinos Tsetsos
committed
Dec 14, 2018
1 parent
ad27b1e
commit 1bc74e7
Showing
55 changed files
with
2,090 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
{\rtf1\ansi\ansicpg1252\cocoartf1671 | ||
{\fonttbl\f0\fnil\fcharset0 HelveticaNeue-Bold;\f1\fnil\fcharset0 HelveticaNeue;} | ||
{\colortbl;\red255\green255\blue255;\red0\green0\blue0;} | ||
{\*\expandedcolortbl;;\cssrgb\c0\c0\c0;} | ||
{\*\listtable{\list\listtemplateid1\listhybrid{\listlevel\levelnfc0\levelnfcn0\leveljc0\leveljcn0\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{decimal\})}{\leveltext\leveltemplateid1\'02\'00);}{\levelnumbers\'01;}\fi-360\li720\lin720 }{\listname ;}\listid1} | ||
{\list\listtemplateid2\listhybrid{\listlevel\levelnfc0\levelnfcn0\leveljc0\leveljcn0\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{decimal\}.}{\leveltext\leveltemplateid101\'02\'00.;}{\levelnumbers\'01;}\fi-360\li720\lin720 }{\listname ;}\listid2} | ||
{\list\listtemplateid3\listhybrid{\listlevel\levelnfc0\levelnfcn0\leveljc0\leveljcn0\levelfollow0\levelstartat2\levelspace360\levelindent0{\*\levelmarker \{decimal\}.}{\leveltext\leveltemplateid201\'02\'00.;}{\levelnumbers\'01;}\fi-360\li720\lin720 }{\listname ;}\listid3} | ||
{\list\listtemplateid4\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid301\'01\uc0\u8226 ;}{\levelnumbers;}\fi-360\li720\lin720 }{\listname ;}\listid4} | ||
{\list\listtemplateid5\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid401\'01\uc0\u8226 ;}{\levelnumbers;}\fi-360\li720\lin720 }{\listname ;}\listid5} | ||
{\list\listtemplateid6\listhybrid{\listlevel\levelnfc0\levelnfcn0\leveljc0\leveljcn0\levelfollow0\levelstartat2\levelspace360\levelindent0{\*\levelmarker \{decimal\}.}{\leveltext\leveltemplateid501\'02\'00.;}{\levelnumbers\'01;}\fi-360\li720\lin720 }{\listname ;}\listid6}} | ||
{\*\listoverridetable{\listoverride\listid1\listoverridecount0\ls1}{\listoverride\listid2\listoverridecount0\ls2}{\listoverride\listid3\listoverridecount0\ls3}{\listoverride\listid4\listoverridecount0\ls4}{\listoverride\listid5\listoverridecount0\ls5}{\listoverride\listid6\listoverridecount0\ls6}} | ||
\paperw11905\paperh16837\margl1133\margr1133\margb1133\margt1133 | ||
\deftab720 | ||
\pard\tx1150\pardeftab720\partightenfactor0 | ||
|
||
\f0\b\fs20 \cf2 \expnd0\expndtw0\kerning0 | ||
\up0 \nosupersub \ulnone \outl0\strokewidth0 \strokec2 \ | ||
****MATLAB SCRIPTS SHARED HERE were IMPLEMENTED IN MATLAB R2017b ****\ | ||
ALSO please note that all models were fitted using parallel computing implemented in a cluster. we used a series of shell scripts that in turn called standalone versions of the matlab scripts shared here. the shell scripts and auxiliary files used for fitting are specific to the cluster\'92s implementation and they are not shared here.\ | ||
\pard\pardeftab720\partightenfactor0 | ||
\f1\b0\fs22 \cf2 \strokec2 \ | ||
The folder \'93extended_models\'94 consists of 3 subfolders:\ | ||
\ | ||
\pard\tx20\tx360\pardeftab720\li360\fi-360\partightenfactor0 | ||
\ls1\ilvl0\cf2 \kerning1\expnd0\expndtw0 \up0 \nosupersub \ulnone \outl0\strokewidth0 {\listtext 1) }\cf2 \expnd0\expndtw0\kerning0 | ||
\up0 \nosupersub \ulnone \outl0\strokewidth0 \strokec2 data_processing\ | ||
\ls1\ilvl0\cf2 \kerning1\expnd0\expndtw0 \up0 \nosupersub \ulnone \outl0\strokewidth0 {\listtext 2) }\cf2 \expnd0\expndtw0\kerning0 | ||
\up0 \nosupersub \ulnone \outl0\strokewidth0 \strokec2 default_protocol\ | ||
\ls1\ilvl0\cf2 \kerning1\expnd0\expndtw0 \up0 \nosupersub \ulnone \outl0\strokewidth0 {\listtext 3) }\cf2 \expnd0\expndtw0\kerning0 | ||
\up0 \nosupersub \ulnone \outl0\strokewidth0 \strokec2 dynamic_protocol\ | ||
\pard\pardeftab720\partightenfactor0 | ||
\cf2 \strokec2 \ | ||
\ | ||
\pard\tx20\tx523\pardeftab720\li523\fi-524\partightenfactor0 | ||
\ls2\ilvl0 | ||
\f0\b\fs32 \cf2 \kerning1\expnd0\expndtw0 \up0 \nosupersub \ulnone \outl0\strokewidth0 {\listtext 1. }\cf2 \expnd0\expndtw0\kerning0 | ||
\up0 \nosupersub \ulnone \outl0\strokewidth0 \strokec2 data_processing\ | ||
\pard\pardeftab720\partightenfactor0 | ||
\f1\b0\fs22 \cf2 \strokec2 \ | ||
Here, the script \'93descriptives_script.m\'94 takes the raw data (motionEnergy*.mat) and summarises behaviour in RT quantiles. The output of this script is \'93descriptives.mat\'94 that is subsequently used to fit different models. \ | ||
\ | ||
\ | ||
\pard\tx20\tx523\pardeftab720\li523\fi-524\partightenfactor0 | ||
\ls3\ilvl0 | ||
\f0\b\fs32 \cf2 \kerning1\expnd0\expndtw0 \up0 \nosupersub \ulnone \outl0\strokewidth0 {\listtext 2. }\cf2 \expnd0\expndtw0\kerning0 | ||
\up0 \nosupersub \ulnone \outl0\strokewidth0 \strokec2 default_protocol\ | ||
\pard\pardeftab720\partightenfactor0 | ||
\f1\b0\fs22 \cf2 \strokec2 \ | ||
This folder contains implementations of different models that rely on the default simulation protocol. Each subfolder corresponds to a different model. Please note that the code in the Naive and Drift_Bias folders includes detailed comments. These models can thus be used as reference to understand the other models.\ | ||
\ | ||
\pard\tx20\tx360\pardeftab720\li360\fi-360\partightenfactor0 | ||
\ls4\ilvl0\cf2 \kerning1\expnd0\expndtw0 \up0 \nosupersub \ulnone \outl0\strokewidth0 {\listtext \uc0\u8226 }\cf2 \expnd0\expndtw0\kerning0 | ||
\up0 \nosupersub \ulnone \outl0\strokewidth0 \strokec2 The general common script structure for each model was as follows:\ | ||
\pard\pardeftab720\partightenfactor0 | ||
\cf2 \strokec2 \ | ||
\'97 \'93diffusion_custom2.m\'94 is the name of the function that implements the corresponding model.\ | ||
\'97 \'93cost_fit.m\'94 is the function that calculates the likelihood of a model for a given set of parameters by calling \'93diffusion_custom2.m.\ | ||
\'97 \'93superScript_Step1.m\'94 implements the 1st step of the fitting procedure is implemented.\ | ||
\'97 \'93Bridge_Fits.m\'94 reformats the fits from the 1st step such that they can be refined in the 2nd step.\ | ||
\'97 \'93superScript_Step2.m\'94 implements the 2nd step of the fitting procedure.\ | ||
\ | ||
\ | ||
\pard\tx20\tx360\pardeftab720\li360\fi-360\partightenfactor0 | ||
\ls5\ilvl0\cf2 \kerning1\expnd0\expndtw0 \up0 \nosupersub \ulnone \outl0\strokewidth0 {\listtext \uc0\u8226 }\cf2 \expnd0\expndtw0\kerning0 | ||
\up0 \nosupersub \ulnone \outl0\strokewidth0 \strokec2 For all models we share the core scripts: cost_fit.m and diffusion_custom2.m.\ | ||
\ls5\ilvl0\cf2 \kerning1\expnd0\expndtw0 \up0 \nosupersub \ulnone \outl0\strokewidth0 {\listtext \uc0\u8226 }\cf2 \expnd0\expndtw0\kerning0 | ||
\up0 \nosupersub \ulnone \outl0\strokewidth0 \strokec2 For all models except the Naive, the superScript_Step1.m and superScript_Step2.m are common to those scripts in the Drift_Bias folder.\ | ||
\ls5\ilvl0\cf2 \kerning1\expnd0\expndtw0 \up0 \nosupersub \ulnone \outl0\strokewidth0 {\listtext \uc0\u8226 }\cf2 \expnd0\expndtw0\kerning0 | ||
\up0 \nosupersub \ulnone \outl0\strokewidth0 \strokec2 For the Naive model we have separate superScript_Step1.m and superScript_Step2.m scripts. Also for this model, for illustration purposes, we share the Brige_Fits.m script (common to all models).\ | ||
\pard\pardeftab720\partightenfactor0 | ||
\cf2 \strokec2 \ | ||
\pard\tx20\tx523\pardeftab720\li523\fi-524\partightenfactor0 | ||
\ls6\ilvl0 | ||
\f0\b\fs32 \cf2 \kerning1\expnd0\expndtw0 \up0 \nosupersub \ulnone \outl0\strokewidth0 {\listtext 2. }\cf2 \expnd0\expndtw0\kerning0 | ||
\up0 \nosupersub \ulnone \outl0\strokewidth0 \strokec2 dynamic_protocol\ | ||
\pard\pardeftab720\partightenfactor0 | ||
\f1\b0\fs22 \cf2 \strokec2 \ | ||
This folder contains implementations of different models that rely on the dynamic simulation protocol. There are two subfolders implementing models with static and collapsing bounds, respectively. Similar to the default protocol, Naive and Drift_Bias scripts are commented in detail and should be use as reference.\ | ||
\ | ||
In static_bounds/Naive we share the superScript_Step*.m files. These files are adjusted relative to the default protocol in order to implement the dynamic protocol. \ | ||
\ | ||
For the remaining models we share the core scripts: cost_fit.m and diffusion_custom2.m.} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
%% The aim of this script is to summarise the raw data into quantiles on a | ||
%% per participant basis. | ||
|
||
|
||
clear all; | ||
close all; | ||
load('motionEnergyData_AnkeMEG.mat'); % +200 ms are added to all RT's to address fitting | ||
%issues with fast responses. This | ||
%structure is used in the default | ||
%protocol models. | ||
%load('motionEnergyData_AnkeMEG_Dynamic.mat');% RT's are memasured to | ||
%stimulus onset. Therefore +750 ms | ||
%is added to all RT's. This | ||
%structure is used in the dynamic | ||
%protocol. | ||
|
||
ss=unique(data.behavior.subj_idx); | ||
cohs=unique(data.behavior.coherence); | ||
cohs=cohs(1:end); | ||
cohs1=[0 9 27];% 81% coherence trials are excluded | ||
cohs2=[3 9 27];% 0% and 3% trials are pooled together due to indistinguishable | ||
% behaviour in these trials. | ||
|
||
drfts=(mean(data.motionenergy_normalized(:,13:end),2)); % calculate the mean motion energy | ||
% after discarding the 13 first | ||
% samples (rising time of the | ||
% motion energy filter) | ||
|
||
data.behavior.correct=double(sign(drfts)==sign(data.behavior.response)); | ||
rep=double(data.behavior.stimulus==data.behavior.prevresp);%1 if stimulus category is the same as previous response | ||
|
||
|
||
|
||
for s=1:length(ss); | ||
|
||
for re=0:1 % loop across rep=0,1 | ||
for c=1:length(cohs1) % loop across all coherence levels | ||
acc(re+1,ss(s),c)=nanmean(data.behavior.correct(data.behavior.subj_idx==ss(s) & rep==(re) & data.behavior.RT>0 & (data.behavior.coherence==cohs1(c) | data.behavior.coherence==cohs2(c)))); | ||
% calculate accuracy for STIM consistent with previous response and | ||
% each coherence level | ||
for cor=0:1 % calculate incorrect/ correct quantiles | ||
indx=find(data.behavior.subj_idx==ss(s) & rep==(re) & data.behavior.RT>0 & (data.behavior.coherence==cohs1(c) | data.behavior.coherence==cohs2(c)) & data.behavior.correct==cor); | ||
RR=data.behavior.RT(indx);RR(isnan(RR))=[]; | ||
QQ(ss(s),re+1,c,cor+1,:)=quantile(RR,[.1 .3 .5 .7 .9]);% QQ->the RT quantiles | ||
a=quantile(RR,[.1 .3 .5 .7 .9]); | ||
QN(ss(s),re+1,c,cor+1,1)=sum(RR<=a(1)); %QN--> number of trials on the corresponding quantile | ||
QN(ss(s),re+1,c,cor+1,2)=sum(RR>a(1) & RR<=a(2)); | ||
QN(ss(s),re+1,c,cor+1,3)=sum(RR>a(2) & RR<=a(3)); | ||
QN(ss(s),re+1,c,cor+1,4)=sum(RR>a(3) & RR<=a(4)); | ||
QN(ss(s),re+1,c,cor+1,5)=sum(RR>a(4) & RR<=a(5)); | ||
QN(ss(s),re+1,c,cor+1,6)=sum(RR>a(5)); | ||
|
||
end | ||
end | ||
end | ||
end | ||
|
||
save descriptives acc QQ QN |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function [LL]= cost_fit(sub,QQ,QN,mattinput,pars) | ||
|
||
coh1=[0 0.0900 0.2700]*100; | ||
coh2=[0.03 0.0900 0.2700]*100; | ||
|
||
for re=0:1 | ||
for c=1:length(coh1) | ||
|
||
trls=mattinput((mattinput(:,2)==coh1(c) | mattinput(:,2)==coh2(c)) & mattinput(:,4)==re,1); | ||
cor=mattinput((mattinput(:,2)==coh1(c) | mattinput(:,2)==coh2(c)) & mattinput(:,4)==re,3); | ||
stim=mattinput((mattinput(:,2)==coh1(c) | mattinput(:,2)==coh2(c)) & mattinput(:,4)==re,5); %this is the only difference relative | ||
%to the naive cost_fit function. Stim encodes the category of the | ||
%previous choice: +1 right, -1 left. | ||
|
||
[RT,ch]= diffusion_custom2(trls,cor,stim,[pars]); | ||
|
||
|
||
acc(c)=mean(ch);%*0.99+0.005; | ||
P(re+1,c,1,:)=(histcounts(RT(ch==0),[-inf squeeze(QQ(sub,re+1,c,1,:))' inf])./sum(ch==0))*(1-acc(c)); | ||
P(re+1,c,2,:)=(histcounts(RT(ch==1),[-inf squeeze(QQ(sub,re+1,c,2,:))' inf])./sum(ch==1))*(acc(c)); | ||
|
||
|
||
end | ||
end | ||
P=P+eps; | ||
NL=squeeze(QN(sub,:,:,:,:)).*log(P); | ||
LL=-sum(sum(sum(sum(NL)))); |
49 changes: 49 additions & 0 deletions
49
extended_models/default_protocol/Drift_Bias/diffusion_custom2.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
function [RT,ch]= diffusion_custom2(trls,cor,stim,pars) | ||
|
||
|
||
thr=pars(1)*10; | ||
scale=pars(2)*60; | ||
T0=pars(3)*.5; | ||
dv=pars(4)*3; | ||
noise_std=1; | ||
spbias=pars(6)*2.5; | ||
bsp=pars(5)*thr*0.75; | ||
inp=scale*(trls)+(spbias.*stim); % the identity of the previous choice modulates the direction drift bias | ||
iters=size(trls,1); | ||
timest=300; | ||
dt=0.01/2; | ||
|
||
|
||
|
||
dvariance=randn(iters,1)*dv; | ||
|
||
I=randn(iters,timest)*noise_std*sqrt(dt)+(inp)*dt+dvariance*sqrt(dt); | ||
P=ones(iters,1)*thr/2+(-1+2*rand(iters,1))*bsp;%+(spbias.*stim); | ||
RT=[]; | ||
ch=[]; | ||
corct=[]; | ||
t=1; | ||
while (length(P)>0 & t<timest) | ||
P=P+I(:,t); | ||
indx=find(P>thr); | ||
indx1=find(P<0); | ||
P([indx;indx1])=[]; | ||
I([indx;indx1],:)=[]; | ||
corct=[corct cor(indx)' cor(indx1)']; | ||
|
||
cor([indx;indx1])=[]; | ||
ch=[ch ones(1,length(indx))]; | ||
ch=[ch zeros(1,length(indx1))]; | ||
RT=[RT t*ones(1,length(indx)+length(indx1))]; | ||
t=t+1; | ||
end | ||
|
||
ch=[ch double(P'>thr/2)]; | ||
RT=[RT ones(1,length(P))*timest]; | ||
corct=[corct cor']; | ||
ch2=ch; | ||
ch2((ch==1 & corct==1) | (ch==0 & corct==-1))=1; | ||
ch2((ch==0 & corct==1) | (ch==1 & corct==-1))=0; | ||
|
||
ch=ch2; | ||
RT=((RT)*dt)+T0; |
46 changes: 46 additions & 0 deletions
46
extended_models/default_protocol/Drift_Bias/superScript_Step1.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
function [] = superScript_Step1(sub,iter) | ||
|
||
%%SAME AS THE CORRESPONDING SCRIPT IN THE NAIVE MODEL | ||
%%DIFFERENCE 1: IN LINE 31 WHERE THE mattinput matrix has an extra column | ||
%%to store the previous response | ||
|
||
%% DIFFERENCE 2: Instead of using 20 random starting points the simplex starting parameter set | ||
%% takes the best fitting parameters from the Naive model and adds '0' for the extra bias parameter | ||
|
||
if ischar(sub), sb = str2double(sub); end | ||
if ischar(iter), iters = str2double(iter); end | ||
load motionEnergyData_AnkeMEG.mat | ||
load descriptives.mat | ||
load(sprintf('/home/ktsetsos/code1/DDM/fits/out%s_%s.mat',sub,iter)); | ||
stp2=xbest; | ||
QQ(isnan(QQ))=0; | ||
|
||
rand('seed',sb+iters); | ||
randn('seed',sb+iters); | ||
%% | ||
coh=unique(data.behavior.coherence); | ||
|
||
opts= optimset('Display','off','TolX',1e-4,'TolFun',1e-4,'MaxIter',150,'MaxFunEvals',1000); | ||
drfts=((data.motionenergy_normalized(:,16:end))); | ||
|
||
indx=find(data.behavior.subj_idx==sb & data.behavior.RT>0 & ~isnan(data.behavior.response) & ~isnan(data.behavior.prevresp)); | ||
|
||
drfts=drfts(indx,:); | ||
drfts=mean(drfts,2)/100; | ||
|
||
|
||
out=NaN; | ||
matinput=[drfts data.behavior.coherence(indx) data.behavior.stimulus(indx) double(data.behavior.stimulus(indx)==data.behavior.prevresp(indx)) data.behavior.prevresp(indx)]; | ||
mattinput=repmat(matinput,10,1); | ||
|
||
|
||
stp=[stp2 0];%starting parameter set is the best fit from the Naive model and 0 for the bias parameter | ||
out=cost_fit(sb,QQ,QN,mattinput,stp); | ||
|
||
|
||
[xbest,fx,exitflag,output]=fminsearchbnd(@(pars) cost_fit(sb,QQ,QN,mattinput,pars),[stp],[0 0.01 0 0 0 -1],[1 1 1 1 1 1],opts); | ||
out1=xbest; | ||
out2=fx; | ||
|
||
clear data; | ||
save(sprintf('/home/ktsetsos/code1/DDM_DC/fits/out%s_%s.mat', sub, iter)); |
58 changes: 58 additions & 0 deletions
58
extended_models/default_protocol/Drift_Bias/superScript_Step2.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
function [] = superScript_Step2(sub,iter) | ||
|
||
%%SAME AS THE CORRESPONDING SCRIPT IN THE NAIVE MODEL | ||
%%DIFFERENCE: IN LINE 31 WHERE THE mattinput matrix has an extra column | ||
%%to store the previous response | ||
|
||
|
||
if ischar(sub), sb = str2double(sub); end | ||
if ischar(iter), iters = str2double(iter); end | ||
load motionEnergyData_AnkeMEG.mat | ||
load descriptives.mat | ||
|
||
QQ(isnan(QQ))=0; | ||
|
||
rand('seed',sb+iters); | ||
randn('seed',sb+iters); | ||
%% | ||
coh=unique(data.behavior.coherence); | ||
|
||
opts= optimset('Display','off','TolX',1e-4,'TolFun',1e-4,'MaxIter',100,'MaxFunEvals',1000); | ||
drfts=((data.motionenergy_normalized(:,16:end))); | ||
|
||
indx=find(data.behavior.subj_idx==sb & data.behavior.RT>0 & ~isnan(data.behavior.response) & ~isnan(data.behavior.prevresp)); | ||
|
||
drfts=drfts(indx,:); | ||
drfts=mean(drfts,2)/100; | ||
|
||
|
||
|
||
|
||
matinput=[drfts data.behavior.coherence(indx) data.behavior.stimulus(indx) double(data.behavior.stimulus(indx)==data.behavior.prevresp(indx)) data.behavior.prevresp(indx)]; | ||
mattinput=repmat(matinput,20,1); | ||
|
||
|
||
|
||
load(sprintf('fits2/out%s.mat', sub)) | ||
|
||
tic; | ||
mm=size(parms,1); | ||
for tt=1:mm | ||
tt | ||
stp=[parms(tt,:)]; | ||
Rout(tt)=cost_fit(sb,QQ,QN,mattinput,stp); | ||
end | ||
Rout | ||
toc; | ||
[ifx,ixx]=sort(Rout); | ||
|
||
tic; | ||
for mm=1:5 | ||
stp=parms(ixx(mm),:); | ||
[xbest,fx,exitflag,output]=fminsearchbnd(@(pars) cost_fit(sb,QQ,QN,mattinput,pars),[stp],[0 0 0.01 0 0 -1],[1 1 1 1 1 1],opts); | ||
Rout1(mm,:)=xbest; | ||
Rout2(mm)=fx; | ||
end | ||
toc | ||
clear data; | ||
save(sprintf('/home/ktsetsos/code1/DDM_DC/fits3/out%s_%s.mat', sub, iter)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function [LL]= cost_fit(sub,QQ,QN,mattinput,pars) | ||
|
||
coh1=[0 0.0900 0.2700]*100; | ||
coh2=[0.03 0.0900 0.2700]*100; | ||
|
||
for re=0:1 | ||
for c=1:length(coh1) | ||
|
||
trls=mattinput((mattinput(:,2)==coh1(c) | mattinput(:,2)==coh2(c)) & mattinput(:,4)==re,1); | ||
cor=mattinput((mattinput(:,2)==coh1(c) | mattinput(:,2)==coh2(c)) & mattinput(:,4)==re,3); | ||
stim=mattinput((mattinput(:,2)==coh1(c) | mattinput(:,2)==coh2(c)) & mattinput(:,4)==re,5); %this is the only difference relative | ||
%to the naive cost_fit function. Stim encodes the category of the | ||
%previous choice: +1 right, -1 left. | ||
|
||
[RT,ch]= diffusion_custom2(trls,cor,stim,[pars]); | ||
|
||
|
||
acc(c)=mean(ch);%*0.99+0.005; | ||
P(re+1,c,1,:)=(histcounts(RT(ch==0),[-inf squeeze(QQ(sub,re+1,c,1,:))' inf])./sum(ch==0))*(1-acc(c)); | ||
P(re+1,c,2,:)=(histcounts(RT(ch==1),[-inf squeeze(QQ(sub,re+1,c,2,:))' inf])./sum(ch==1))*(acc(c)); | ||
|
||
|
||
end | ||
end | ||
P=P+eps; | ||
NL=squeeze(QN(sub,:,:,:,:)).*log(P); | ||
LL=-sum(sum(sum(sum(NL)))); |
Oops, something went wrong.