function dst = nldist(me, dat, n, sigma, gam, prekern)

dsize = size(dat);
lgamma = gam;
nclust = n;
for d= 1:dsize(1)
	mylgamma(d) = kernel(me, dat(d,:));
end
prob = 0;
for c = 1:nclust
	A = lgamma(c,:)'*lgamma(c,:);
	dis = kernel(me,me)+sum(sum(A.*prekern))-2*sum(lgamma(c,:).*mylgamma);
	prob = prob+(1./(2*pi*sigma).^(dsize(2)/2))* exp((-1./(2*sigma^2))*(dis^2));
end
dst = prob;