-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtsdTAFCSimulationTutorial.m
More file actions
88 lines (77 loc) · 2.32 KB
/
Copy pathtsdTAFCSimulationTutorial.m
File metadata and controls
88 lines (77 loc) · 2.32 KB
1
% tsdTAFCSimulationTutorial%% Simulation of observer performance for a% two-alternative forced choice task. Signal% is presented in one interval, noise in the% other interval. Obsever chooses interval% with the larger observation, and percent% correct is computed.%% An interesting extension would be to parametrically% vary the signal mean and plot out a psychometric% function.%% A second extension would be to combine the calculations% here with those suggested in tsdBasicSimulationTutorial,% numericaly compute the area under the ROC for each choice% of signal mean, and show that percent correct in TAFC is% given by the area under the ROC.%% Requires statistics toolbox.% % 9/28/04 dhb Wrote it.% 7/10/09 dhb Wrote it.% Clear outclear all;% Number of simulation trials to run. Increase to% improve simulation accuracy, decrease to speed it up.Ntrials = 1000;% Signal and noise distribution parameters% We will assume both distributions are normal,% so that we specify mean (u) and variance (var)% of eachun = 1;varn = 1;us = 2;vars = 1;% Counter variables to record trial by trial outcomesNcorrect = 0;% Simulate out for decisions based on true population statistics.% The logic here just goes through the trials one by one and% simulates generation of observation and then decision.x1 = zeros(Ntrials,1);x2 = zeros(Ntrials,1);is_1 = zeros(Ntrials,1);for i = 1:Ntrials % Determine signal interval is_1(i) = (rand(1,1) < 0.5); if ( is_1(i) ) x1(i) = normrnd(us,sqrt(vars)); x2(i) = normrnd(un,sqrt(varn)); else x1(i) = normrnd(un,sqrt(varn)); x2(i) = normrnd(us,sqrt(vars)); end % Compute log likelyhoods loglikelisignal1 = log(normpdf(x1(i),us,sqrt(vars))); loglikelinoise1 = log(normpdf(x1(i),un,sqrt(varn))); loglikelisignal2 = log(normpdf(x2(i),us,sqrt(vars))); loglikelinoise2 = log(normpdf(x2(i),un,sqrt(varn))); loglikeli1 = loglikelisignal1 + loglikelinoise2; loglikeli2 = loglikelisignal2 + loglikelinoise1; % Decide which we want if (loglikeli1 > loglikeli2) say_1 = 1; else say_1 = 0; end % Record outcome if (is_1(i) & say_1) Ncorrect = Ncorrect+1; elseif (~is_1(i) & ~say_1) Ncorrect = Ncorrect+1; endend% Compute hit and false alarm rates, print them out.Pcorrect = Ncorrect/Ntrials;fprintf('Percent correct = %0.1f%%\n',100*Pcorrect);