Figure 7.1: Logistic regression
randn('state',0);
rand('state',0);
a = 1;
b = -5 ;
m= 100;
u = 10*rand(m,1);
y = (rand(m,1) < exp(a*u+b)./(1+exp(a*u+b)));
plot(u,y,'o')
axis([-1,11,-0.1, 1.1]);
U = [ones(m,1) u];
cvx_expert true
cvx_begin
variables x(2)
maximize(y'*U*x-sum(log_sum_exp([zeros(1,m); x'*U'])))
cvx_end
ind1 = find(y==1);
ind2 = find(y==0);
aml = x(2); bml = x(1);
us = linspace(-1,11,1000)';
ps = exp(aml*us + bml)./(1+exp(aml*us+bml));
dots = plot(us,ps,'-', u(ind1),y(ind1),'o',...
u(ind2),y(ind2),'o');
axis([-1, 11,-0.1,1.1]);
xlabel('x');
ylabel('y');
Successive approximation method to be employed.
SDPT3 will be called several times to refine the solution.
Original size: 600 variables, 202 equality constraints
For improved efficiency, SDPT3 is solving the dual problem.
Approximation size: 2201 variables, 1202 equality constraints
-----------------------------------------------------------------
Target Conic Solver
Precision Error Status
---------------------------
1.221e-04 2.483e+00 Solved
1.221e-04 3.072e-03 Solved
1.221e-04 0.000e+00 Solved
1.490e-08 2.781e-06 Solved
1.490e-08 0.000e+00 Solved
-----------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): -32.9797