function talagtest(m0,n0) global m n randomize m = m0; n = n0; global myopt myopt = optimset('Diagnostics','off'); myopt = optimset('Display','off'); warning off warning('off'); global pstr pstr = mfilename global lstr rstr global maxr maxr = 0; global P X A Xii Aii Xii = [1:m^n]'; X=ind2coord(Xii,repmat([m],[1 n])); while 1 % draw random product measure P = unifP(m,1); for i = 1:n-1 P = tensprod(P,unifP(m,1)); end % make it nonproduct! P = unifP(m,n); % mess with it P = 0*P; P(1)=1/2; P(end)=1/2; %P=customproc1eqn; P % pick random subset A while 1 %Aii = rand_subset(1:m^n); %Aii = randbigset; Aii = 1; A = X(Aii,:); PA = sum(P(Aii)); %if ~isempty(Aii) if PA > 1/2-1e-9 break end end Aii %% test taladist %xi = randel(1:m^n); %x = X(xi,:); %d0 = talabrute(x,A,m,n); %d1 = taladist(x,A,m,n); %if abs(d0-d1)>1e-9 % 'bad' % keyboard %end if 1 % get enlargement %t = randinseg(0,sqrt(n)); %t = randinseg(0,1); %[At,Atii] = getAt(t); %t = minimize_t(Aii,t); [cAii,dd]= getcAdd; ut = unique(dd); for ti = 1:length(ut) t = ut(ti); ai = find(dd>=t); Atii = cAii(ai); lhs = sum(P(Atii)); %rhs = exp(-t^2/4)/sum(P(Aii)); rhs = exp(-t^2/4)/PA; r = lhs/rhs; maxr = max(r,maxr); fprintf('%s: PARAMS: n=%d m=%d \n',pstr,n,m); fprintf('RATIO maxr ==============================================================%1.9f \n',maxr); if maxr > 1 keyboard end end end end return function Aii = randbigset global m n P X A Xii Aii Aii = []; rp = randperm(m^n); for i=1:length(rp) PA = sum(P(Aii)); if PA >= 1/2 break else Aii(end+1) = rp(i); end end return function [cAii,dd]= getcAdd global m n X A Xii Aii cAii = setdiff(Xii,Aii); %cA = X(cAii,:); dd = zeros(size(cAii)); for ai = 1:length(cAii) xi = cAii(ai); x = X(xi,:); [d,w] = talabrute(x,A,m,n); dd(ai) = d; end return function [At,Atii] = getAt(t) global m n X A Xii Aii Atii0 = setdiff(Xii,Aii); Atii = []; for ai = 1:length(Atii0) xi = Atii0(ai); x = X(xi,:); [d,w] = talabrute(x,A,m,n); if d > t Atii(end+1) = xi; end end At = X(Atii,:); return function t = minimize_t(Aii,t0) L = 0; H = t0; while (H-L > 1e-5) t = (H+L)/2; [At,Atii] = getAt(t); if length(Atii) < length(Aii) % set has shrunk % increse t L = t; else % set has not shrunk % decrease t H = t; end end return function P=customproc1eqn global m n P = ones(m^n,1); for xi=1:m^n x = i2c(xi); P(xi) = (x(1)==x(end)); % good end P = P+eps; P=P/sum(P); return