示例#1
0
文件: graph.py 项目: zwytop/Circulo
def compute_metrics(G, refresh=True):

    descriptTLU = 'TLU--Local Clustering Coefficient'
    descriptDegree = 'Degree Statistics'

    if refresh or G.metrics == None:

        #we treat a single node graph to have a density of 1
        #TODO: This is undefined for multigraphs. Prob should simplify if this happens
        density = G.density() if G.vcount() > 1 else 1.0

        G.metrics = {
            'Internal Number Nodes':
            G.vcount(),
            'Internal Number Edges':
            G.ecount(),
            'Density':
            density,
            'Diameter':
            G.diameter(),
            'Cohesiveness':
            G.cohesiveness(),
            'Triangle Participation Ratio':
            G.triangle_participation_ratio(),
            'Transitivity Undirected (Global Clustering Coefficient)':
            G.transitivity_undirected(mode='zero')
        }
        G.metrics.update(
            aggregate(G.transitivity_local_undirected(mode='zero'),
                      prefix=descriptTLU))
        G.metrics.update(aggregate(G.degree(), prefix=descriptDegree))
示例#2
0
def compute_metrics(G, refresh = True):

    descriptTLU = 'TLU--Local Clustering Coefficient'
    descriptDegree = 'Degree Statistics'

    if refresh or G.metrics == None:
        G.metrics = {
                'Internal Number Nodes'         : G.vcount(),
                'Internal Number Edges'         : G.ecount(),
                'Density'                       : G.density(),
                'Diameter'                      : G.diameter(),
                'Cohesiveness'                  : G.cohesiveness(),
                'Triangle Participation Ratio'  : G.triangle_participation_ratio(),
                'Transitivity Undirected (Global Clustering Coefficient)'
                                                : G.transitivity_undirected()
                                                }

        G.metrics.update(aggregate(G.transitivity_local_undirected(mode='zero'), prefix=descriptTLU))
        G.metrics.update(aggregate(G.degree(), prefix=descriptDegree))
示例#3
0
文件: graph.py 项目: Bubblbu/Circulo
def compute_metrics(G, refresh = True):

    descriptTLU = 'TLU--Local Clustering Coefficient'
    descriptDegree = 'Degree Statistics'

    if refresh or G.metrics == None:

        #we treat a single node graph to have a density of 1
        #TODO: This is undefined for multigraphs. Prob should simplify if this happens
        density = G.density() if G.vcount() > 1 else 1.0

        G.metrics = {
                'Internal Number Nodes'         : G.vcount(),
                'Internal Number Edges'         : G.ecount(),
                'Density'                       : density,
                'Diameter'                      : G.diameter(),
                'Cohesiveness'                  : G.cohesiveness(),
                'Triangle Participation Ratio'  : G.triangle_participation_ratio(),
                'Transitivity Undirected (Global Clustering Coefficient)'
                                                : G.transitivity_undirected(mode='zero')
                                                }
        G.metrics.update(aggregate(G.transitivity_local_undirected(mode='zero'), prefix=descriptTLU))
        G.metrics.update(aggregate(G.degree(), prefix=descriptDegree))
