#priorgraphs=[] #prioritems=[] #for osub in subs: # if osub != subj: # g, i = rw.read_csv('s2016.csv',cols=("node1","node2"),header=True,filters={"subj": osub, "uinvite": "1"}) # priorgraphs.append(g) # prioritems.append(i) #priordict = rw.genGraphPrior(priorgraphs, prioritems) toydata.numx = len(Xs) prior = (priordict, items) # u-invite uinvite_prior_graph, bestval = rw.uinvite(Xs, toydata, numnodes, fitinfo=fitinfo, prior=prior) # rw rw_graph = rw.noHidden(Xs, numnodes) g = nx.to_networkx_graph(uinvite_prior_graph) g2 = nx.to_networkx_graph(rw_graph) nx.relabel_nodes(g, items, copy=False) nx.relabel_nodes(g2, items, copy=False) rw.write_csv([g, g2], subj + "usf_sparse.csv", subj) # write multiple graphs
category="animals" Xs, items, irts.data, numnodes=rw.readX(subj,category,'./Spring2015/results_cleaned.csv',ignorePerseverations=True) # uinvite prior priorgraphs=[] prioritems=[] for osub in subs: if osub != subj: g, i = rw.read_csv('Sdirected2015.csv',cols=("node1","node2"),header=True,filters={"subj": osub, "uinvite": "1"},undirected=False) priorgraphs.append(g) prioritems.append(i) priordict = rw.genGraphPrior(priorgraphs, prioritems) toydata.numx = len(Xs) prior = (priordict, items) # u-invite directed_prior_graph, bestval=rw.uinvite(Xs, toydata, numnodes, fitinfo=fitinfo, prior=prior) # rw rw_graph=rw.noHidden(Xs, numnodes) g=nx.DiGraph(directed_prior_graph) g2=nx.DiGraph(rw_graph) nx.relabel_nodes(g, items, copy=False) nx.relabel_nodes(g2, items, copy=False) rw.write_csv([g, g2],subj+"_directed_prior_nosparse.csv",subj,directed=True) # write multiple graphs
# goni goni_graph=rw.goni(Xs, numnodes, td=toydata, valid=0, fitinfo=fitinfo) # prior #toygraphs.numnodes = numnodes #prior=rw.genSWPrior(toygraphs, fitinfo.prior_samplesize) #prior_graph, bestval=rw.uinvite(Xs, toydata, numnodes, fitinfo=fitinfo, prior=prior) # priming #toydata.priming = 0.5 #priming_graph, bestval=rw.uinvite(Xs, toydata, numnodes, fitinfo=fitinfo) # complete (irts, prior,, priming) #complete_graph, bestval=rw.uinvite(Xs, toydata, numnodes, fitinfo=fitinfo, prior=prior, irts=irts) #toydata.priming = 0.0 # reset priming g=nx.to_networkx_graph(rw_graph) g2=nx.to_networkx_graph(goni_graph) g3=nx.to_networkx_graph(uinvite_graph) g4=nx.to_networkx_graph(irt5_graph) g5=nx.to_networkx_graph(irt95_graph) nx.relabel_nodes(g, items, copy=False) nx.relabel_nodes(g2, items, copy=False) nx.relabel_nodes(g3, items, copy=False) nx.relabel_nodes(g4, items, copy=False) nx.relabel_nodes(g5, items, copy=False) rw.write_csv([g, g2, g3, g4, g5],subj+".csv",subj) # write multiple graphs
Xs, items, irts, numnodes=rw.readX(subj,category,'exp/results_cleaned.csv') # Find best graph! best_graph, bestval=rw.findBestGraph(Xs, irts, jeff, beta) best_rw=rw.noHidden(Xs, numnodes) # convert best graph to networkX graph, add labels, write to file g=nx.to_networkx_graph(best_graph) g2=nx.to_networkx_graph(best_rw) nx.relabel_nodes(g, items, copy=False) nx.relabel_nodes(g2, items, copy=False) #nx.write_dot(g,subj+".dot") # write to DOT #rw.write_csv(g,subj+".csv",subj) # write single graph rw.write_csv([g, g2],subj+".csv",subj) # write multiple graphs # write lists to file #with open(subj+'_lists.csv','w') as f: # for i, x in enumerate(Xs): # for item in x: # print>>f, str(i)+","+items[item] # items removed #for i in np.argwhere(graph5-oldgraph==-1): # if i[0]>i[1]: # skip duplicates # print items[i[0]],items[i[1]] # items added #for i in np.argwhere(graph5-oldgraph==1):
# Find best graph! #best_graph, bestval=rw.findBestGraph(Xs, irts, jeff, beta) best_graph, bestval = rw.findBestGraph(Xs, numnodes=numnodes) best_rw = rw.noHidden(Xs, numnodes) # convert best graph to networkX graph, add labels, write to file g = nx.to_networkx_graph(best_graph) g2 = nx.to_networkx_graph(best_rw) nx.relabel_nodes(g, items, copy=False) nx.relabel_nodes(g2, items, copy=False) #nx.write_dot(g,subj+".dot") # write to DOT #rw.write_csv(g,subj+".csv",subj) # write single graph rw.write_csv([g, g2], subj + ".csv", subj) # write multiple graphs # write lists to file #with open(subj+'_lists.csv','w') as f: # for i, x in enumerate(Xs): # for item in x: # print>>f, str(i)+","+items[item] # items removed #for i in np.argwhere(graph5-oldgraph==-1): # if i[0]>i[1]: # skip duplicates # print items[i[0]],items[i[1]] # items added #for i in np.argwhere(graph5-oldgraph==1): # if i[0]>i[1]: # skip duplicates
extra_data={} for inum, i in enumerate(uinvite_graph): for jnum, j in enumerate(i): if uinvite_graph[inum,jnum]==1: uinvite_graph[inum,jnum]=0 uinvite_graph[jnum,inum]=0 result=rw.probX(Xs, uinvite_graph, toydata, forceCompute=True) if items[inum] not in extra_data: extra_data[items[inum]]={} if items[jnum] not in extra_data: extra_data[items[jnum]]={} extra_data[items[inum]][items[jnum]] = (result[0], np.mean(rw.flatten_list(result[1]))) extra_data[items[jnum]][items[inum]] = (result[0], np.mean(rw.flatten_list(result[1]))) uinvite_graph[inum,jnum]=1 uinvite_graph[jnum,inum]=1 g=nx.to_networkx_graph(uinvite_graph) nx.relabel_nodes(g, items, copy=False) rw.write_csv(g,subj+".csv",subj,extra_data=extra_data) # write multiple graphs #@joe #what if we only include edges that are either bidirectional or uni-directional AND in the undirected graph #there's also a standard procedure for converting directed graphs into undirected graphs #it's called moralization # match edge density of USF network (i.e., prior on edges)
}) for subj in subs: category = "animals" Xs, items, irts.data, numnodes = rw.readX( subj, category, './Spring2015/results_cleaned.csv') uinvite_irt9, bestval = rw.uinvite(Xs, toydata, numnodes, fitinfo=fitinfo, irts=irts) irts.irt_weight = 0.95 uinvite_irt95, bestval = rw.uinvite(Xs, toydata, numnodes, fitinfo=fitinfo, irts=irts) irts.irt_weight = 0.5 uinvite_irt5, bestval = rw.uinvite(Xs, toydata, numnodes, fitinfo=fitinfo, irts=irts) g = nx.to_networkx_graph(uinvite_irt5) g2 = nx.to_networkx_graph(uinvite_irt9) g3 = nx.to_networkx_graph(uinvite_irt95) nx.relabel_nodes(g, items, copy=False) nx.relabel_nodes(g2, items, copy=False) nx.relabel_nodes(g3, items, copy=False) rw.write_csv([g, g2, g3], subj + "_irt.csv", subj) # write multiple graphs