vecdiffsubsamp.m 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. function [vdg0nm, vdnmd, vdnmn, vd, vdg0, fpr, tpr, auc]=vecdiffsubsamp(x,y,nrecalls)
  2. if nargin<3; nrecalls=1; end
  3. if ~isvector(x) || ~isvector(y)
  4. error('inputs should be 1-D vectors');
  5. end
  6. x=rmnans(x(:));
  7. y=rmnans(y(:));
  8. Nx=length(x);
  9. Ny=length(y);
  10. vdg0nm=nan;
  11. vdnmd=nan;
  12. vdnmn=nan;
  13. vd=nan;
  14. vdg0=nan;
  15. if Nx>0 && Ny>0
  16. zd=linspace(min([x(:); y(:)]), max([x(:); y(:)]), 1e3);
  17. if Nx==Ny
  18. xr=x;
  19. yr=y';
  20. elseif Ny>Nx
  21. nfolds=ceil(Ny/Nx);
  22. iy=mod(randperm(Nx*nfolds*nrecalls),Ny)+1;
  23. xr=repmat(x',Nx,1,nfolds*nrecalls);
  24. yr=reshape(repmat(y(iy)',1,Nx),Nx,Nx,nfolds*nrecalls);
  25. elseif Nx>Ny
  26. nfolds=ceil(Nx/Ny);
  27. ix=mod(randperm(Ny*nfolds*nrecalls),Nx)+1;
  28. xr=reshape(repmat(x(ix)',1,Ny),Ny,Ny,nfolds*nrecalls);
  29. yr=repmat(y',Ny,1,nfolds*nrecalls);
  30. end
  31. vd=xr-yr;
  32. [fpr,tpr,auc]=get_fpr_tpr_auc(x(:),y(:),zd);
  33. vd_nans=nan(size(vd));
  34. vd_nans(~isnan(vd))=1;
  35. vdg0=(vd>0).*vd_nans;
  36. vdg0nm=nanmean(vdg0,'all');
  37. vdnmd=nanmedian(vd,'all');
  38. vdnmn=nanmean(vd,'all');
  39. end
  40. end