(
    head_embedding,
    tail_embedding,
    head,
    tail,
    n_epochs,
    n_vertices,
    epochs_per_sample,
    a,
    b,
    rng_state,
    gamma=1.0,
    initial_alpha=1.0,
    negative_sample_rate=5.0,
    parallel=False,
    verbose=False,
    densmap=False,
    densmap_kwds=None,
    tqdm_kwds=None,
    move_other=False,
)
return head_embedding
Improve an embedding using stochastic gradient descent to minimize the
    fuzzy set cross entropy between the 1-skeletons of the high dimensional
    and low dimensional fuzzy simplicial sets. In practice this is done by
    sampling edges based on their membership strength (with the (1-p) terms
    coming from negative sampling similar to word2vec).
    Parameters
    ----------
    head_embedding: array of shape (n_samples, n_components)
        The initial embedding to be improved by SGD.
    tail_embedding: array of shape (source_samples, n_components)
        The reference embedding of embedded points. If not embedding new
        previously unseen points with respect to an existing embedding this
        is simply the head_embedding (again); otherwise it provides the
        existing embedding to embed with respect to.
    head: array of shape (n_1_simplices)
        The indices of the heads of 1-simplices with non-zero membership.
    tail: array of shape (n_1_simplices)
        The indices of the tails of 1-simplices with non-zero membership.
    n_epochs: int
        The number of training epochs to use in optimization.
    n_vertices: int
        The number of vertices (0-simplices) in the dataset.
    epochs_per_sample: array of shape (n_1_simplices)
        A float value of the number of epochs per 1-simplex. 1-simplices with
        weaker membership strength will have more epochs between being sampled.
    a: float
        Parameter of differentiable approximation of right adjoint functor
    b: float
        Parameter of differentiable approximation of right adjoint functor
    rng_state: array of int64, shape (3,)
        The internal state of the rng
    gamma: float (optional, default 1.0)
        Weight to apply to negative samples.
    initial_alpha: float (optional, default 1.0)
        Initial learning rate for the SGD.
    negative_sample_rate: int (optional, default 5)
        Number of negative samples to use per positive sample.
    parallel: bool (optional, default False)
        Whether to run the computation using numba parallel.
        Running in parallel is non-deterministic, and is not used
        if a random seed has been set, to ensure reproducibility.
    verbose: bool (optional, default False)
        Whether to report information on the current progress of the algorithm.
    densmap: bool (optional, default False)
        Whether to use the density-augmented densMAP objective
    densmap_kwds: dict (optional, default None)
        Auxiliary data for densMAP
    tqdm_kwds: dict (optional, default None)
        Keyword arguments for tqdm progress bar.
    move_other: bool (optional, default False)
        Whether to adjust tail_embedding alongside head_embedding
    Returns
    -------
    embedding: array of shape (n_samples, n_components)
        The optimized embedding.
Improve an embedding using stochastic gradient descent to minimize the
    fuzzy set cross entropy between the 1-skeletons of the high dimensional
    and low dimensional fuzzy simplicial sets. In practice this is done by
    sampling edges based on their membership strength (with the (1-p) terms
    coming from negative sampling similar to word2vec).
    Parameters
    ----------
    head_embedding: array of shape (n_samples, n_components)
        The initial embedding to be improved by SGD.
    tail_embedding: array of shape (source_samples, n_components)
        The reference embedding of embedded points. If not embedding new
        previously unseen points with respect to an existing embedding this
        is simply the head_embedding (again); otherwise it provides the
        existing embedding to embed with respect to.
    head: array of shape (n_1_simplices)
        The indices of the heads of 1-simplices with non-zero membership.
    tail: array of shape (n_1_simplices)
        The indices of the tails of 1-simplices with non-zero membership.
    n_epochs: int
        The number of training epochs to use in optimization.
    n_vertices: int
        The number of vertices (0-simplices) in the dataset.
    epochs_per_sample: array of shape (n_1_simplices)
        A float value of the number of epochs per 1-simplex. 1-simplices with
        weaker membership strength will have more epochs between being sampled.
    a: float
        Parameter of differentiable approximation of right adjoint functor
    b: float
        Parameter of differentiable approximation of right adjoint functor
    rng_state: array of int64, shape (3,)
        The internal state of the rng
    gamma: float (optional, default 1.0)
        Weight to apply to negative samples.
    initial_alpha: float (optional, default 1.0)
        Initial learning rate for the SGD.
    negative_sample_rate: int (optional, default 5)
        Number of negative samples to use per positive sample.
    parallel: bool (optional, default False)
        Whether to run the computation using numba parallel.
        Running in parallel is non-deterministic, and is not used
        if a random seed has been set, to ensure reproducibility.
    verbose: bool (optional, default False)
        Whether to report information on the current progress of the algorithm.
    densmap: bool (optional, default False)
        Whether to use the density-augmented densMAP objective
    densmap_kwds: dict (optional, default None)
        Auxiliary data for densMAP
    tqdm_kwds: dict (optional, default None)
        Keyword arguments for tqdm progress bar.
    move_other: bool (optional, default False)
        Whether to adjust tail_embedding alongside head_embedding
    Returns
    -------
    embedding: array of shape (n_samples, n_components)
        The optimized embedding.
