forked from sjgershm/reward-complexity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fit_models_steyvers.m
51 lines (35 loc) · 1.14 KB
/
fit_models_steyvers.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function [results, bms_results] = fit_models_steyvers(data,models)
% Fit models to Steyvers data. Requires mfit package.
if nargin < 2; models = 1:2; end
for m = models
disp(['... fitting model ',num2str(m)]);
switch m
case 1
param(1) = struct('name','b','logpdf',@(x) 0);
param(2) = struct('name','sticky','logpdf',@(x) 0);
fun = @lik_steyvers;
case 2
param(1) = struct('name','b','logpdf',@(x) 0);
fun = @lik_steyvers;
end
results(m) = mfit_optimize(fun,param,data);
clear param
end
% Bayesian model selection
if nargout > 1
bms_results = mfit_bms(results,1);
end
end
function lik = lik_steyvers(x,data)
b = x(1);
if length(x) > 1
sticky = x(2);
else
sticky = 1;
end
d = b*data.Q + sticky*data.logPa;
lik = -sum(logsumexp(d,2));
for t = 1:data.N
lik = lik + d(t,data.action(t));
end
end