-
Notifications
You must be signed in to change notification settings - Fork 3
/
get_bnd.m
66 lines (47 loc) · 1.37 KB
/
get_bnd.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
% function input :
% x : (n by k) matrix of covariate data
% beta0 : the coefficient for the first covariate in x
% bnd : ((k-1) by 2) matrix where the first and second columns
% respectively store the lower and upper bounds
% of the unknown coefficients
% function output :
% bound : ((k-1) by 2) matrix for the refined lower and upper bounds
% of the unknown coefficients for the parameter space used
% in the warm-start approach
function bound = get_bnd(y,x,beta0,bnd)
k=size(x,2)-1;
p_hat = 1./(1+exp(-x*logit(y,x)));
constr=repmat(p_hat-0.5,1,size(x,2)).*x;
bound=bnd;
model.sense = '>';
model.A = sparse(constr(:,2:size(x,2)));
model.rhs = -constr(:,1)*beta0;
tol=1e-6;
params.outputflag = 0;
params.OptimalityTol=tol;
params.FeasibilityTol=tol;
params.IntFeasTol=tol;
model.lb = bound(:,1);
model.ub = bound(:,2);
for i=1:k
objcoef=zeros(1,k);
objcoef(i)=1;
model.obj = objcoef;
model.modelsense = 'min';
try
result= gurobi(model, params);
bound(i,1)=result.objval;
catch gurobiError
fprintf('Error reported\n');
end
model.modelsense = 'max';
model.lb = bound(:,1);
try
result = gurobi(model, params);
bound(i,2)=result.objval;
catch gurobiError
fprintf('Error reported\n');
end
model.ub = bound(:,2);
end
end