Advertisement
Guest User

SOD LMNN

a guest
Sep 10th, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.63 KB | None | 0 0
  1. function res=SOD(x,a,b);
  2. % function res=SOD(x,a,b);
  3. %
  4. % Computes and sums over all outer products of the columns in x.
  5. %
  6. % equivalent to:
  7. %
  8. % res=zeros(size(x,1));
  9. % for i=1:n
  10. %   res=res+x(:,a(i))*x(:,b(i))';
  11. % end;
  12. %
  13. %
  14. % copyright 2005 by Kilian Q. Weinberger
  15. % University of Pennsylvania
  16. % kilianw@seas.upenn.edu
  17. % ********************************************
  18.  
  19. [D,N]=size(x);
  20. B=round(2500/D^2*1000000);
  21. res=zeros(D^2,1);
  22. for i=1:B:length(a)
  23.   BB=min(B,length(a)-i);
  24.   Xa=x(:,a(i:i+BB));
  25.   Xb=x(:,b(i:i+BB));
  26.   XaXb=Xa*Xb';
  27.   res=res+vec(Xa*Xa'+Xb*Xb'-XaXb-XaXb');
  28.  
  29.   if(i>1)   fprintf('.');end;
  30. end;
  31. res=mat(res);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement