(data, normalize, pca_components, k_neighbors, metric, resolution, state)
return res
Run the louvain clustering on `data`.

    state is used to report progress and partial results. Returns early if
    `task.is_interuption_requested()` returns true.

    Parameters
    ----------
    data : Table
        Data table
    normalize : bool
        If `True`, the data is first normalized before computing PCA.
    pca_components : Optional[int]
        If not `None` then the data is first projected onto first
        `pca_components` principal components.
    k_neighbors : int
        Passed to `table_to_knn_graph`
    metric : str
        Passed to `table_to_knn_graph`
    resolution : float
        Passed to `Louvain`
    state : TaskState

    Returns
    -------
    res : Results
Run the louvain clustering on `data`.
Run the louvain clustering on data .
def run_on_data(data, normalize, pca_components, k_neighbors, metric, resolution, state):
    # type: (Table, Optional[int], int, str, float, bool, TaskState) -> Results
    """
    Run the louvain clustering on `data`.

    state is used to report progress and partial results. Returns early if
    `task.is_interuption_requested()` returns true.

    Parameters
    ----------
    data : Table
        Data table
    normalize : bool
        If `True`, the data is first normalized before computing PCA.
    pca_components : Optional[int]
        If not `None` then the data is first projected onto first
        `pca_components` principal components.
    k_neighbors : int
        Passed to `table_to_knn_graph`
    metric : str
        Passed to `table_to_knn_graph`
    resolution : float
        Passed to `Louvain`
    state : TaskState

    Returns
    -------
    res : Results
    """
    state = state  # type: TaskState
    res = Results(
        normalize=normalize, pca_components=pca_components,
        k_neighbors=k_neighbors, metric=metric, resolution=resolution,
    )
    step = 0
    if state.is_interuption_requested():
        return res

    if pca_components is not None:
        steps = 3
        state.set_status("Computing PCA...")
        pca = PCA(n_components=pca_components, random_state=0)

        data = res.pca_projection = pca(data)(data)
        assert isinstance(data, Table)
        state.set_partial_results(("pca_projection", res.pca_projection))
        step += 1
    else:
        steps = 2

    if state.is_interuption_requested():
        return res

    state.set_progress_value(100. * step / steps)
    state.set_status("Building graph...")

    # Apply Louvain preprocessing before converting the table into a graph
    louvain = Louvain(resolution=resolution, random_state=0)
    data = louvain.preprocess(data)

    if state.is_interuption_requested():
        return res

    def pcallback(val):
        state.set_progress_value((100. * step + 100 * val) / steps)
        if state.is_interuption_requested():
            raise InteruptRequested()

    try:
        res.graph = graph = matrix_to_knn_graph(
            data.X, k_neighbors=k_neighbors, metric=metric,
            progress_callback=pcallback)
    except InteruptRequested:
        return res

    state.set_partial_results(("graph", res.graph))

    step += 1
    state.set_progress_value(100 * step / steps)
    state.set_status("Detecting communities...")
    if state.is_interuption_requested():
        return res

    res.partition = louvain(graph)
    state.set_partial_results(("partition", res.partition))
    return res
def run_on_data ( data , normalize , pca_components , k_neighbors , metric , resolution , state ) : # type: (Table, Optional[int], int, str, float, bool, TaskState) -> Results state = state # type: TaskState res = Results ( normalize = normalize , pca_components = pca_components , k_neighbors = k_neighbors , metric = metric , resolution = resolution , ) step = 0 if state . is_interuption_requested ( ) : return res if pca_components is not None : steps = 3 state . set_status ( "Computing PCA..." ) pca = PCA ( n_components = pca_components , random_state = 0 ) data = res . pca_projection = pca ( data ) ( data ) assert isinstance ( data , Table ) state . set_partial_results ( ( "pca_projection" , res . pca_projection ) ) step += 1 else : steps = 2 if state . is_interuption_requested ( ) : return res state . set_progress_value ( 100. * step / steps ) state . set_status ( "Building graph..." ) # Apply Louvain preprocessing before converting the table into a graph louvain = Louvain ( resolution = resolution , random_state = 0 ) data = louvain . preprocess ( data ) if state . is_interuption_requested ( ) : return res def pcallback ( val ) : state . set_progress_value ( ( 100. * step + 100 * val ) / steps ) if state . is_interuption_requested ( ) : raise InteruptRequested ( ) try : res . graph = graph = matrix_to_knn_graph ( data . X , k_neighbors = k_neighbors , metric = metric , progress_callback = pcallback ) except InteruptRequested : return res state . set_partial_results ( ( "graph" , res . graph ) ) step += 1 state . set_progress_value ( 100 * step / steps ) state . set_status ( "Detecting communities..." ) if state . is_interuption_requested ( ) : return res res . partition = louvain ( graph ) state . set_partial_results ( ( "partition" , res . partition ) ) return res