(
    _raw_data, graph, n_components, random_state, metric, _metric_kwds, init="spectral"
)
return embedding
Initialize embedding using graph. This is for direct embeddings.

    Parameters
    ----------
    init : str, optional
        Type of initialization to use. Either random, or spectral, by default "spectral"

    Returns
    -------
    embedding : np.array
        the initialized embedding
Initialize embedding using graph. This is for direct embeddings.
Initialize embedding using graph . This is for direct embeddings .
def init_embedding_from_graph(
    _raw_data, graph, n_components, random_state, metric, _metric_kwds, init="spectral"
):
    """Initialize embedding using graph. This is for direct embeddings.

    Parameters
    ----------
    init : str, optional
        Type of initialization to use. Either random, or spectral, by default "spectral"

    Returns
    -------
    embedding : np.array
        the initialized embedding
    """
    if random_state is None:
        random_state = check_random_state(None)

    if isinstance(init, str) and init == "random":
        embedding = random_state.uniform(
            low=-10.0, high=10.0, size=(graph.shape[0], n_components)
        ).astype(np.float32)
    elif isinstance(init, str) and init == "spectral":
        # We add a little noise to avoid local minima for optimization to come

        initialisation = spectral_layout(
            _raw_data,
            graph,
            n_components,
            random_state,
            metric=metric,
            metric_kwds=_metric_kwds,
        )
        expansion = 10.0 / np.abs(initialisation).max()
        embedding = (initialisation * expansion).astype(
            np.float32
        ) + random_state.normal(
            scale=0.0001, size=[graph.shape[0], n_components]
        ).astype(
            np.float32
        )

    else:
        init_data = np.array(init)
        if len(init_data.shape) == 2:
            if np.unique(init_data, axis=0).shape[0] < init_data.shape[0]:
                tree = KDTree(init_data)
                dist, ind = tree.query(init_data, k=2)
                nndist = np.mean(dist[:, 1])
                embedding = init_data + random_state.normal(
                    scale=0.001 * nndist, size=init_data.shape
                ).astype(np.float32)
            else:
                embedding = init_data

    return embedding
def init_embedding_from_graph ( _raw_data , graph , n_components , random_state , metric , _metric_kwds , init = "spectral" ) : if random_state is None : random_state = check_random_state ( None ) if isinstance ( init , str ) and init == "random" : embedding = random_state . uniform ( low = - 10.0 , high = 10.0 , size = ( graph . shape [ 0 ] , n_components ) ) . astype ( np . float32 ) elif isinstance ( init , str ) and init == "spectral" : # We add a little noise to avoid local minima for optimization to come initialisation = spectral_layout ( _raw_data , graph , n_components , random_state , metric = metric , metric_kwds = _metric_kwds , ) expansion = 10.0 / np . abs ( initialisation ) . max ( ) embedding = ( initialisation * expansion ) . astype ( np . float32 ) + random_state . normal ( scale = 0.0001 , size = [ graph . shape [ 0 ] , n_components ] ) . astype ( np . float32 ) else : init_data = np . array ( init ) if len ( init_data . shape ) == 2 : if np . unique ( init_data , axis = 0 ) . shape [ 0 ] < init_data . shape [ 0 ] : tree = KDTree ( init_data ) dist , ind = tree . query ( init_data , k = 2 ) nndist = np . mean ( dist [ : , 1 ] ) embedding = init_data + random_state . normal ( scale = 0.001 * nndist , size = init_data . shape ) . astype ( np . float32 ) else : embedding = init_data return embedding