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 loss and grad.
  
  Compute loss and grad given embedding of the current example,
  embedding of the context and negative sampling embedding.
  
  Parameters
  ----------
  example_embedding : array-like, shape=[dim]
      Current data sample embedding.
  context_embedding : array-like, shape=[dim]
      Current context embedding.
  negative_embedding: array-like, shape=[dim]
      Current negative sample embedding.
  
  Returns
  -------
  total_loss : int
      The current value of the loss function.
  example_grad : array-like, shape=[dim]
      The gradient of the loss function at the embedding
      of the current data sample.
docstr_tok: ["Compute","loss","and","grad",".","Compute","loss","and","grad","given","embedding","of","the","current","example",",","embedding","of","the","context","and","negative","sampling","embedding",".","Parameters","--","--","--","--","--","example_embedding",":","array-like",",","shape=","[","dim","]","Current","data","sample","embedding",".","context_embedding",":","array-like",",","shape=","[","dim","]","Current","context","embedding",".","negative_embedding",":","array-like",",","shape=","[","dim","]","Current","negative","sample","embedding",".","Returns","--","--","--","-","total_loss",":","int","The","current","value","of","the","loss","function",".","example_grad",":","array-like",",","shape=","[","dim","]","The","gradient","of","the","loss","function","at","the","embedding","of","the","current","data","sample","."]
code: def loss(
      self, example_embedding, context_embedding, negative_embedding
  ):
      """Compute loss and grad.
  
      Compute loss and grad given embedding of the current example,
      embedding of the context and negative sampling embedding.
  
      Parameters
      ----------
      example_embedding : array-like, shape=[dim]
          Current data sample embedding.
      context_embedding : array-like, shape=[dim]
          Current context embedding.
      negative_embedding: array-like, shape=[dim]
          Current negative sample embedding.
  
      Returns
      -------
      total_loss : int
          The current value of the loss function.
      example_grad : array-like, shape=[dim]
          The gradient of the loss function at the embedding
          of the current data sample.
      """
      n_edges, dim = (
          negative_embedding.shape[0],
          example_embedding.shape[-1],
      )
      example_embedding = gs.expand_dims(example_embedding, 0)
      context_embedding = gs.expand_dims(context_embedding, 0)
  
      positive_distance = self.manifold.metric.squared_dist(
          example_embedding, context_embedding
      )
      positive_loss = self.log_sigmoid(-positive_distance)
  
      reshaped_example_embedding = gs.repeat(
          example_embedding, n_edges, axis=0
      )
  
      negative_distance = self.manifold.metric.squared_dist(
          reshaped_example_embedding, negative_embedding
      )
      negative_loss = self.log_sigmoid(negative_distance)
  
      total_loss = -(positive_loss + gs.sum(negative_loss))
  
      positive_log_sigmoid_grad = -self.grad_log_sigmoid(
          -positive_distance
      )
  
      positive_distance_grad = self.grad_squared_distance(
          example_embedding, context_embedding
      )
  
      positive_grad = (
          gs.repeat(positive_log_sigmoid_grad, dim, axis=-1)
          * positive_distance_grad
      )
  
      negative_distance_grad = self.grad_squared_distance(
          reshaped_example_embedding, negative_embedding
      )
  
      negative_distance = gs.to_ndarray(
          negative_distance, to_ndim=2, axis=-1
      )
      negative_log_sigmoid_grad = self.grad_log_sigmoid(
          negative_distance
      )
  
      negative_grad = negative_log_sigmoid_grad * negative_distance_grad
  
      example_grad = -(positive_grad + gs.sum(negative_grad, axis=0))
  
      return total_loss, example_grad
  
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 5 for calling the HyperbolicEmbedding obj's underlying member method code with example usage: obj.loss(example_embedding, context_embedding, negative_embedding) and returns: total_loss,  example_grad