class_docstr: Class for learning embeddings of graphs on hyperbolic space.
  
  Parameters
  ----------
  dim : object
      Dimensions of the used hyperbolic space.
  max_epochs : int
      Maximum number of iterations for embedding.
  lr : int
      Learning rate for embedding.
  n_context : int
      Number of nodes to consider from a neighborhood
      of nodes around a particular node.
  n_negative : int
      Number of nodes to consider when searching for
      a set of nodes that are far from a particular node.
class_docstr_tok: ["Class","for","learning","embeddings","of","graphs","on","hyperbolic","space",".","Parameters","--","--","--","--","--","dim",":","object","Dimensions","of","the","used","hyperbolic","space",".","max_epochs",":","int","Maximum","number","of","iterations","for","embedding",".","lr",":","int","Learning","rate","for","embedding",".","n_context",":","int","Number","of","nodes","to","consider","from","a","neighborhood","of","nodes","around","a","particular","node",".","n_negative",":","int","Number","of","nodes","to","consider","when","searching","for","a","set","of","nodes","that","are","far","from","a","particular","node","."]
docstr: Compute embedding.
  
  Optimize a loss function to obtain a representable embedding.
  
  Parameters
  ----------
  graph : object
      An instance of the Graph class.
  
  Returns
  -------
  embeddings : array-like, shape=[n_samples, dim]
      Return the embedding of the data. Each data sample
      is represented as a point belonging to the manifold.
docstr_tok: ["Compute","embedding",".","Optimize","a","loss","function","to","obtain","a","representable","embedding",".","Parameters","--","--","--","--","--","graph",":","object","An","instance","of","the","Graph","class",".","Returns","--","--","--","-","embeddings",":","array-like",",","shape=","[","n_samples",",","dim","]","Return","the","embedding","of","the","data",".","Each","data","sample","is","represented","as","a","point","belonging","to","the","manifold","."]
code: def embed(self, graph):
      """Compute embedding.
  
      Optimize a loss function to obtain a representable embedding.
  
      Parameters
      ----------
      graph : object
          An instance of the Graph class.
  
      Returns
      -------
      embeddings : array-like, shape=[n_samples, dim]
          Return the embedding of the data. Each data sample
          is represented as a point belonging to the manifold.
      """
      nb_vertices_by_edges = [
          len(e_2) for _, e_2 in graph.edges.items()
      ]
      logging.info("Number of edges: %s", len(graph.edges))
      logging.info(
          "Mean vertices by edges: %s",
          (sum(nb_vertices_by_edges, 0) / len(graph.edges)),
      )
  
      negative_table_parameter = 5
      negative_sampling_table = []
  
      for i, nb_v in enumerate(nb_vertices_by_edges):
          negative_sampling_table += (
              [i]
              * int((nb_v ** (3.0 / 4.0)))
              * negative_table_parameter
          )
  
      negative_sampling_table = gs.array(negative_sampling_table)
      random_walks = graph.random_walk()
      embeddings = gs.random.normal(
          size=(graph.n_nodes, self.manifold.dim)
      )
      embeddings = embeddings * 0.2
  
      for epoch in range(self.max_epochs):
          total_loss = []
          for path in random_walks:
              for example_index, one_path in enumerate(path):
                  context_index = path[
                      max(0, example_index - self.n_context) : min(
                          example_index + self.n_context, len(path)
                      )
                  ]
                  negative_index = gs.random.randint(
                      negative_sampling_table.shape[0],
                      size=(len(context_index), self.n_negative),
                  )
  
                  negative_index = gs.expand_dims(
                      gs.flatten(negative_index), axis=-1
                  )
  
                  negative_index = gs.get_slice(
                      negative_sampling_table, negative_index
                  )
  
                  example_embedding = embeddings[
                      gs.cast(one_path, dtype=gs.int64)
                  ]
  
                  for one_context_i, one_negative_i in zip(
                      context_index, negative_index
                  ):
                      context_embedding = embeddings[one_context_i]
  
                      negative_embedding = gs.get_slice(
                          embeddings,
                          gs.squeeze(
                              gs.cast(one_negative_i, dtype=gs.int64)
                          ),
                      )
  
                      l, g_ex = self.loss(
                          example_embedding,
                          context_embedding,
                          negative_embedding,
                      )
                      total_loss.append(l)
  
                      example_to_update = embeddings[one_path]
  
                      valeur = self.manifold.metric.exp(
                          -self.lr * g_ex, example_to_update
                      )
  
                      embeddings = gs.assignment(
                          embeddings,
                          valeur,
                          gs.to_ndarray(one_path, to_ndim=1),
                          axis=1,
                      )
  
          logging.info(
              "iteration %d loss_value %f",
              epoch,
              sum(total_loss, 0) / len(total_loss),
          )
      return embeddings
  
file_path: geomstats/geomstats/datasets/prepare_graph_data.py
imports: import logging
  import random
  import geomstats.backend
  from geomstats.geometry.poincare_ball import PoincareBall
label_desc: Use image node_id 6 for calling the HyperbolicEmbedding obj's underlying member method code with example usage: obj.embed(graph) and returns: embeddings