itemsinXs = np.unique( rw.flatten_list(Xs)) # list of items that appear in toy data # reconstruct graph rw_graph = rw.noHidden(Xs, numnodes) ui_graph, bestval = rw.findBestGraph(Xs, numnodes=numnodes) # remove nodes not in X from all graphs before comparison rw_graph = rw_graph[itemsinXs, ] rw_graph = rw_graph[:, itemsinXs] ui_graph = ui_graph[itemsinXs, ] ui_graph = ui_graph[:, itemsinXs] usfcopy = np.copy(usf) usfcopy = usfcopy[itemsinXs, ] usfcopy = usfcopy[:, itemsinXs] sdt_rw = rw.costSDT(rw_graph, usfcopy) sdt_ui = rw.costSDT(ui_graph, usfcopy) sdt_rws.append(sdt_rw) sdt_uis.append(sdt_ui) towrite = rw.flatten_list([sdt_rw, sdt_ui]) towrite = ','.join([str(i) for i in towrite]) towrite = str(numlists) + ',' + str(listlength) + ',' + str( gnum) + ',' + towrite f.write(towrite) f.write('\n')
fe_graph = rw.firstEdge(flatdata, usf_numnodes) if 'uinvite' in methods: uinvite_graphs, priordict = rw.hierarchicalUinvite( datab[:listnum], items[:listnum], numnodes[:listnum], toydata, fitinfo=fitinfo) uinvite_group_graph = rw.priorToGraph(priordict, usf_items, cutoff=0.7) #JZ for method in methods: if method == "rw": costlist = [ rw.costSDT(rw_graph, usf_graph), rw.cost(rw_graph, usf_graph) ] if method == "goni": costlist = [ rw.costSDT(goni_graph, usf_graph), rw.cost(goni_graph, usf_graph) ] if method == "chan": costlist = [ rw.costSDT(chan_graph, usf_graph), rw.cost(chan_graph, usf_graph) ] if method == "kenett": costlist = [ rw.costSDT(kenett_graph, usf_graph),
graphs = alldata['uinvite_graphs'] items = alldata['items'][0:10] priordict = alldata['priordict'] # for old pickles. ha, that's kinda funny. if 'DEFAULTPRIOR' not in priordict.keys(): priordict['DEFAULTPRIOR'] = 0.5 # recompute for halfa... should be identical for a=1 #priordict = rw.genGraphPrior(graphs, items, a_inc=0.5) print rw.probXhierarchical(Xs, graphs, items, priordict, td) for cut in [j/20.0 for j in range(21)]: uinvite_group_graph = rw.priorToGraph(priordict, usf_items,cutoff=cut) asd=rw.costSDT(uinvite_group_graph, usf_graph) print ",".join([str(i) for i in [filename.split('.')[0], cut, asd[0], asd[2], asd[1]+asd[2]]]) # newmixturepe3 >> 281 # newmixturep275 >> 275 # newmixturep4 + cutoff=.8 >> 267 # constructed with a_inc=1 # [109, 284, 33, 12294] # -8531.6869171978178 # constructed with a_inc=0.5, prob checked with new prior a_inc=1.0 # [141, 252, 31, 12296] # -8474.0454830370072 # constructed with a_inc=0.5
Xs = [[convertX[i] for i in x] for x in Xs] datab.append(Xs) seednum += numlists listnum=10 uinvite_graphs, priordict = rw.hierarchicalUinvite(datab[:listnum], items[:listnum], numnodes[:listnum], toydata, fitinfo=fitinfo) uinvite_group_graph = rw.priorToGraph(priordict, usf_items) alldata=dict() alldata['uinvite_graphs'] = uinvite_graphs alldata['priordict'] = priordict alldata['uinvite_group_graph'] = uinvite_group_graph alldata['datab'] = datab alldata['items'] = items alldata['numnodes'] = numnodes #alldata['td'] = toydata #alldata['fitinfo'] = fitinfo fh=open(filename,"w") pickle.dump(alldata,fh) fh.close() costlist = [rw.costSDT(uinvite_group_graph, usf_graph), rw.cost(uinvite_group_graph, usf_graph)] costlist = rw.flatten_list(costlist) for i in costlist: print i, ",", print rw.probXhierarchical(datab[:listnum], uinvite_graphs[:listnum], items[:listnum], priordict, toydata)