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: Splitting edge data based on edge type or edge type and edge property. The edge property must be a date in the
  format ``dd/mm/yyyy``. If splitting by date, then a threshold value must also be given such that only edges with
  date larger than the threshold can be in the set of positive examples. The edge property does not effect the
  sampling of negative examples.
  
  Args:
      p (float): Percent of edges to be returned. It is calculated as a function of the total number of edges
       in the original graph. If the graph is heterogeneous, the percentage is calculated
       as a function of the total number of edges that satisfy the edge_label, edge_attribute_label and
       edge_attribute_threshold values given.
      method (str): Should be 'global' or 'local'. Specifies the method for selecting negative examples.
      edge_label (str): The edge type to split on
      probs (list of float, optional): If method=='local' then this vector of floats specifies the probabilities for
       sampling at each depth from the source node. The first value should be 0.0 and all values should sum to 1.0.
      keep_connected (bool): If True then when positive edges are removed care is taken that the reduced graph
       remains connected. If False, positive edges are removed without guaranteeing the connectivity of the reduced graph.
      edge_attribute_label (str): The label for the edge attribute to split on
      edge_attribute_threshold (str, optional): The threshold value applied to the edge attribute when sampling positive
       examples
  
  Returns:
      2 numpy arrays, the first N × 2 holding the node ids for the edges and the second N × 1 holding the edge
  labels, 0 for negative and 1 for positive example.
