function [ED2 A]=transD2tf(tf,doclen,T) %TRANSD2TF Expected (Translated) (L2Distance)^2 % % Arguments: % tf document term frequency (i.e., normalized) % N document lengths % T translation matrix % % Returns: % ED2 E_{p(y|x)} ( ||x_i-x_j||_2^2 ) % A E_{p(y|x)} ( ||x_i||_2^2 ) % % Authors: % Joshua V. Dillon; Feb. 26, 2007; jvdillon AAT purdue DDOT edu if nargin~=3 error('insufficient arguments'); end [Mv Nd] = size(tf); N = doclen'.^-1; TT = T*T'; B = tf' * TT * tf; A = diag(B) - N.*(tf'*diag(TT)) + N; ED2 = repmat(A,1,Nd) + repmat(A',Nd,1) - 2 * B; %tc=ceil(10*rand(5,3));tf=normalizeRows(tc')';N=sum(tc);T=normalizeRows(rand(5,5));transD2(tc,T)-transD2tf(tf,sum(tc),T)