Skip to content

Commit

Permalink
change API of logitBin related functions to support rvm functions in …
Browse files Browse the repository at this point in the history
…chapter07
  • Loading branch information
sth4nth committed Dec 29, 2015
1 parent eb1f617 commit c37e77e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
3 changes: 1 addition & 2 deletions chapter04/binPlot.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ function binPlot(model, X, t)
% t: 1xn label
assert(size(X,1) == 2);
w = model.w;
w0 = model.w0;
xi = min(X,[],2);
xa = max(X,[],2);
[x1,x2] = meshgrid(linspace(xi(1),xa(1)), linspace(xi(2),xa(2)));
Expand All @@ -20,6 +19,6 @@ function binPlot(model, X, t)
idc = t==i;
scatter(X(1,idc),X(2,idc),36,color(mod(i-1,m)+1));
end
y = w0+w(1)*x1+w(2)*x2;
y = w(1)*x1+w(2)*x2+w(3);
contour(x1,x2,y,[-0 0]);
hold off;
17 changes: 9 additions & 8 deletions chapter04/demo.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
[X,t] = kmeansRnd(2,k,n);
[model, llh] = logitBin(X,t-1,0);
plot(llh);
binPlot(model,X,t)
y = logitBinPred(model,X)+1;
binPlot(model,X,y)
pause
%%
clear
k = 3;
n = 1000;
[X,t] = kmeansRnd(2,k,n);
[model, llh] = logitMn(X,t);
y = logitMnPred(model,X);
spread(X,y)
% clear
% k = 3;
% n = 1000;
% [X,t] = kmeansRnd(2,k,n);
% [model, llh] = logitMn(X,t);
% y = logitMnPred(model,X);
% plotClass(X,y)
5 changes: 2 additions & 3 deletions chapter04/logitBin.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [model, llh] = logitBin(X, t, lambda)
function [model, llh] = logitBin(X, t, lambda, w)
% Logistic regression for binary classification optimized by Newton-Raphson
% method.
% X: dxn data matrix
Expand Down Expand Up @@ -43,5 +43,4 @@
if incr < tol; break; end
end
llh = llh(2:iter);
model.w = w(1:(end-1));
model.w0 = w(end);
model.w = w;
4 changes: 2 additions & 2 deletions chapter04/logitBinPred.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
% model: trained model structure
% X: d x n testing data
% Written by Mo Chen ([email protected]).
X = [X;ones(1,size(X,2))];
w = model.w;
w0 = model.w0;
p = exp(-log1pexp(w'*X+w0));
p = exp(-log1pexp(w'*X));
y = (p>0.5)+0;

0 comments on commit c37e77e

Please sign in to comment.