docstr_tok: ["Splitting","edge","data","based","on","edge","type","or","edge","type","and","edge","property",".","The","edge","property","must","be","a","date","in","the","format","``","dd\/mm\/yyyy","``",".","If","splitting","by","date",",","then","a","threshold","value","must","also","be","given","such","that","only","edges","with","date","larger","than","the","threshold","can","be","in","the","set","of","positive","examples",".","The","edge","property","does","not","effect","the","sampling","of","negative","examples",".","Args",":","p","(","float",")",":","Percent","of","edges","to","be","returned",".","It","is","calculated","as","a","function","of","the","total","number","of","edges","in","the","original","graph",".","If","the","graph","is","heterogeneous",",","the","percentage","is","calculated","as","a","function","of","the","total","number","of","edges","that","satisfy","the","edge_label",",","edge_attribute_label","and","edge_attribute_threshold","values","given",".","method","(","str",")",":","Should","be","'global","'","or","'local","'",".","Specifies","the","method","for","selecting","negative","examples",".","edge_label","(","str",")",":","The","edge","type","to","split","on","probs","(","list","of","float",",","optional",")",":","If","method=='local","'","then","this","vector","of","floats","specifies","the","probabilities","for","sampling","at","each","depth","from","the","source","node",".","The","first","value","should","be","0.0","and","all","values","should","sum","to","1.0.","keep_connected","(","bool",")",":","If","True","then","when","positive","edges","are","removed","care","is","taken","that","the","reduced","graph","remains","connected",".","If","False",",","positive","edges","are","removed","without","guaranteeing","the","connectivity","of","the","reduced","graph",".","edge_attribute_label","(","str",")",":","The","label","for","the","edge","attribute","to","split","on","edge_attribute_threshold","(","str",",","optional",")",":","The","threshold","value","applied","to","the","edge","attribute","when","sampling","positive","examples","Returns",":","2","numpy","arrays",",","the","first","N","\u00d7","2","holding","the","node","ids","for","the","edges","and","the","second","N","\u00d7","1","holding","the","edge","labels",",","0","for","negative","and","1","for","positive","example","."]
code: def _train_test_split_heterogeneous(
      self,
      p,
      method,
      edge_label,
      probs=None,
      keep_connected=False,
      edge_attribute_label=None,
      edge_attribute_threshold=None,
  ):
      """
      Splitting edge data based on edge type or edge type and edge property. The edge property must be a date in the
      format ``dd/mm/yyyy``. If splitting by date, then a threshold value must also be given such that only edges with
      date larger than the threshold can be in the set of positive examples. The edge property does not effect the
      sampling of negative examples.
  
      Args:
          p (float): Percent of edges to be returned. It is calculated as a function of the total number of edges
           in the original graph. If the graph is heterogeneous, the percentage is calculated
           as a function of the total number of edges that satisfy the edge_label, edge_attribute_label and
           edge_attribute_threshold values given.
          method (str): Should be 'global' or 'local'. Specifies the method for selecting negative examples.
          edge_label (str): The edge type to split on
          probs (list of float, optional): If method=='local' then this vector of floats specifies the probabilities for
           sampling at each depth from the source node. The first value should be 0.0 and all values should sum to 1.0.
          keep_connected (bool): If True then when positive edges are removed care is taken that the reduced graph
           remains connected. If False, positive edges are removed without guaranteeing the connectivity of the reduced graph.
          edge_attribute_label (str): The label for the edge attribute to split on
          edge_attribute_threshold (str, optional): The threshold value applied to the edge attribute when sampling positive
           examples
  
      Returns:
          2 numpy arrays, the first N × 2 holding the node ids for the edges and the second N × 1 holding the edge
      labels, 0 for negative and 1 for positive example.
      """
      # minedges are those edges that if removed we might end up with a disconnected graph after the positive edges
      # have been sampled.
      if keep_connected:
          self.minedges = self._get_minimum_spanning_edges()
      else:
          self.minedges = []
          self.minedges_set = set()
  
      # Note: The caller guarantees the edge_label is not None so we don't have to check here again.
      if edge_attribute_threshold is None:
          positive_edges = self._reduce_graph_by_edge_type(
              minedges=self.minedges_set, p=p, edge_label=edge_label
          )
      else:
          positive_edges = (
              self._reduce_graph_by_edge_type_and_attribute(
                  minedges=self.minedges_set,
                  p=p,
                  edge_label=edge_label,
                  edge_attribute_label=edge_attribute_label,
                  edge_attribute_threshold=edge_attribute_threshold,
              )
          )
  
      if len(positive_edges) == 0:
          raise Exception(
              "ERROR: Unable to sample any positive edges of type '{}'".format(
                  edge_label
              )
          )
  
      df = pd.DataFrame(positive_edges)
      self.positive_edges_ids = np.array(df.iloc[:, 0:2])
      self.positive_edges_labels = np.array(df.iloc[:, 2])
  
      if method == "global":
          negative_edges = (
              self._sample_negative_examples_by_edge_type_global(
                  p=p,
                  edges=positive_edges,
                  edge_label=edge_label,
                  limit_samples=len(positive_edges),
              )
          )
      else:  # method == 'local'
          if probs is None:
              probs = [0.0, 0.25, 0.50, 0.25]
              warnings.warn(
                  "Using default sampling probabilities (distance from source node): {}".format(
                      probs
                  ),
                  RuntimeWarning,
                  stacklevel=2,
              )
          negative_edges = (
              self._sample_negative_examples_by_edge_type_local_dfs(
                  p=p,
                  probs=probs,
                  edges_positive=positive_edges,
                  edge_label=edge_label,
                  limit_samples=len(positive_edges),
              )
          )
  
      df = pd.DataFrame(negative_edges)
      self.negative_edges_ids = np.array(df.iloc[:, 0:2])
      self.negative_edges_labels = np.array(df.iloc[:, 2])
  
      if len(self.positive_edges_ids) == 0:
          raise Exception("Could not sample any positive edges")
      if len(self.negative_edges_ids) == 0:
          raise Exception("Could not sample any negative edges")
  
      edge_data_ids = np.vstack(
          (self.positive_edges_ids, self.negative_edges_ids)
      )
      edge_data_labels = np.hstack(
          (self.positive_edges_labels, self.negative_edges_labels)
      )
      print(
          "** Sampled {} positive and {} negative edges. **".format(
              len(self.positive_edges_ids), len(self.negative_edges_ids)
          )
      )
  
      return edge_data_ids, edge_data_labels
  
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 3 for calling the EdgeSplitter obj's underlying member method code with example usage: obj._train_test_split_heterogeneous(p, method, edge_label, probs, keep_connected, edge_attribute_label, edge_attribute_threshold) and returns: edge_data_ids,  edge_data_labels