当前位置: 首页>>代码示例>>Python>>正文


Python networkx.read_weighted_edgelist函数代码示例

本文整理汇总了Python中networkx.read_weighted_edgelist函数的典型用法代码示例。如果您正苦于以下问题:Python read_weighted_edgelist函数的具体用法?Python read_weighted_edgelist怎么用?Python read_weighted_edgelist使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了read_weighted_edgelist函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: weightiest_edges

def weightiest_edges(network, n=20, d="directed"):
    """Find top n edges with highest weights and
    write results in the new file.

    Parameters
    ----------
    network : network edge list
    n : int
        number of wanted edges
    d : directed or undirected
        type of graph
    """
    if d == "directed":
        g = nx.read_weighted_edgelist(network, create_using=nx.DiGraph())
    elif d == "undirected":
        g = nx.read_weighted_edgelist(network)

    if g.number_of_edges() < n:
        n = g.number_of_edges()

    weight_dict = {(u, v): i['weight'] for (u, v, i) in g.edges(data=True)}
    weight_list = [edge for edge in weight_dict.iteritems()]
    weight_list.sort(key=lambda x: x[1])
    weight_list.reverse()

    with open(network.rsplit(".", 1)[0] + "_weightiest_edges.txt", "w",
              encoding="utf-8") as write_f:
        for i, value in enumerate(weight_list):
            if i < n:
                write_f.write(str(value[0][0]) + "\t\t: " +
                              str(value[0][1]) + "\t\t" + str(value[1]) + "\n")
            else:
                break
开发者ID:Autodidact24,项目名称:LaNCoA,代码行数:33,代码来源:content_analysis.py

示例2: hubs

def hubs(network, n=20, d="directed"):
    """Find top n nodes with highest degree and
    write results in the new file.

    Parameters
    ----------
    network : network edge list
    n : int
        number of wanted nodes
    d : directed or undirected
        if directed is selected than two new files
        will be created. One for in-degree and one
        for out-degree
    """
    n = int(n)

    if d == "directed":
        g = nx.read_weighted_edgelist(network, create_using=nx.DiGraph())
        if g.number_of_nodes() < n:
            n = int(g.number_of_nodes())

        degree_list_in = [node for node in g.in_degree().iteritems()]
        degree_list_in.sort(key=lambda x: x[1])
        degree_list_in.reverse()
        degree_list_out = [node for node in g.out_degree().iteritems()]
        degree_list_out.sort(key=lambda x: x[1])
        degree_list_out.reverse()

        with open(network.rsplit(".", 1)[0] + "_hubs_in.txt", "w",
                  encoding="utf-8") as write_f_in:
            for i, value in enumerate(degree_list_in):
                if i < n:
                    write_f_in.write(str(value[0]) + "\t\tIn-degree: " + str(value[1]) + "\n")
                else:
                    break

        with open(network.rsplit(".", 1)[0] + "_hubs_out.txt", "w",
                  encoding="utf-8") as write_f_out:
            for i, value in enumerate(degree_list_out):
                if i < n:
                    write_f_out.write(str(value[0]) + "\t\tOut-degree: " + str(value[1]) + "\n")
                else:
                    break

    elif d == "undirected":
        g = nx.read_weighted_edgelist(network)
        if g.number_of_nodes() < n:
            n = int(g.number_of_nodes())

        degree_list = [node for node in g.degree().iteritems()]
        degree_list.sort(key=lambda x: x[1])
        degree_list.reverse()

        with open(network.rsplit(".", 1)[0] + "_hubs.txt", "w",
                  encoding="utf-8") as write_f:
            for i, value in enumerate(degree_list):
                if i < n:
                    write_f.write(str(value[0]) + "\t\tDegree: " + str(value[1]) + "\n")
                else:
                    break
开发者ID:Autodidact24,项目名称:LaNCoA,代码行数:60,代码来源:content_analysis.py

示例3: total_overlap