Improve an embedding using stochastic gradient descent to minimize the fuzzy set cross entropy between the 1 - skeletons of the high dimensional and low dimensional fuzzy simplicial sets . In practice this is done by sampling edges based on their membership strength ( with the ( 1 - p ) terms coming from negative sampling similar to word2vec ) . Parameters ---------- head_embedding : array of shape ( n_samples n_components ) The initial embedding to be improved by SGD . tail_embedding : array of shape ( source_samples n_components ) The reference embedding of embedded points . If not embedding new previously unseen points with respect to an existing embedding this is simply the head_embedding ( again ) ; otherwise it provides the existing embedding to embed with respect to . head : array of shape ( n_1_simplices ) The indices of the heads of 1 - simplices with non - zero membership . tail : array of shape ( n_1_simplices ) The indices of the tails of 1 - simplices with non - zero membership . n_epochs : int The number of training epochs to use in optimization . n_vertices : int The number of vertices ( 0 - simplices ) in the dataset . epochs_per_sample : array of shape ( n_1_simplices ) A float value of the number of epochs per 1 - simplex . 1 - simplices with weaker membership strength will have more epochs between being sampled . a : float Parameter of differentiable approximation of right adjoint functor b : float Parameter of differentiable approximation of right adjoint functor rng_state : array of int64 shape ( 3 ) The internal state of the rng gamma : float ( optional default 1 . 0 ) Weight to apply to negative samples . initial_alpha : float ( optional default 1 . 0 ) Initial learning rate for the SGD . negative_sample_rate : int ( optional default 5 ) Number of negative samples to use per positive sample . parallel : bool ( optional default False ) Whether to run the computation using numba parallel . Running in parallel is non - deterministic and is not used if a random seed has been set to ensure reproducibility . verbose : bool ( optional default False ) Whether to report information on the current progress of the algorithm . densmap : bool ( optional default False ) Whether to use the density - augmented densMAP objective densmap_kwds : dict ( optional default None ) Auxiliary data for densMAP tqdm_kwds : dict ( optional default None ) Keyword arguments for tqdm progress bar . move_other : bool ( optional default False ) Whether to adjust tail_embedding alongside head_embedding Returns ------- embedding : array of shape ( n_samples n_components ) The optimized embedding .
def optimize_layout_euclidean(
    head_embedding,
    tail_embedding,
    head,
    tail,
    n_epochs,
    n_vertices,
    epochs_per_sample,
    a,
    b,
    rng_state,
    gamma=1.0,
    initial_alpha=1.0,
    negative_sample_rate=5.0,
    parallel=False,
    verbose=False,
    densmap=False,
    densmap_kwds=None,
    tqdm_kwds=None,
    move_other=False,
):
    """Improve an embedding using stochastic gradient descent to minimize the
    fuzzy set cross entropy between the 1-skeletons of the high dimensional
    and low dimensional fuzzy simplicial sets. In practice this is done by
    sampling edges based on their membership strength (with the (1-p) terms
    coming from negative sampling similar to word2vec).
    Parameters
    ----------
    head_embedding: array of shape (n_samples, n_components)
        The initial embedding to be improved by SGD.
    tail_embedding: array of shape (source_samples, n_components)
        The reference embedding of embedded points. If not embedding new
        previously unseen points with respect to an existing embedding this
        is simply the head_embedding (again); otherwise it provides the
        existing embedding to embed with respect to.
    head: array of shape (n_1_simplices)
        The indices of the heads of 1-simplices with non-zero membership.
    tail: array of shape (n_1_simplices)
        The indices of the tails of 1-simplices with non-zero membership.
    n_epochs: int
        The number of training epochs to use in optimization.
    n_vertices: int
        The number of vertices (0-simplices) in the dataset.
    epochs_per_sample: array of shape (n_1_simplices)
        A float value of the number of epochs per 1-simplex. 1-simplices with
        weaker membership strength will have more epochs between being sampled.
    a: float
        Parameter of differentiable approximation of right adjoint functor
    b: float
        Parameter of differentiable approximation of right adjoint functor
    rng_state: array of int64, shape (3,)
        The internal state of the rng
    gamma: float (optional, default 1.0)
        Weight to apply to negative samples.
    initial_alpha: float (optional, default 1.0)
        Initial learning rate for the SGD.
    negative_sample_rate: int (optional, default 5)
        Number of negative samples to use per positive sample.
    parallel: bool (optional, default False)
        Whether to run the computation using numba parallel.
        Running in parallel is non-deterministic, and is not used
        if a random seed has been set, to ensure reproducibility.
    verbose: bool (optional, default False)
        Whether to report information on the current progress of the algorithm.
    densmap: bool (optional, default False)
        Whether to use the density-augmented densMAP objective
    densmap_kwds: dict (optional, default None)
        Auxiliary data for densMAP
    tqdm_kwds: dict (optional, default None)
        Keyword arguments for tqdm progress bar.
    move_other: bool (optional, default False)
        Whether to adjust tail_embedding alongside head_embedding
    Returns
    -------
    embedding: array of shape (n_samples, n_components)
        The optimized embedding.
    """

    dim = head_embedding.shape[1]
    alpha = initial_alpha

    epochs_per_negative_sample = epochs_per_sample / negative_sample_rate
    epoch_of_next_negative_sample = epochs_per_negative_sample.copy()
    epoch_of_next_sample = epochs_per_sample.copy()

    optimize_fn = numba.njit(
        _optimize_layout_euclidean_single_epoch, fastmath=True, parallel=parallel
    )
    if densmap_kwds is None:
        densmap_kwds = {}
    if tqdm_kwds is None:
        tqdm_kwds = {}

    if densmap:
        dens_init_fn = numba.njit(
            _optimize_layout_euclidean_densmap_epoch_init,
            fastmath=True,
            parallel=parallel,
        )

        dens_mu_tot = np.sum(densmap_kwds["mu_sum"]) / 2
        dens_lambda = densmap_kwds["lambda"]
        dens_R = densmap_kwds["R"]
        dens_mu = densmap_kwds["mu"]
        dens_phi_sum = np.zeros(n_vertices, dtype=np.float32)
        dens_re_sum = np.zeros(n_vertices, dtype=np.float32)
        dens_var_shift = densmap_kwds["var_shift"]
    else:
        dens_mu_tot = 0
        dens_lambda = 0
        dens_R = np.zeros(1, dtype=np.float32)
        dens_mu = np.zeros(1, dtype=np.float32)
        dens_phi_sum = np.zeros(1, dtype=np.float32)
        dens_re_sum = np.zeros(1, dtype=np.float32)

    if "disable" not in tqdm_kwds:
        tqdm_kwds["disable"] = not verbose

    for n in tqdm(range(n_epochs), **tqdm_kwds):

        densmap_flag = (
            densmap
            and (densmap_kwds["lambda"] > 0)
            and (((n + 1) / float(n_epochs)) > (1 - densmap_kwds["frac"]))
        )

        if densmap_flag:
            # FIXME: dens_init_fn might be referenced before assignment

            dens_init_fn(
                head_embedding,
                tail_embedding,
                head,
                tail,
                a,
                b,
                dens_re_sum,
                dens_phi_sum,
            )

            # FIXME: dens_var_shift might be referenced before assignment
            dens_re_std = np.sqrt(np.var(dens_re_sum) + dens_var_shift)
            dens_re_mean = np.mean(dens_re_sum)
            dens_re_cov = np.dot(dens_re_sum, dens_R) / (n_vertices - 1)
        else:
            dens_re_std = 0
            dens_re_mean = 0
            dens_re_cov = 0

        optimize_fn(
            head_embedding,
            tail_embedding,
            head,
            tail,
            n_vertices,
            epochs_per_sample,
            a,
            b,
            rng_state,
            gamma,
            dim,
            move_other,
            alpha,
            epochs_per_negative_sample,
            epoch_of_next_negative_sample,
            epoch_of_next_sample,
            n,
            densmap_flag,
            dens_phi_sum,
            dens_re_sum,
            dens_re_cov,
            dens_re_std,
            dens_re_mean,
            dens_lambda,
            dens_R,
            dens_mu,
            dens_mu_tot,
        )

        alpha = initial_alpha * (1.0 - (float(n) / float(n_epochs)))

    return head_embedding
