Esempio n. 1
0
def community_evaluation_metrics(cdlib_coms):
    uG = cdlib_coms.graph

    # https://cdlib.readthedocs.io/en/latest/reference/evaluation.html
    embeddedness = evaluation.avg_embeddedness(uG, cdlib_coms, summary=False)
    average_internal_degree = evaluation.average_internal_degree(uG,
                                                                 cdlib_coms,
                                                                 summary=False)
    conductance = evaluation.conductance(uG, cdlib_coms, summary=False)
    transitivity = evaluation.avg_transitivity(uG, cdlib_coms, summary=False)
    cut_ratio = evaluation.cut_ratio(uG, cdlib_coms, summary=False)
    expansion = evaluation.expansion(uG, cdlib_coms, summary=False)
    edges_inside = evaluation.edges_inside(uG, cdlib_coms, summary=False)
    fraction_over_median_degree = evaluation.fraction_over_median_degree(
        uG, cdlib_coms, summary=False)
    hub_dominance = evaluation.hub_dominance(uG, cdlib_coms, summary=False)
    internal_edge_density = evaluation.internal_edge_density(uG,
                                                             cdlib_coms,
                                                             summary=False)
    max_odf = evaluation.max_odf(uG, cdlib_coms, summary=False)
    avg_odf = evaluation.avg_odf(uG, cdlib_coms, summary=False)
    flake_odf = evaluation.flake_odf(uG, cdlib_coms, summary=False)
    size = evaluation.size(uG, cdlib_coms, summary=False)
    triangle_participation_ratio = evaluation.triangle_participation_ratio(
        uG, cdlib_coms, summary=False)

    eval_dict = {
        'embeddedness': embeddedness,
        'average_internal_degree': average_internal_degree,
        'conductance': conductance,
        'transitivity': transitivity,
        'cut_ratio': cut_ratio,
        'expansion': expansion,
        'edges_inside': edges_inside,
        'fraction_over_median_degree': fraction_over_median_degree,
        'hub_dominance': hub_dominance,
        'internal_edge_density': internal_edge_density,
        'max_odf': max_odf,
        'avg_odf': avg_odf,
        'flake_odf': flake_odf,
        'size': size,
        'triangle_participation_ratio': triangle_participation_ratio
    }

    com_eval_df = pd.DataFrame(eval_dict)\
        .reset_index()\
        .rename({'index':'community_id'}, axis = 1)
    com_eval_df['community_id'] = com_eval_df['community_id'] + 1
    return com_eval_df
Esempio n. 2
0
    def flake_odf(self, **kwargs):
        """
        Fraction of nodes in S that have fewer edges pointing inside than to the outside of the algorithms.

        .. math:: f(S) = \\frac{| \{ u:u \in S,| \{(u,v) \in E: v \in S \}| < d(u)/2 \}|}{n_S}

        where :math:`E` is the graph edge set, :math:`v` is a node in :math:`S`, :math:`d(u)` is the degree of :math:`u` and :math:`n_S` is the set of algorithms nodes.

        :param summary: (optional, default True) if **True**, an overall summary is returned for the partition (min, max, avg, std); if **False** a list of community-wise score
        :return: a FitnessResult object/a list of community-wise score

        :Example:

        >>> from cdlib.algorithms import louvain
        >>> g = nx.karate_club_graph()
        >>> communities = louvain(g)
        >>> mod = communities.flake_odf()

        """
        if self.__check_graph():
            return evaluation.flake_odf(self.graph, self, **kwargs)
        else:
            raise ValueError("Graph instance not specified")