function tmpfunc2(M,Xii,aa,b0) X0 = simple_paths(M); RR = {}; for i=1:length(X0) RR{i} = spath2cell(M,X0{i}); end good = 1; while good for i=1:length(X0) x = sample_from_sp(RR{i},.8); fprintf('x = %s\n',x); y = 2*run_dfsa(M,x)-1; y_hat = compute_yhat_c(Xii,{x},aa,b0,@ptkermx); if y~=y_hat save PTFAIL x keyboard end end end return function s = sample_from_sp(R,lam) % larger lam => longer strings s = ''; for i=1:length(R) A = R{i}; if length(A)==1 s(end+1) = A; else while 1 a = randel(A); if a == '@' if rand > lam break end else s(end+1) = a; end end end end s = strrep(s,'@',''); return function R = spath2cell(M,s) R = {}; A = ['@' selfloops(M,M.q0)]; R{end+1} = A; q = M.q0; for i=1:length(s) s1 = s(i); R{end+1} = s1; q = dfsa_delta(M,q,s1); A = ['@' selfloops(M,q)]; R{end+1} = A; end return function LSEQ = str2Lseq(M0,s) LSEQ = {}; A = selfloops(M0,M0.q0); R = ''; if ~isempty(A) %R = [R setstar(A)]; A(end+1) = '@'; LSEQ{end+1} = A; end if ~isempty(s) q = M0.q0; for i=1:length(s) s1 = s(i); LSEQ{end+1} = s1; q = dfsa_delta(M0,q,s1); A = selfloops(M0,q); if ~isempty(A) R = [R setstar(A)]; A(end+1) = '@'; LSEQ{end+1} = A; end end end return function X = getsample(M) SP = simple_paths(M); %[X,w] = explicit_uw_pt(SP,zeros(size(SP))); %return ns = length(SP); X = {}; for i=1:ns u = SP{i}; if isempty(u) X = [X;{u}]; else LSEQ = str2Lseq(M,u); ss = list_all_ind_g(LSEQ); ss = cellstr(ss); for j=1:length(ss) ss{j} = strrep(ss{j},'@',''); end X = [X;ss]; end end cx = char(X); L = size(cx,2); [X,Y] = reglang_posneg_dense(0,L,M); %[X,bla] = explicit_uw_pt(X,zeros(size(X))); return [U,w] = explicit_uw_pt(SP,zeros(size(SP))); ns = length(SP); nu = length(U); MM = {}; for i=1:ns MS{i} = Phi(M,SP{i}); end MU = {}; for i=1:nu ui = U{i}; if isempty(ui) ui = '@'; end fprintf('processing U = %s \n',ui); MU{i} = bool2fsa_pt(['(' ui ')'],M.ALF); end X = {}; try PROGstart(ns*nu,'generating sample'); cnt = 0; for is = 1:ns for iu = 1:nu Msu = intersect_dfsa(MS{is},MU{iu}); [b,str] = accept_str(Msu); if b X{end+1} = str; end end cnt = cnt + 1; PROGupdate(cnt); end PROGend; catch keyboard end X = unique(X); return function Ms = Phi(M,s) % Ms is the regular (pt) language %% $\Phi(s) = \bigcup_{z\in\path_L\inv(s)} \{u: u\subseq z\} $ % no, it's just \path\inv(s) Ms = str2M(M,s,s); return Ms = null_dfsa(M.ALF); N = length(s); for i=1:2^N setstr = dec2bin(i-1,N); ii0 = find(setstr=='0'); si = s; si(ii0) = repmat('@',1,length(ii0)); Mi = str2M(M,si,s); Ms = union_dfsa(Ms,Mi); end return function A = selfloops(DFSA,q) %[pp,nss] = find(DFSA.delta==q); %ii = find(pp==q); %A = DFSA.ALF(nss(ii)); A = alltrans(DFSA,q,q); return function A = alltrans(DFSA,q0,q1) % all the letters that take q0 to q1 [pp,nss] = find(DFSA.delta==q1); ii = find(pp==q0); A = DFSA.ALF(nss(ii)); return function M = str2M(M0,s,s00) A = selfloops(M0,M0.q0); R = ''; if ~isempty(A) R = [R setstar(A)]; end if ~isempty(s) q = M0.q0; for i=1:length(s) s1 = s(i); if s1~='@' R = [R s1]; q = dfsa_delta(M0,q,s1); else q = dfsa_delta(M0,q,s00(i)); end A = selfloops(M0,q); if ~isempty(A) R = [R setstar(A)]; end end end M = gregexp2dfsa_fast(R,M0.ALF); return function M = unions(MM,alf) M = null_dfsa(alf); for i=1:length(MM) M = union_dfsa(M,MM{i}); end %M = remove_unreachable(M); %M = minimize_dfsa(M); return