def total_overlap(network1, network2, d="directed"):
    """Returns value of total overlap measure for
    two given networks of the same sets of nodes.

    Parameters
    ----------
    network1 : first network edge list
    network2 : second network edge list
    d : directed or undirected
        type of graph

    Returns
    -------
    t_overlap : float
    """
    if d == "directed":
        g1 = nx.read_weighted_edgelist(network1, create_using=nx.DiGraph())
        g2 = nx.read_weighted_edgelist(network2, create_using=nx.DiGraph())
    elif d == "undirected":
        g1 = nx.read_weighted_edgelist(network1)
        g2 = nx.read_weighted_edgelist(network2)

    overlap = 0
    for i in g1.edges():
        if g2.has_edge(i[0], i[1]):
            overlap += 1

    t_overlap = (float(overlap) / float(nx.compose(g1, g2).number_of_edges()))

    return t_overlap
开发者ID:Autodidact24,项目名称:LaNCoA,代码行数:30,代码来源:overlaps.py

示例4: main

def main():
	parser = argparse.ArgumentParser()
	parser.add_argument('edgelist')
	parser.add_argument('outfile', nargs='?')
	parser.add_argument('-t', '--interconnectivity', default=0.83, type=float)
	parser.add_argument('-d', '--density', default=0.83, type=float)
	parser.add_argument('-m', '--min-edge', default=0.05, type=float)
	parser.add_argument('-l', '--linkage', default='average')
	parser.add_argument('-a', '--authorprefeat', default='generated/Author_prefeat.pickle')
	args = parser.parse_args()

	if args.outfile == None:
		args.outfile = args.edgelist.replace('.prob','') + '.clusters'

	threshold_min_weight = args.min_edge
	threshold_interconnectivity = args.interconnectivity
	threshold_density = args.density

	print_err("Loading graph")
	G_sim = nx.read_weighted_edgelist(enforce_min(skip_comments(open(args.edgelist, 'rb')), threshold_min_weight), nodetype=int, delimiter=',')
	print_err('Loaded (V={:}, E={:})'.format(len(G_sim), G_sim.size()))

	print_err("Clustering")
	clusters = hcluster(G_sim, threshold_interconnectivity, args.linkage)

 	print_err("Writing clusters")
 	
	G_nsim = nx.read_weighted_edgelist(skip_comments(open(args.edgelist, 'rb')), nodetype=int, delimiter=',')

	print_err("Loading pickled author pre-features")
  	authors = pickle.load(open(args.authorprefeat, 'rb'))

 	outputClusters(clusters, open(args.outfile, 'wb'), G_nsim, authors, threshold_density)
开发者ID:wonglkd,项目名称:KDDCup13Track2,代码行数:33,代码来源:cluster_hc.py

示例5: jaccard

def jaccard(network1, network2, d="directed"):
    """Returns Jaccard similarity coefficient and
    distance of two different networks of the same
    sets of nodes.

    Parameters
    ----------
    network1 : first network edge list
    network2 : second network edge list
    d : directed or undirected
        type of graph

    Returns
    -------
    j : float
        Jaccard similarity coefficient
    jd : float
        Jaccard distance
    """
    if d == "directed":
        g1 = nx.read_weighted_edgelist(network1, create_using=nx.DiGraph())
        g2 = nx.read_weighted_edgelist(network2, create_using=nx.DiGraph())
    elif d == "undirected":
        g1 = nx.read_weighted_edgelist(network1)
        g2 = nx.read_weighted_edgelist(network2)

    union = nx.compose(g1, g2)
    inter = nx.intersection(g1, g2)

    j = float(inter.number_of_edges()) / float(union.number_of_edges())
    jd = 1 - j

    return j, jd
开发者ID:Autodidact24,项目名称:LaNCoA,代码行数:33,代码来源:overlaps.py

示例6: create_network

    def create_network(self, nodes, edges, nodes_max_length, edges_min_weight):

        # limit network size
        top_nodes=self.get_top_nodes(nodes,nodes_max_length)
        print "%d top_nodes"%len(top_nodes)

        top_edges=self.get_edges_containing_nodes(edges, top_nodes)
        print "%d top_edges"%len(top_edges)

        weighted_edges = self.get_weigthed_edges(top_edges, edges_min_weight)

        weighted_edges_str=[
                str(nodes.index(w[0]))+" "+str(nodes.index(w[1]))+" "+str(w[2])
                for w in weighted_edges
                ]

        # create graph object
        G = nx.read_weighted_edgelist(weighted_edges_str, nodetype=str, delimiter=" ",create_using=nx.DiGraph())

        # dimensions
        N,K = G.order(), G.size()
        print "Nodes: ", N
        print "Edges: ", K

        return G