示例#4
0
文件: cover.py 项目: Minimong/Circulo
def compute_metrics(cover, weights=None, ground_truth_cover=None):
    t0 = time.time()

    fomd_results = fomd(cover, weights)
    expansion_results = expansion(cover, weights)
    cut_ratio_results = cut_ratio(cover)
    conductance_results = conductance(cover, weights)
    n_cut_results = normalized_cut(cover, weights)
    max_out_results = maximum_out_degree_fraction(cover, weights)
    avg_out_results = average_out_degree_fraction(cover, weights)
    flake_odf_results = flake_out_degree_fraction(cover, weights)
    sep_results = separability(cover,weights)

    results_key = "results"
    agg_key = "aggegations"

    cover.metrics = {
            'Fraction over a Median Degree' : {results_key:fomd_results, agg_key:aggregate(fomd_results)},
            'Expansion'                     : {results_key:expansion_results, agg_key:aggregate(expansion_results)},
            'Cut Ratio'                     : {results_key:cut_ratio_results, agg_key:aggregate(cut_ratio_results)},
            'Conductance'                   : {results_key:conductance_results, agg_key:aggregate(conductance_results)},
            'Normalized Cut'                : {results_key:n_cut_results, agg_key:aggregate(n_cut_results)},
            'Maximum Out Degree Fraction'   : {results_key:max_out_results, agg_key:aggregate(max_out_results)},
            'Average Out Degree Fraction'   : {results_key:avg_out_results, agg_key:aggregate(avg_out_results)},
            'Flake Out Degree Fraction'     : {results_key:flake_odf_results, agg_key:aggregate(flake_odf_results)},
            'Separability'                  : {results_key:sep_results, agg_key:aggregate(sep_results)},
            }

    for i in range(len(cover)):
        sg = cover.subgraph(i)
        sg.compute_metrics(refresh=False)

        #we want to add the metrics from the subgraph calculations to the current cover. The cover and
        #subgraph are essentially the same thing, however because we use the igraph graph functions we
        #can't natively call these call a cover...  hence the need to transfer over the results
        for key, val in sg.metrics.items():
            if key not in cover.metrics:
                cover.metrics[key] = {results_key:[], agg_key:None}
            cover.metrics[key][results_key] += [val]

    #aggregate just the results from the subgraph metrics
    for k  in sg.metrics.keys():
        cover.metrics[k][agg_key] = aggregate(cover.metrics[k][results_key])

    cover.metrics['omega'] = compare_omega(cover, ground_truth_cover)
    cover.metrics['metrics_total_time'] = time.time() - t0
示例#5
0
文件: cover.py 项目: zwytop/Circulo
def compute_metrics(cover, weights=None, ground_truth_cover=None):
    t0 = time.time()

    fomd_results = fomd(cover, weights)
    expansion_results = expansion(cover, weights)
    cut_ratio_results = cut_ratio(cover)
    conductance_results = conductance(cover, weights)
    n_cut_results = normalized_cut(cover, weights)

    # Get out degree fraction results then reuse for max, average, flake
    odf = out_degree_fraction(cover, weights)
    odf = odf.tocsc()
    max_out_results = maximum_out_degree_fraction(cover,
                                                  odf=odf,
                                                  weights=weights)
    avg_out_results = average_out_degree_fraction(cover,
                                                  odf=odf,
                                                  weights=weights)
    flake_odf_results = flake_out_degree_fraction(cover,
                                                  odf=odf,
                                                  weights=weights)
    sep_results = separability(cover, weights)
    results_key = "results"
    agg_key = "aggregations"

    cover.metrics = {
        'Fraction over a Median Degree': {
            results_key: fomd_results,
            agg_key: aggregate(fomd_results)
        },
        'Expansion': {
            results_key: expansion_results,
            agg_key: aggregate(expansion_results)
        },
        'Cut Ratio': {
            results_key: cut_ratio_results,
            agg_key: aggregate(cut_ratio_results)
        },
        'Conductance': {
            results_key: conductance_results,
            agg_key: aggregate(conductance_results)
        },
        'Normalized Cut': {
            results_key: n_cut_results,
            agg_key: aggregate(n_cut_results)
        },
        'Maximum Out Degree Fraction': {
            results_key: max_out_results,
            agg_key: aggregate(max_out_results)
        },
        'Average Out Degree Fraction': {
            results_key: avg_out_results,
            agg_key: aggregate(avg_out_results)
        },
        'Flake Out Degree Fraction': {
            results_key: flake_odf_results,
            agg_key: aggregate(flake_odf_results)
        },
        'Separability': {
            results_key: sep_results,
            agg_key: aggregate(sep_results)
        },
    }

    for i in range(len(cover)):
        sg = cover.subgraph(i)
        sg.compute_metrics(refresh=False)
        #we want to add the metrics from the subgraph calculations to the current cover. The cover and
        #subgraph are essentially the same thing, however because we use the igraph graph functions we
        #can't natively call these call a cover...  hence the need to transfer over the results
        for key, val in sg.metrics.items():
            if key not in cover.metrics:
                cover.metrics[key] = {results_key: [], agg_key: None}
            cover.metrics[key][results_key] += [val]
    #aggregate just the results from the subgraph metrics
    for k in sg.metrics.keys():
        cover.metrics[k][agg_key] = aggregate(cover.metrics[k][results_key])