def optimize_layout_euclidean ( head_embedding , tail_embedding , head , tail , n_epochs , n_vertices , epochs_per_sample , a , b , rng_state , gamma = 1.0 , initial_alpha = 1.0 , negative_sample_rate = 5.0 , parallel = False , verbose = False , densmap = False , densmap_kwds = None , tqdm_kwds = None , move_other = False , ) : dim = head_embedding . shape [ 1 ] alpha = initial_alpha epochs_per_negative_sample = epochs_per_sample / negative_sample_rate epoch_of_next_negative_sample = epochs_per_negative_sample . copy ( ) epoch_of_next_sample = epochs_per_sample . copy ( ) optimize_fn = numba . njit ( _optimize_layout_euclidean_single_epoch , fastmath = True , parallel = parallel ) if densmap_kwds is None : densmap_kwds = { } if tqdm_kwds is None : tqdm_kwds = { } if densmap : dens_init_fn = numba . njit ( _optimize_layout_euclidean_densmap_epoch_init , fastmath = True , parallel = parallel , ) dens_mu_tot = np . sum ( densmap_kwds [ "mu_sum" ] ) / 2 dens_lambda = densmap_kwds [ "lambda" ] dens_R = densmap_kwds [ "R" ] dens_mu = densmap_kwds [ "mu" ] dens_phi_sum = np . zeros ( n_vertices , dtype = np . float32 ) dens_re_sum = np . zeros ( n_vertices , dtype = np . float32 ) dens_var_shift = densmap_kwds [ "var_shift" ] else : dens_mu_tot = 0 dens_lambda = 0 dens_R = np . zeros ( 1 , dtype = np . float32 ) dens_mu = np . zeros ( 1 , dtype = np . float32 ) dens_phi_sum = np . zeros ( 1 , dtype = np . float32 ) dens_re_sum = np . zeros ( 1 , dtype = np . float32 ) if "disable" not in tqdm_kwds : tqdm_kwds [ "disable" ] = not verbose for n in tqdm ( range ( n_epochs ) , * * tqdm_kwds ) : densmap_flag = ( densmap and ( densmap_kwds [ "lambda" ] > 0 ) and ( ( ( n + 1 ) / float ( n_epochs ) ) > ( 1 - densmap_kwds [ "frac" ] ) ) ) if densmap_flag : # FIXME: dens_init_fn might be referenced before assignment dens_init_fn ( head_embedding , tail_embedding , head , tail , a , b , dens_re_sum , dens_phi_sum , ) # FIXME: dens_var_shift might be referenced before assignment dens_re_std = np . sqrt ( np . var ( dens_re_sum ) + dens_var_shift ) dens_re_mean = np . mean ( dens_re_sum ) dens_re_cov = np . dot ( dens_re_sum , dens_R ) / ( n_vertices - 1 ) else : dens_re_std = 0 dens_re_mean = 0 dens_re_cov = 0 optimize_fn ( head_embedding , tail_embedding , head , tail , n_vertices , epochs_per_sample , a , b , rng_state , gamma , dim , move_other , alpha , epochs_per_negative_sample , epoch_of_next_negative_sample , epoch_of_next_sample , n , densmap_flag , dens_phi_sum , dens_re_sum , dens_re_cov , dens_re_std , dens_re_mean , dens_lambda , dens_R , dens_mu , dens_mu_tot , ) alpha = initial_alpha * ( 1.0 - ( float ( n ) / float ( n_epochs ) ) ) return head_embedding