开发者ID:ungentilgarcon,项目名称:topogram,代码行数:25,代码来源:old_topogram.py

示例7: getAllPaths

def getAllPaths():
    #import matplotlib.pyplot as plt
    
    g = nx.read_weighted_edgelist("hb.txt")   
    
    #print g["ASPA0085"]["HOHA0402"]
    
    
         
    fp = open("allpaths.txt", 'w')
    
    try:
        counter = 1
        for eachPath in nx.all_shortest_paths(g, u"ASPA0085", u"GLUA0194"):
            if not isValidPath(eachPath):
                continue
            fp.write("path%d" % counter)
            for eachResidue in eachPath:
                fp.write('%10s' % eachResidue)
            fp.write('\n')
            counter += 1
    except nx.exception.NetworkXNoPath:
        fp.write("No connected pathway\n")
    finally:
        fp.close()
开发者ID:zxiaoyao,项目名称:br_pscript,代码行数:25,代码来源:setuphbrun.py

示例8: loadGraphs

def loadGraphs(filenames, verb=False):
    """
    Given a list of files, returns a dictionary of graphs

    Required parameters:
        filenames:
            - List of filenames for graphs
    Optional parameters:
        verb:
            - Toggles verbose output statements
    """
    #  Initializes empty dictionary
    if type(filenames) is not list:
        filenames = [filenames]
    gstruct = OrderedDict()
    for idx, files in enumerate(filenames):
        if verb:
            print("Loading: " + files)
        #  Adds graphs to dictionary with key being filename
        fname = os.path.basename(files)
        try:
            gstruct[fname] = nx.read_weighted_edgelist(files) 
        except:
            try:
                gstruct[fname] = nx.read_gpickle(files)
            except:
                gstruct[fname] = nx.read_graphml(files)
    return gstruct
开发者ID:gkiar,项目名称:ndmg,代码行数:28,代码来源:loadGraphs.py

示例9: selectivity

def selectivity(network):
    """Calculate selectivity for each node
    in graph and write results in dictionary.

    Parameters
    ----------
    network : edge list of network

    Returns
    -------
    selectivity_dict : dict
        a dictionary where keys are graph nodes
        and values are calculated selectivity
    """
    g = nx.read_weighted_edgelist(network)

    selectivity_dict = {}
    for node in g.nodes():
        s = g.degree(node, weight="weight")
        k = g.degree(node, weight=None)
        if k > 0:
            selectivity = s / k
            selectivity_dict[node] = selectivity
        else:
            selectivity_dict[node] = 0

    return selectivity_dict
开发者ID:Autodidact24,项目名称:LaNCoA,代码行数:27,代码来源:measures.py

示例10: main

def main():
    parser = createParser()
    options = parser.parse_args()

    gtGraphNames = glob.glob("{0}/*.sim.cut".format(options.gtruth))
    gtGraphs = { fn.split("/")[-1][:-8] : nx.read_edgelist(fn) for fn in gtGraphNames }
    print(gtGraphs)
    print(gtGraphNames)

    oGraphNames = [ "{0}/{1}.out.ppi".format(options.other, k) for k in gtGraphs.keys() ]
    oGraphs = { fn.split("/")[-1][:-8] : nx.read_weighted_edgelist(fn) for fn in oGraphNames }
    inputGraphNames = glob.glob("{0}/bZIP*.cut".format(options.other))
    print(inputGraphNames)
    inputGraph = nx.read_edgelist(inputGraphNames[0])
    print(oGraphNames)

    cutoff = 0.99
    paranaGraph = graphWithCutoff(options.parana, 0.0)
    c = findSuggestedCutoff( paranaGraph, inputGraph, cutoff )
    evaluation.printStats( filteredGraph(paranaGraph, inputGraph.nodes(), cutoff=c ), inputGraph )
    print >>sys.stderr, "Parana 2.0    : {0}".format(getCurve(paranaGraph, inputGraph))



    for gtName, gtGraph in gtGraphs.iteritems():
        print(gtName)
        c = findSuggestedCutoff( paranaGraph, gtGraph, cutoff )
        print("Parana cutoff = {0}".format(c))
        print("==================")
        evaluation.printStats( filteredGraph(oGraphs[gtName], gtGraph.nodes()), gtGraph )
        print >>sys.stderr, "Pinney et. al : {0}".format(getCurve(oGraphs[gtName], gtGraph))
        evaluation.printStats( filteredGraph(paranaGraph, gtGraph.nodes(), cutoff=c ), gtGraph )
        print >>sys.stderr, "Parana 2.0    : {0}".format(getCurve(paranaGraph, gtGraph))
        print("\n")
    sys.exit(0)
