-
Notifications
You must be signed in to change notification settings - Fork 1
/
BT_model.m
48 lines (41 loc) · 1.19 KB
/
BT_model.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
function [Q_log, Lb, Ub]= BT_model(P)
% Bradley-Terry-Model
% (c) Falah Jabar (falah.jabar@lx.it.pt)
%% input:
% P : wining frequency matrix
%% Output
% Q: BT scores (or quality scores)
% Lb: lower bound of confidence interval
% Ub: upper bound of confidence interval
Stimu=length(P(:,1)); %% number of conditions or stimuli
%% Cost function
f = @(x)pwcp2quality(x,P,Stimu);
lb =zeros (1,Stimu);%% lowerbound
ub = ones (1,Stimu); %% upperbound
A = [];
b = [];
Aeq = [];
beq = [];
v0=zeros (1,Stimu);%% intial values
v0(:)=1/Stimu;%% intial values
nonlcon = @unitdisk;
options = optimset( 'Display','iter','UseParallel',1,'PlotFcn','optimplotfval');
options.Algorithm = 'interior-point';
[Q,fval,exitflag,output,lambda,grad,hessian] = fmincon(f,v0,A,b,Aeq,beq,lb,ub,nonlcon,options);
%% computes numerical Hessian
[CM ,N]= HHessian(P,Q);
Sigm=diag(CM);
Ub=zeros (1,Stimu);%% intial values
Lb=zeros (1,Stimu);%% intial values
for i=1:Stimu
Lb(i)=log(Q(i))-(1.96*sqrt(Sigm(i)/N)/Q(i));
Ub(i)=log(Q(i))+(1.96*sqrt(Sigm(i)/N)/Q(i));
end
Q_log=log(Q);
%% row2col
Q_log=Q_log'; Lb=Lb'; Ub=Ub'; Q=Q';
function [c,ceq] = unitdisk(x)
c = [];
ceq = sum(x) - 1;
end
end