A
download ldiscrim.m
Language: Matlab
LOC: 43
Project Info
MatLinks/Chorus(matlinks)
Server: SourceForge
Type: cvs
...chest\copyleft\gpl\stixbox\
   bincoef.m
   cat2tbl.m
   ciboot.m
   ciquant.m
   cmpmod.m
   Contents.m
   contincy.m
   corr.m
   covboot.m
   covjack.m
   cvar.m
   datas1.m
   datas10.m
   datas11.m
   datas2.m
   datas3.m
   datas4.m
   datas5.m
   datas6.m
   datas7.m
   datas8.m
   datas9.m
   dbeta.m
   dbinom.m
   dchisq.m
   df.m
   dgamma.m
   dgumbel.m
   dhypg.m
   dlognorm.m
   dnorm.m
   dt.m
   dweib.m
   egumbel.m
   getdata.m
   histo.m
   identif5.m
   identify.m
   kaplamai.m
   ldiscrim.m
   linreg.m
   lodds.m
   loddsinv.m
   logitfit.m
   lsfit.m
   lsselect.m
   normmix.m
   octvinit.m
   pairs.m
   pbeta.m
   pbinom.m
   pchisq.m
   pf.m
   pgamma.m
   pgumbel.m
   phypg.m
   plognorm.m
   plotdens.m
   plotempd.m
   plotsym.m
   pnorm.m
   pt.m
   pweib.m
   qbeta.m
   qbinom.m
   qchisq.m
   qf.m
   qgamma.m
   qgumbel.m
   qhypg.m
   qlognorm.m
   qnorm.m
   qqgamma.m
   qqgumbel.m
   qqnorm.m
   qqplot.m
   qqweib.m
   qt.m
   quantile.m
   qweib.m
   ranktrf.m
   rbeta.m
   rbinom.m
   rboot.m
   rchisq.m
   Readme.m
   rf.m
   rgamma.m
   rgumbel.m
   rhypg.m
   rlognorm.m
   rnorm.m
   rt.m
   rweib.m
   spearman.m
   stdboot.m
   stdize.m
   stdjack.m
   stixdemo.m
   test1b.m
   test1n.m
   test1r.m
   test2n.m
   test2r.m

function  [v, c, e1, e2] = ldiscrim(y,x,a3,a4);
%LDISCRIM Compute a linear discriminant by logistic regression. 
%
%     	  [v, c, e1, e2] = ldiscrim(x1, x2)
%
%         A good linear discriminator is found through logistic
%	  regression. An observation is classified as belonging to
%	  the first group if  v*x < c. The outputs  e1  and  e2
%	  are the misclassification rates on the given training set.
%	  One might also call the function with the form
%
%      	  [v, c, e1, e2] = ldiscrim(group, x)
%
%	  where  group  is a column vector with only 2 different
%	  kinds of elements - e g 1 and 2 - for group indication.
%
%	  If a third and a fourth argument are given they are taken 
%	  as plot symbols, and a plot is drawn.

%       GPL Copyright (c) Anders Holtsberg, 1999-04-13

% ------------------------------------------------- Rebuild ---

if size(y,2) > 1 | ~(all(y == min(y) | y == max(y)))
   if (size(x,2) ~= size(y,2))
      error('input format is wrong')
   end
   n1 = size(y,1);
   n2 = size(x,1);
   x = [y; x];
   y = [zeros(n1,1); ones(n2,1)];
end

% ------------------------------------------------- Check y ---

if size(y,2) ~= 1 | size(y,1) ~= size(x,1)
   error('input format is wrong')
end
y = y == max(y);
n1 = sum(y==0);
n2 = sum(y==1);

% ---------------------------------------------- Do the job ---

b = logitfit(y, [x, ones(size(x,1),1)]);
v = b(1:length(b)-1);
c = b(length(b));
c = -c/norm(v);
v = v./norm(v);
e1 = sum(x(1:n1,:)*v >= c) / n1;
e2 = sum(x(n1+(1:n2),:)*v < c) / n2;

% ---------------------------------------------------- Plot ---

if nargin == 4
   xx = x - (x*v)*v';
   m = mean(xx);
   s = std(xx);
   z = stdize(xx);
   CC = z'*z;
   [vn, e] = eig(CC);
   [dummy, I] = sort(diag(e));
   v2 = vn(:,I(size(x,2))) ./ s';
   l1 = x*v;
   l2 = x*v2;
   h = ishold;
   plot(l1(y==0), l2(y==0), a3)
   hold on
   plot(l1(y==1), l2(y==1), a4)
   a = axis;
   plot([c c], a([3, 4]), 'k');
   grid
   if ~h, hold off, end
end

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us