예제 #1
0
def louvain(input_graph, max_iter=100, resolution=1.):
    """
    Compute the modularity optimizing partition of the input graph using the
    Louvain heuristic

    Parameters
    ----------
    input_graph : cugraph.Graph
        cuGraph graph descriptor of type Graph

        The adjacency list will be computed if not already present. The graph
        should be undirected where an undirected edge is represented by a
        directed edge in both direction.

    max_iter : integer
        This controls the maximum number of levels/iterations of the Louvain
        algorithm. When specified the algorithm will terminate after no more
        than the specified number of iterations. No error occurs when the
        algorithm terminates early in this manner.

    resolution: float/double, optional
        Called gamma in the modularity formula, this changes the size
        of the communities.  Defaults to 1.

    Returns
    -------
    parts : cudf.DataFrame
        GPU data frame of size V containing two columns the vertex id and the
        partition id it is assigned to.

        df['vertex'] : cudf.Series
            Contains the vertex identifiers
        df['partition'] : cudf.Series
            Contains the partition assigned to the vertices

    modularity_score : float
        a floating point number containing the global modularity score of the
        partitioning.

    Examples
    --------
    >>> M = cudf.read_csv('datasets/karate.csv',
                          delimiter = ' ',
                          dtype=['int32', 'int32', 'float32'],
                          header=None)
    >>> G = cugraph.Graph()
    >>> G.from_cudf_edgelist(M, source='0', destination='1')
    >>> parts, modularity_score = cugraph.louvain(G)
    """

    if type(input_graph) is not Graph:
        raise Exception("input graph must be undirected")

    parts, modularity_score = louvain_wrapper.louvain(input_graph, max_iter,
                                                      resolution)

    if input_graph.renumbered:
        parts = input_graph.unrenumber(parts, "vertex")

    return parts, modularity_score
예제 #2
0
def louvain(input_graph, max_iter=100):
    """
    Compute the modularity optimizing partition of the input graph using the
    Louvain heuristic

    Parameters
    ----------
    input_graph : cugraph.Graph
        cuGraph graph descriptor, should contain the connectivity information
        as an edge list.
        The adjacency list will be computed if not already present. The graph
        should be undirected where an undirected edge is represented by a
        directed edge in both direction.

    max_iter : integer
        This controls the maximum number of levels/iterations of the Louvain
        algorithm. When specified the algorithm will terminate after no more
        than the specified number of iterations. No error occurs when the
        algorithm terminates early in this manner.

    Returns
    -------
    parts : cudf.DataFrame
        GPU data frame of size V containing two columns the vertex id and the
        partition id it is assigned to.
    modularity_score : float
        a floating point number containing the modularity score of the
        partitioning.

    Examples
    --------
    >>> M = cudf.read_csv('datasets/karate.csv', delimiter=' ',
    >>>                   dtype=['int32', 'int32', 'float32'], header=None)
    >>> sources = cudf.Series(M['0'])
    >>> destinations = cudf.Series(M['1'])
    >>> G = cugraph.Graph()
    >>> G.add_edge_list(sources, destinations, None)
    >>> parts, modularity_score = cugraph.louvain(G)
    """

    if type(input_graph) is not Graph:
        raise Exception("input graph must be undirected")

    parts, modularity_score = louvain_wrapper.louvain(input_graph,
                                                      max_iter=max_iter)

    return parts, modularity_score
예제 #3
0
def louvain(input_graph):
    """
    Compute the modularity optimizing partition of the input graph using the
    Louvain heuristic

    Parameters
    ----------
    input_graph : cugraph.Graph
        cuGraph graph descriptor, should contain the connectivity information
        as an edge list.
        The adjacency list will be computed if not already present. The graph
        should be undirected where an undirected edge is represented by a
        directed edge in both direction.

    Returns
    -------
    parts : cudf.DataFrame
        GPU data frame of size V containing two columns the vertex id and the
        partition id it is assigned to.
    modularity_score : float
        a floating point number containing the modularity score of the
        partitioning.

    Examples
    --------
    >>> M = cudf.read_csv('datasets/karate.csv', delimiter=' ',
    >>>                   dtype=['int32', 'int32', 'float32'], header=None)
    >>> sources = cudf.Series(M['0'])
    >>> destinations = cudf.Series(M['1'])
    >>> G = cugraph.Graph()
    >>> G.add_edge_list(sources, destinations, None)
    >>> parts, modularity_score = cugraph.louvain(G)
    """

    parts, modularity_score = louvain_wrapper.louvain(input_graph.graph_ptr)

    return parts, modularity_score
예제 #4
0
파일: louvain.py 프로젝트: isVoid/cugraph
def louvain(input_graph, max_iter=100, resolution=1.):
    """
    Compute the modularity optimizing partition of the input graph using the
    Louvain method

    It uses the Louvain method described in:

    VD Blondel, J-L Guillaume, R Lambiotte and E Lefebvre: Fast unfolding of
    community hierarchies in large networks, J Stat Mech P10008 (2008),
    http://arxiv.org/abs/0803.0476

    Parameters
    ----------
    input_graph : cugraph.Graph
        cuGraph graph descriptor of type Graph

        The adjacency list will be computed if not already present.

    max_iter : integer
        This controls the maximum number of levels/iterations of the Louvain
        algorithm. When specified the algorithm will terminate after no more
        than the specified number of iterations. No error occurs when the
        algorithm terminates early in this manner.

    resolution: float/double, optional
        Called gamma in the modularity formula, this changes the size
        of the communities.  Higher resolutions lead to more smaller
        communities, lower resolutions lead to fewer larger communities.
        Defaults to 1.

    Returns
    -------
    parts : cudf.DataFrame
        GPU data frame of size V containing two columns the vertex id and the
        partition id it is assigned to.

        df['vertex'] : cudf.Series
            Contains the vertex identifiers
        df['partition'] : cudf.Series
            Contains the partition assigned to the vertices

    modularity_score : float
        a floating point number containing the global modularity score of the
        partitioning.

    Examples
    --------
    >>> M = cudf.read_csv('datasets/karate.csv',
                          delimiter = ' ',
                          dtype=['int32', 'int32', 'float32'],
                          header=None)
    >>> G = cugraph.Graph()
    >>> G.from_cudf_edgelist(M, source='0', destination='1')
    >>> parts, modularity_score = cugraph.louvain(G)
    """

    if type(input_graph) is not Graph:
        raise Exception("input graph must be undirected")

    parts, modularity_score = louvain_wrapper.louvain(input_graph, max_iter,
                                                      resolution)

    if input_graph.renumbered:
        parts = input_graph.unrenumber(parts, "vertex")

    return parts, modularity_score