function dirsketch(n) keyboard while 1 a = rand; P = fillprob(n,a); [hh,Ht,H] = gethhn(P,n,n); H = hh+eye(n); G=sqrt(H)'*sqrt(H); g = sqrt(max(eig(G))); hold on plot(a,g,'.'); drawnow end return function p = getprob(x,alf) p = 1; for t=1:length(x) P = conddistr(x(1:t-1),alf); if x(t)>length(P) p = 0; return end p = p * P(x(t)); end return function P = fillprob(n,alf) MN = repmat([n],[1 n]); mn = n^(n); P = zeros(mn,1); for xi = 1:mn x = ind2coord(xi,MN); P(xi) = getprob(x,alf); end return function P = conddistr(x,alf) % conditional distribution on next table % given the previous tables if isempty(x) P = 1; % always pick table 1 first else Uniq = unique(x(:)); N = length(Uniq); P = zeros(N+1,1); Ucnt = getucnt(x,Uniq); P(1:N) = alf * Ucnt/sum(Ucnt); P(N+1) = 1-alf; P = P/sum(P); end return function p = condprob0(x,alf) T = length(x); if T==1 p = (x==1); % always pick table 1 first else Uniq = unique(x(1:T-1)); if x(T) > max(Uniq)+1 p = 0; else Ucnt = getucnt(U,Uniq); end end return function Ucnt = getucnt(U,Uniq) Ucnt = zeros(size(Uniq)); for j=1:length(Uniq) Ucnt(j) = length(find(U==Uniq(j))); end return