function trivcollaps_conj 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; p00 = A0(1,1); p10 = 1-p00; p1 = A0(:,1); g=0; for b=2:nstate b %dd = sum(abs(A-repmat(p1,[1 nstate]))); %[a,b] = max(dd); %dd = abs(p00-A(1,:)); %[a,b] = max(dd); p01 = A0(1,b); p11 = 1-p01; %h0 = strict(A0); %p=p00; %if (p<.5) % q = p+h0; %else % q = p-h0; %end %q = max(0,q); %q = min(1,q); %p01 = q; %p11 = 1-q; A = [[p00 p01];[p10 p11]] B = zeros(nstate); B(1:2,1:2) = A; A=B+realmin; %ALLSEQ = collaps(ALLSEQ); %ALLSEQ1 = collaps(ALLSEQ1); Y_new = Y(Xi) if (abs(Y_old)<=abs(Y_new)+1e-10) 'good' g=1; break; else g=0; %'bad' end end if(~g) 'real bad' keyboard end %[h,i1,i2] = strict(A); %H = sum(h.^(0:lenseq-1)); %h0 = strict(A0) %h %if (abs(Y_old)<= H) % 'good' %else % 'bad!!!!!!!!!!!!!!!!!!!!!!!' % keyboard %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