function optcollapse global nstate global lenseq global ALLSEQ global ALLSEQ1 nstate = 4; lenseq = 6; global FN global NN NN = lenseq; %FN = randFN(nstate,NN); i0=1; ALLSEQ = list_all_ind(repmat(nstate,1,lenseq)); ALLSEQ1 = list_all_ind(repmat(nstate,1,lenseq-i0+1)); Xi = 1; % fix X for t=1:100 global A C A = pnormdim(rand(nstate,nstate),1) %C = pnormdim(rand(nstate,1),1) C = zeros(nstate,1); C(2)=1; Y_old = Y(Xi) A0=A; A = optcollapse(A) B = zeros(nstate); B(1:2,1:2) = A; A=B+realmin; Y_new = Y(Xi) if (abs(Y_old)<=abs(Y_new)+1e-10) 'good' g=1; %break; else g=0; 'bad' keyboard end end return function B = optcollapse(A) n = size(A,1); B = pnormdim(ones(2),1); maxh = 0; for k=1:n-1 combs = generate_combs(n,k); for c=1:size(combs,1) comb = combs(c,:); ii = find(comb); jj = find(~comb); ppi = mean(A(:,ii),2); ppj = mean(A(:,jj),2); p00 = sum(ppi(ii)); Pii = sum(ppi(ii)); Pij = sum(ppi(jj)); Pji = sum(ppj(ii)); Pjj = sum(ppj(jj)); b = [[Pii Pij];[Pji Pjj]]; h = strict(b); if h > maxh B = b; end end end return function XX=collaps(XX) global nstate %for n=3:nstate for j=1:size(XX,2) x = XX(:,j); ii = find(x~=1); x(ii) = 2*ones(size(ii)); XX(:,j) = x; end return function y = h(x) y = (x==1) + 2*(x~=1); return function y = evalF(FN,x) global nstate lenseq = length(x); FF = FN{lenseq}; ind = coord2ind(x,(repmat(nstate,1,lenseq))); y = FF(ind); return function r = F(x) global nstate %global lenseq if ~x(end), x=x(1:end-1); end; r = length(find(x~=1)); return lenseq = length(x); global FN FF = FN{lenseq}; ind = coord2ind(x,(repmat(nstate,1,lenseq))); r = FF(ind); 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 return