class_docstr: Class for generating training and test data for link prediction in graphs.
  
  The class requires as input a graph (in networkx format) and a percentage as a function of the total number of edges
  in the given graph of the number of positive and negative edges to sample. For heterogeneous graphs, the caller
  can also specify the type of edge and an edge property to split on. In the latter case, only a date property
  can be used and it must be in the format ``dd/mm/yyyy``. A date to be used as a threshold value such that only
  edges that have date after the threshold must be given. This effects only the sampling of positive edges.
  
  Negative edges are sampled at random by (for 'global' method) selecting two nodes in the graph and
  then checking if these edges are connected or not. If not, the pair of nodes is considered a negative sample.
  Otherwise, it is discarded and the process repeats. Alternatively, negative edges are sampled (for 'local' method)
  using DFS search at a distance from the source node (selected at random from all nodes in the graph)
  sampled according to a given set of probabilities.
  
  Positive edges can be sampled so that when they are subsequently removed from the graph, the reduced graph is either
  guaranteed, or not guaranteed, to remain connected. In the former case, graph connectivity is maintained by first
  calculating the minimum spanning tree. The edges that belong to the minimum spanning tree are protected from
  removal, and therefore cannot be sampled for the training set. The edges that do not belong to the minimum spanning
  tree are then sampled uniformly at random, until the required number of positive edges have been sampled for the
  training set. In the latter case, when connectedness of the reduced graph is not guaranteed, positive edges are
  sampled uniformly at random from all the edges in the graph, regardless of whether they belong to the spanning tree
  (which is not calculated in this case).
  
  Args:
      g (StellarGraph or networkx object): The graph to sample edges from.
      g_master (StellarGraph or networkx object): The graph representing the original dataset and a superset of the
          graph g. If it is not None, then when positive and negative edges are sampled, care is taken to make sure
          that a true positive edge is not sampled as a negative edge.
class_docstr_tok: ["Class","for","generating","training","and","test","data","for","link","prediction","in","graphs",".","The","class","requires","as","input","a","graph","(","in","networkx","format",")","and","a","percentage","as","a","function","of","the","total","number","of","edges","in","the","given","graph","of","the","number","of","positive","and","negative","edges","to","sample",".","For","heterogeneous","graphs",",","the","caller","can","also","specify","the","type","of","edge","and","an","edge","property","to","split","on",".","In","the","latter","case",",","only","a","date","property","can","be","used","and","it","must","be","in","the","format","``","dd\/mm\/yyyy","``",".","A","date","to","be","used","as","a","threshold","value","such","that","only","edges","that","have","date","after","the","threshold","must","be","given",".","This","effects","only","the","sampling","of","positive","edges",".","Negative","edges","are","sampled","at","random","by","(","for","'global","'","method",")","selecting","two","nodes","in","the","graph","and","then","checking","if","these","edges","are","connected","or","not",".","If","not",",","the","pair","of","nodes","is","considered","a","negative","sample",".","Otherwise",",","it","is","discarded","and","the","process","repeats",".","Alternatively",",","negative","edges","are","sampled","(","for","'local","'","method",")","using","DFS","search","at","a","distance","from","the","source","node","(","selected","at","random","from","all","nodes","in","the","graph",")","sampled","according","to","a","given","set","of","probabilities",".","Positive","edges","can","be","sampled","so","that","when","they","are","subsequently","removed","from","the","graph",",","the","reduced","graph","is","either","guaranteed",",","or","not","guaranteed",",","to","remain","connected",".","In","the","former","case",",","graph","connectivity","is","maintained","by","first","calculating","the","minimum","spanning","tree",".","The","edges","that","belong","to","the","minimum","spanning","tree","are","protected","from","removal",",","and","therefore","can","not","be","sampled","for","the","training","set",".","The","edges","that","do","not","belong","to","the","minimum","spanning","tree","are","then","sampled","uniformly","at","random",",","until","the","required","number","of","positive","edges","have","been","sampled","for","the","training","set",".","In","the","latter","case",",","when","connectedness","of","the","reduced","graph","is","not","guaranteed",",","positive","edges","are","sampled","uniformly","at","random","from","all","the","edges","in","the","graph",",","regardless","of","whether","they","belong","to","the","spanning","tree","(","which","is","not","calculated","in","this","case",")",".","Args",":","g","(","StellarGraph","or","networkx","object",")",":","The","graph","to","sample","edges","from",".","g_master","(","StellarGraph","or","networkx","object",")",":","The","graph","representing","the","original","dataset","and","a","superset","of","the","graph","g.","If","it","is","not","None",",","then","when","positive","and","negative","edges","are","sampled",",","care","is","taken","to","make","sure","that","a","true","positive","edge","is","not","sampled","as","a","negative","edge","."]
docstr: This method samples uniformly at random nodes from the graph and, if they don't have an edge in the graph,
  it records the pair as a negative edge.
  
  Args:
      p: (float) factor that multiplies the number of edges in the graph and determines the number of negative
      edges to be sampled.
      limit_samples: (int, optional) it limits the maximum number of samples to the given number, if not None
  
  Returns:
      (list) A list of 2-tuples that are pairs of node IDs that don't have an edge between them in the graph.
