Exemplo n.º 1
0
    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
Exemplo n.º 2
0
            for itemnum, item in enumerate(itemset):
                ss_items[itemnum] = usf_items[item]
                convertX[item] = itemnum

            items.append(ss_items)

            Xs = [[convertX[i] for i in x] for x in Xs]
            datab.append(Xs)

            seednum += numlists

        for listnum in range(1, len(data) + 1):
            print simnum, listnum
            flatdata = rw.flatten_list(data[:listnum])
            if 'rw' in methods:
                rw_graph = rw.noHidden(flatdata, usf_numnodes)
            if 'goni' in methods:
                goni_graph = rw.goni(flatdata,
                                     usf_numnodes,
                                     td=toydata,
                                     valid=0,
                                     fitinfo=fitinfo)
            if 'chan' in methods:
                chan_graph = rw.chan(flatdata, usf_numnodes)
            if 'kenett' in methods:
                kenett_graph = rw.kenett(flatdata, usf_numnodes)
            if 'fe' in methods:
                fe_graph = rw.firstEdge(flatdata, usf_numnodes)
            if 'uinvite' in methods:
                uinvite_graphs, priordict = rw.hierarchicalUinvite(
                    datab[:listnum],
Exemplo n.º 3
0
Arquivo: gui.py Projeto: ssyoon/semnet
def network_properties(command):
    subj_props = command['data_parameters']
    command = command['network_parameters']
    Xs, items, irts, numnodes = rw.readX(subj_props['subject'],
                                         subj_props['category'],
                                         subj_props['fullpath'])

    def no_persev(x):
        seen = set()
        seen_add = seen.add
        return [i for i in x if not (i in seen or seen_add(i))]

    toydata = rw.Data({
        'numx': len(Xs),
        'trim': 1,
        'jump': 0.0,
        'jumptype': "stationary",
        'priming': 0.0,
        'startX': "stationary"
    })
    fitinfo = rw.Fitinfo({
        'startGraph': "goni_valid",
        'goni_size': 2,
        'goni_threshold': 2,
        'followtype': "avg",
        'prior_samplesize': 10000,
        'recorddir': "records/",
        'prune_limit': 100,
        'triangle_limit': 100,
        'other_limit': 100
    })

    if command['network_method'] == "RW":
        bestgraph = rw.noHidden(Xs, numnodes)
    elif command['network_method'] == "Goni":
        bestgraph = rw.goni(Xs, numnodes, td=toydata, valid=0, fitinfo=fitinfo)
    elif command['network_method'] == "U-INVITE":
        no_persev_Xs = [no_persev(x) for x in Xs
                        ]  # U-INVITE doesn't work with perseverations
        bestgraph, ll = rw.uinvite(no_persev_Xs,
                                   toydata,
                                   numnodes,
                                   fitinfo=fitinfo,
                                   debug=False)

    nxg = nx.to_networkx_graph(bestgraph)

    node_degree = np.mean(nxg.degree().values())
    nxg_json = jsonGraph(nxg, items)
    clustering_coefficient = nx.average_clustering(nxg)
    try:
        aspl = nx.average_shortest_path_length(nxg)
    except:
        aspl = "disjointed graph"

    return {
        "type": "network_properties",
        "node_degree": node_degree,
        "clustering_coefficient": clustering_coefficient,
        "aspl": aspl,
        "graph": nxg_json
    }
Exemplo n.º 4
0
import random

allsubs=["S101","S102","S103","S104","S105","S106","S107","S108","S109","S110",
         "S111","S112","S113","S114","S115","S116","S117","S118","S119","S120"]

# free parameters
jeff=0.9           # 1-IRT weight
beta=1.1             # for gamma distribution when generating IRTs from hidden nodes

subj="S105"
category="animals"
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:
Exemplo n.º 5
0
import random

allsubs=["S101","S102","S103","S104","S105","S106","S107","S108","S109","S110",
         "S111","S112","S113","S114","S115","S116","S117","S118","S119","S120"]

# free parameters
beta=1.1             # for gamma distribution when generating IRTs from hidden nodes

subj="S120"
category="vegetables"

for subj in allsubs:
    Xs, items, irts, numnodes=rw.readX(subj,category,'exp/results_cleaned.csv')

    # Find best graphs!
    rw_graph = rw.noHidden(Xs,numnodes)
    rw_g=nx.to_networkx_graph(rw_graph) # use rw.drawDot instead
    nx.relabel_nodes(rw_g, items, copy=False)
    nx.write_dot(rw_g,subj+"_rw.dot")

    invite_graph, val=rw.findBestGraph(Xs)
    invite_g=nx.to_networkx_graph(invite_graph)
    nx.relabel_nodes(invite_g, items, copy=False)
    nx.write_dot(invite_g,subj+"_invite.dot")

    jeff=0.9           # IRT weight
    irt_graph, val=rw.findBestGraph(Xs, irts, jeff, beta)
    irt_g=nx.to_networkx_graph(irt_graph)
    nx.relabel_nodes(irt_g, items, copy=False)
    nx.write_dot(irt_g,subj+"_irt9.dot")
Exemplo n.º 6
0
Arquivo: s2.py Projeto: ssyoon/semnet
    "S110", "S111", "S112", "S113", "S114", "S115", "S116", "S117", "S118",
    "S119", "S120"
]

