https://github.com/nwbarendregt/AdaptNormThresh
Tip revision: 2878a3d9f5a3b9b89a0084a897bef3414e9de4a2 authored by nwbarendregt on 03 May 2022, 15:08:29 UTC
Add files via upload
Add files via upload
Tip revision: 2878a3d
RC_Const_Opt.m
% RC_Const_Opt.m
% Calculates optimal parameterization of the noise-free Const model, and
% associated reward rate, for the reward change task from
% Barendregt et al., 2022.
clear
% Define simulation parameters for the reward change task:
T = 5; dt = 0.005; t_i = 1;
dg = 0.001;
m = 5; c = 1;
R_1 = linspace(1,10); R_2 = 11-R_1;
% Define simulation parameters to empirically calculate model performance:
N_trial = 1e4;
% Define model parameterization mesh to search over:
Const_thresh = linspace(0.1,5,10);
% Pre-allocate reward rate and model parameterization storage:
Const_RR_Opt = NaN(1,length(R_1));
Const_Opt_theta = NaN(1,length(R_1));
for i = 1:length(R_1)
% Pre-allocate RT, reward, and time cost storage for model
% parameterizations:
RT = NaN(length(Const_thresh),N_trial);
reward = NaN(length(Const_thresh),N_trial);
cost = NaN(length(Const_thresh),N_trial);
for j = 1:length(Const_thresh)
% Construct Const model given parameterization:
thresh = Const_thresh(j)*ones(1,T/5/dt+1);
% Generate block data:
y = RDMD_trial_generate(m,T/5,dt,0,N_trial);
for n = 1:N_trial
% Perform trial block using given Const model parameterization:
[RT(j,n),C] = RDMD_sim_norm(y(n,:),T/5,dt,thresh,0);
reward(j,n) = C*(R_1(i)*(RT(j,n) < 0.5)+R_2(i)*(RT(j,n) >= 0.5));
cost(j,n) = c*RT(j,n);
end
end
% Calculate maximal reward rate for given reward timeseries and store
% optimal parameterization:
[Const_RR_Opt(i),I] = max((mean(reward,2)-mean(cost,2))./(mean(RT,2)+t_i));
Const_Opt_theta(i) = Const_thresh(I);
end
save('RC_Const_Opt_Data.mat','Const_RR_Opt','Const_Opt_theta','R_1','R_2');