Exemplo n.º 1
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.º 2
0
#!/usr/bin/python

import pickle
import numpy as np
import rw
import networkx as nx
import sys

filename = sys.argv[1]

usf_graph, usf_items = rw.read_csv("./snet/USF_animal_subset.snet")
usf_graph_nx = nx.from_numpy_matrix(usf_graph)
usf_numnodes = len(usf_items)

td=rw.Data({
        'numx': 3,
        'trim': 35})


fh = open(filename,'r')
alldata = pickle.load(fh)
Xs = alldata['datab'][0:10]
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
Exemplo n.º 3
0
import rw
import networkx as nx
import numpy as np

usf_graph, usf_items = rw.read_csv("./snet/USF_animal_subset.snet")
usf_graph_nx = nx.from_numpy_matrix(usf_graph)
usf_numnodes = len(usf_items)

numsubs = 50
numlists = 3
listlength = 35
numsims = 1
#methods=['rw','goni','chan','kenett','fe']
methods = ['uinvite']

toydata = rw.Data({'numx': numlists, 'trim': listlength})

fitinfo = rw.Fitinfo({
    'startGraph': "goni_valid",
    'goni_size': 2,
    'goni_threshold': 2,
    'followtype': "avg",
    'prune_limit': np.inf,
    'triangle_limit': np.inf,
    'other_limit': np.inf
})

#toygraphs=rw.Graphs({
#        'numgraphs': 1,
#        'graphtype': "steyvers",
#        'numnodes': 280,