# free parameters
jeff = 0.9  # 1-IRT weight
beta = 1.1  # for gamma distribution when generating IRTs from hidden nodes

subj = "S001"
category = "animals"
Xs, items, irts, numnodes = rw.readX(subj, category, 's1_data.csv')

# 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):
Exemplo n.º 7
0
    changesmade = 0
    np.random.shuffle(subs)

    for subj in subs:
        print "ss: ", subj
        subj_idx = original_order.index(subj)
        toydata.numx = len(ss_Xs[subj_idx])
        fitinfo.startGraph = prior_graphs[subj_idx]

        prior = (priordict, prior_items[subj_idx])

        # find best graph
        uinvite_graph, bestval = rw.uinvite(ss_Xs[subj_idx],
                                            toydata,
                                            ss_numnodes[subj_idx],
                                            fitinfo=fitinfo,
                                            prior=prior)

        ## update prior if graph has changed
        if not np.array_equal(uinvite_graph, prior_graphs[subj_idx]):
            changesmade += 1
            prior_graphs[subj_idx] = uinvite_graph
            priordict = rw.genGraphPrior(prior_graphs, prior_items)

for subj in range(len(subs)):
    g = nx.to_networkx_graph(prior_graphs[subj])
    g2 = nx.to_networkx_graph(rw.noHidden(ss_Xs[subj], ss_numnodes[subj]))
    nx.relabel_nodes(g, prior_items[subj], copy=False)
    nx.relabel_nodes(g2, prior_items[subj], copy=False)
    rw.write_csv([g, g2], subj + ".csv", subj)  # write multiple graphs
Exemplo n.º 8
0
        'irttype': "exgauss",
        'exgauss_lambda': 0.721386887,
        'exgauss_sigma': 6.58655566,
        'irt_weight': 0.95,
        'rcutoff': 20
    })

    ss_irts.data = ss_irtdata
    irts.append(ss_irts)
    items.append(ss_items)
    Xs.append(ss_Xs)
    numnodes.append(ss_numnodes)

graphs, priordict = rw.hierarchicalUinvite(Xs,
                                           items,
                                           numnodes,
                                           toydata,
                                           fitinfo=fitinfo,
                                           seed=None,
                                           irts=irts)

for subnum, subj in enumerate(subs):
    g = nx.to_networkx_graph(graphs[subnum])
    g2 = nx.to_networkx_graph(rw.noHidden(Xs[subnum], numnodes[subnum]))
    nx.relabel_nodes(g, items[subnum], copy=False)
    nx.relabel_nodes(g2, items[subnum], copy=False)
    rw.write_csv([g, g2], subj + "_irt.csv", subj)  # write multiple graphs

with open('prior_irt.pickle', 'w') as fh:
    pickle.dump(priordict, fh)