Psychology 448A/538A

Advanced Programming for the Behavioral Sciences

psi
Home Library of Functions Lessons Homework Discussion Board

 

Homeworkmatlab

Homework 1: Yellow on Blue


Homework 2: Speed Discrimination Task

Due Sunday, April 12 at 5pm

Write script that measures your own 'Speed Discrimination' psychometric function by modifying the matlab code from Lesson 4. You can use either the method of constant stimuli or the staircase method.

For each trial, the subject will view two intervals of moving dots (specific parameters below). On one of the intervals, the dots will move at the 'baseline' speed of 5 deg/sec. On the other interval, the dots will move at a faster speed - the baseline plus some increment. The speed increment will vary from trial to trial, just as coherence did in the lesson. The interval that contains the faster speed will be randomized from trial to trial. The subject's job is to respond '1' or '2' for which interval (first or second) had the faster speed.

Each interval should last 1/2 second with a 1/4 second pause in between. The inter-trial interval should be 2.25 seconds. Let the dots have 100% coherence, moving upward within a 6 degree circular aperture centered at fixation. The rest of the paramters (dot color, size, number etc.) us up to you.

Save the results in our standard structure 'results.m' where 'results.intensity' refers to the speed increment for each trial.

At the end of the script, plot the results like we did in lesson 4. You may either use a log or linear x-axis.

What I want from you is:

1) the script containing the code that runs the trials and plots the graphs, and

2) a pdf of the plot of the psychometric function run on yourself.


Homework 3: confidence intervals for increasing number of trials

Due Sunday, April 26 (midnight)

Download the matlab code of my solution here, and the corresponding pdf here

The central limit theorem predicts that the standard error of the mean (SEM) shrinks in proportion to 1 over the square root of the sample size. This means that a plot of the sample size on the x-axis and the SEM on the y-axis should have a slope of -1/2 on a log-log axis.

Homework 3 is to use the parametric bootstrapping program to see if the same thing happens to the width of the confidence interval for the threshold as you increase the number of 2AFC trials.

This will require you to run 'bootstrapWeibullThreshold' using sample data sets with increasing number of 2AFC trials. The easiest way to do this is to choose a series of intensity levels and an increasing list of repetitions per intensity. Each sample data set will contain a list of intensities (results.intensity) that has a fixed number of repetitions of each intensity (recall how we did this using 'repmat' for the method of constant stimuli).

Our bootstrapping program 'bootstrapWeibullThreshold' will calculate confidence intervals based on each sample data set. Recall that it works by fitting the Weibull to the sample data set and then samples new 'fake' data based on this best-fitting Weibull function. For this homework's analysis, we want the Weibull parameters used for the sampling to be the same, regardless of the number of trials. To ensure this, make your sample data set's responses ('results.response') be set to the Weibull function evaluated at the corresponding intensity (rather than 0's and 1's).

Choose Weibull parameters p.t = 0.1 and p.b = 2

Use intensity levels [.02,.04,.08,.16,.32,.64]

For each bootstrap, repeat each intensity [1,2,4,8,16,32,64,128] times (yeilding 6, 12, 24, 48, 96, 192, 384, and 768 trials)

Please turn in two files:

(1) The matlab file you wrote to run the analysis and

(2) a pdf of the plot. Plot the results on a log-log axis where the x-axis is the number of trials and the y-axis is half of the confidence interval using the default 68% width.

Be sure to label your axes and turn in code that runs!

Extra credit: Fit the results (the log of x and log of y) with a linear polynomial (you can use matlab's 'polyfit') to see if the slope on log-log axes is -1/2.


Homework 4: Programming Contest: Be the best at estimating an ideal observer's threshold!

Due Sunday May 3rd (midnight)

I've created a function 'idealObserver' that takes in intensity values (between 0 and 1) and returns the binary response to 2AFC trials for the corresponding intensity (zero or one). Your job is to estimate this observer's threshold as accurately as possible in 60 trials (or less). This means that the you have to choose the list of stimulus intensities. The easiest choice would be a set of pre-set intensities as in the method of constant stimuli. But it might be more efficient to use an 'adaptive' method such as a 3-down 1-up staircase. It's all up to you.

My ideal observer will behave according to Signal Detection Theory by drawing from signal and noise distributions. The observer will also make button press errors on an average of 2% of the time, meaning that 2% of the responses will be random coin-flips. Inside my idealObserver function are hard-coded parameters that will determine the slope and threshold for the expected psychometric function.

You can download an example here:

idealObserver.p

This is a 'protected' file which runs properly, but you can't see the code.

You must provide me a function called 'getThreshold' that takes in no arguments and returns a single number - the estimated threshold. Here's a valid example:

function thresh = getThreshold

intensities = [0,.2,.4,.6,.8,1];
nReps = 10; %repetitions per intensity
nTrials = length(intensities)*nReps; %60

intensityList = repmat(intensities,nReps,1);
results.intensity = intensityList(:);
results.response = idealObserver(results.intensity);

pInit.t = .1;
pInit.b = 3;
pInit.shutup = 1;

pBest = fit('fitPsychometricFunction',pInit,{'t','b'},results,'Weibull');
thresh = pBest.t;

Here's another example - the one we wrote together in class using an embedded function:

function thresh = getThreshold

results.intensity = linspace(0,1,60);
results.response = idealObserver(results.intensity);

pInit.sig = 1;
freeParams = {'sig'};

myFn = @logistic;

pBest = fit('fitPsychometricFunction',pInit,freeParams,results,myFn);

thresh = pBest.sig;

figure(1)
clf

y = logistic(pBest,results.intensity);
plot(results.intensity,y);
hold on
plot(results.intensity,results.response,'ro');

end

function y = logistic(p,x)
y = 1./(1+exp(-p.sig*x));
end

 

How your homework will be evaluated:

I will choose one set of parameter values for the ideal observer and run your program 1000 times. I will then calculate the confidence interval containing the middle 68% of the thresholds. The ideal observer's actual threshold will be reasonable: somewhere between .1 and .9 with a slope betwen 0.5 and 10. The score for your homework will be calculated as the sum of the following (maximum 100 pts):

40 pts: If your function calls the function 'idealObserver' at least once but not more than 60 times and returns any threshold whatsoever

30 pts: If the 95% confidence interval contains the actual threshold of the ideal observer

30 pts: If the 68% confidence interval contains the actual threshold of the ideal observer

A FREE MATLAB T-SHIRT WILL BE AWARDED TO THE SUBMISSION WITH THE NARROWEST 68% CONFIDENCE INTERVAL!

Nerdy Matlab Rubik's Cubes will be award to the 2nd and 3rd place entries

rubik


Final Project:

Submit any matlab files and related documents/images etc. Here.