docstr_tok: ["This","method","samples","uniformly","at","random","nodes","from","the","graph","and",",","if","they","do","n't","have","an","edge","in","the","graph",",","it","records","the","pair","as","a","negative","edge",".","Args",":","p",":","(","float",")","factor","that","multiplies","the","number","of","edges","in","the","graph","and","determines","the","number","of","negative","edges","to","be","sampled",".","limit_samples",":","(","int",",","optional",")","it","limits","the","maximum","number","of","samples","to","the","given","number",",","if","not","None","Returns",":","(","list",")","A","list","of","2-tuples","that","are","pairs","of","node","IDs","that","do","n't","have","an","edge","between","them","in","the","graph","."]
code: def _sample_negative_examples_global(self, p=0.5, limit_samples=None):
      """
      This method samples uniformly at random nodes from the graph and, if they don't have an edge in the graph,
      it records the pair as a negative edge.
  
      Args:
          p: (float) factor that multiplies the number of edges in the graph and determines the number of negative
          edges to be sampled.
          limit_samples: (int, optional) it limits the maximum number of samples to the given number, if not None
  
      Returns:
          (list) A list of 2-tuples that are pairs of node IDs that don't have an edge between them in the graph.
      """
      self.negative_edge_node_distances = []
  
      num_edges_to_sample = int(self.g.number_of_edges() * p)
  
      if limit_samples is not None:
          if num_edges_to_sample > limit_samples:
              num_edges_to_sample = limit_samples
  
      if self.g_master is None:
          edges = list(self.g.edges())
      else:
          edges = list(self.g_master.edges())
  
      # to speed up lookup of edges in edges list, create a set the values stored are the concatenation of
      # the source and target node ids.
      edges_set = set(edges)
      edges_set.update({(u[1], u[0]) for u in edges})
      sampled_edges_set = set()
  
      start_nodes = list(self.g.nodes(data=False))
      end_nodes = list(self.g.nodes(data=False))
  
      count = 0
      sampled_edges = []
  
      num_iter = (
          int(np.ceil(num_edges_to_sample / (1.0 * len(start_nodes))))
          + 1
      )
      for _ in np.arange(0, num_iter):
          self._random.shuffle(start_nodes)
          self._random.shuffle(end_nodes)
          for u, v in zip(start_nodes, end_nodes):
              if (
                  (u != v)
                  and ((u, v) not in edges_set)
                  and ((u, v) not in sampled_edges_set)
              ):
                  sampled_edges.append(
                      (u, v, 0)
                  )  # the last entry is the class label
                  sampled_edges_set.update(
                      {(u, v), (v, u)}
                  )  # test for bi-directional edges
                  count += 1
              if count == num_edges_to_sample:
                  return sampled_edges
  
      if len(sampled_edges) != num_edges_to_sample:
          raise ValueError(
              "Unable to sample {} negative edges. Consider using smaller value for p.".format(
                  num_edges_to_sample
              )
          )
  
imports: import datetime
  import warnings
  import networkx
  import pandas
  import numpy
  from math import isclose
  from ..core import StellarGraph
  from ..globalvar import FEATURE_ATTR_NAME
label_desc: Use image node_id 12 for calling the EdgeSplitter obj's underlying member method code with example usage: obj._sample_negative_examples_global(p, limit_samples) and returns: sampled_edges