开发者ID:rob-p,项目名称:Parana2-CPP,代码行数:35,代码来源:AnalyzePredictions.py

示例11: read_test_trps_txt

def read_test_trps_txt(path, toNX=False, skip = 0):
# Accepts path to TEST_FNAME
# If toNX, returns a nx.DiGraph, otherwise returns a ndarray
# Can be given a number of rows to skip, ndarray case only
    if toNX:
        return nx.read_weighted_edgelist(path + TEST_FNAME, create_using=nx.DiGraph(), nodetype=int)
    return np.loadtxt(path + TEST_FNAME, skiprows = skip)
开发者ID:JonathanShor,项目名称:COS424-HW-trey,代码行数:7,代码来源:Utils.py

示例12: edges

def edges(currentNode):
  # hardcoded source for graph
  g = nx.read_weighted_edgelist("example_4_pathfind.graph",
        nodetype=str,create_using=nx.DiGraph())
  # output successors
  for node in g.successors(currentNode.value()):
    dlvhex.output( (node,) )
开发者ID:hexhex,项目名称:manual,代码行数:7,代码来源:example_4_pathfind.py

示例13: reciprocity

def reciprocity(network):
    """Returns reciprocity of the given network.

    Parameters
    ----------
    network : edge list of the network

    Returns
    -------
    r : float
        network reciprocity
    a : float
        the ratio of observed to possible directed links
    ro : float
        Garlaschelli and Loffredo's definition of reciprocity
    """
    g = nx.read_weighted_edgelist(network, create_using=nx.DiGraph())

    self_loops = g.number_of_selfloops()
    r = sum([g.has_edge(e[1], e[0]) for e in g.edges_iter()]) / float(g.number_of_edges())

    a = (g.number_of_edges() - self_loops) / (float(g.number_of_nodes()) * float((g.number_of_nodes() - 1)))

    ro = float((r - a)) / float((1 - a))

    return r, a, ro
开发者ID:Autodidact24,项目名称:LaNCoA,代码行数:26,代码来源:measures.py

示例14: __init__

 def __init__(self):
     self.G = nx.read_weighted_edgelist(
         CliqueSpy.get_data_dir() + CliqueSpy.SINGER_GRAPH_FILE,
         delimiter=';',
         encoding='utf-8'
     )
     self.G.remove_edges_from(self.G.selfloop_edges())
     self.singer_dict = CliqueSpy.read_dict(CliqueSpy.get_data_dir() + CliqueSpy.SINGER_DICT)
开发者ID:vslovik,项目名称:ARS,代码行数:8,代码来源:cliques_spy.py

示例15: edges

def edges(fileName, currentNode):
    # Sources will be loaded from the file
    g = nx.read_weighted_edgelist(fileName.value().strip('"'), nodetype=str, create_using=nx.DiGraph())
    # Output successor nodes of the current node including weight
    for node in g.successors(currentNode.value()):
        weight = g[currentNode.value()][node]["weight"]
        # produce one output tuple
        dlvhex.output((node, int(weight)))
开发者ID:hexhex,项目名称:manual,代码行数:8,代码来源:example_4_travel.py


注:本文中的networkx.read_weighted_edgelist函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。