function newcollapse global nstate global lenseq global ALLSEQ global ALLSEQ1 nstate = 4; lenseq = 6; global FN global NN NN = lenseq; %FN = randFN(nstate,NN); %global ksi %ksi = 1; i0=1; Xi = 1; % fix X global A C A0 C0 ALLSEQ_n = list_all_ind(repmat(nstate,1,lenseq)); ALLSEQ1_n = list_all_ind(repmat(nstate,1,lenseq-i0+1)); ALLSEQ_2 = list_all_ind(repmat(2,1,lenseq)); ALLSEQ1_2 = list_all_ind(repmat(2,1,lenseq-i0+1)); for t=1:2 A = pnormdim(rand(nstate,nstate,lenseq-1),1); %A = pnormdim(rand(nstate,nstate,1),1); global A00 %A = A00; %A = zeros(4); %A = eye(4); %A(1:2,1:2) = ones(2); %A(3:4,3:4) = ones(2); %A = pnormdim(A+eps,1); %A = repmat(A,[1 1 lenseq-1]); %C = pnormdim(rand(nstate,1),1); %C = pnormdim(ones(nstate,1),1); C = zeros(nstate,1); C(2) = 1; C = C/sum(C); A0 = A; C0 = C; h0 = strict(A0); ALLSEQ = ALLSEQ_n; ALLSEQ1 = ALLSEQ1_n; Y1 = Y(Xi); %Y2 = Y_pr(Xi) % they match %Y2 = Y_gam % they match C = zeros(2,1); C(2) = 1; C = C/sum(C); ALLSEQ = ALLSEQ_2; ALLSEQ1 = ALLSEQ1_2; A = collapseA; %C = collapseC; h1 = strict(A); Y2 = Y(Xi); good = ((abs(Y1)<=abs(Y2)+1e-10) & (h1<=h0+1e-10)); if ~good 'BAAAAAAAAAAAAAAAAAAAAAAAAAAAD' keyboard end end return function B = collapseA global A [n,n,T] = size(A); B = zeros(2,2,T); for t=1:T B(:,:,t) = collapse_t(A(:,:,t)); end B = B + realmin; return function B = collapse_t(A) [n,n] = size(A); p1 = A(:,1); P1 = repmat(p1,[1 n]); dd = sum(abs(A-P1),1); [a,b] = max(dd); B(1,1) = A(1,1); %B(2,1) = 1-B(1,1); B(2,1) = A(b,1); B(1,2) = A(1,b); B(2,2) = A(b,b); B=pnormdim(B,1); return function r = F(x) global nstate %global lenseq if ~x(end), x=x(1:end-1); end; r = length(find(x~=1)); return function Ef = E(Xi) % E[f(X)|Xi] global ALLSEQ %global A Ef = 0; i = length(Xi); n = size(ALLSEQ,2); for k=1:size(ALLSEQ,1) x = ALLSEQ(k,:); p = P(x); if (i & (ih i1=i; i2=j; h=d; end % this stricture has the VERY NICE property % of not increasing after state collapse %d = max(d,max(abs(x-y))); % this is the OLD, BAD stricture def. % that's the problem that Sinai was so quick to point out % in my terminology, this stricture might increase after collapse end end end return