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: Generates positive and negative edges and a graph that has the same nodes as the original but the positive
  edges removed. It can be used to generate data from homogeneous and heterogeneous graphs.
  
  For heterogeneous graphs, positive and negative examples can be generated based on specified edge type or
  edge type and edge property given a threshold value for the latter.
  
  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): How negative edges are sampled. If 'global', then nodes are selected at random.
       If 'local' then the first nodes is sampled from all nodes in the graph, but the second node is
       chosen to be from the former's local neighbourhood.
      probs (list): list The probabilities for sampling a node that is k-hops from the source node,
       e.g., [0.25, 0.75] means that there is a 0.25 probability that the target node will be 1-hope away from the
       source node and 0.75 that it will be 2 hops away from the source node. This only affects sampling of
       negative edges if method is set to 'local'.
      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_label (str, optional) If splitting based on edge type, then this parameter specifies the key for the type
       of edges to split on.
      edge_attribute_label (str, optional): 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.
      attribute_is_datetime (bool, optional): Specifies if edge attribute is datetime or not.
      seed (int, optional): seed for random number generator, positive int or 0
  
  Returns:
      The reduced graph (positive edges removed) and the edge data as 2 numpy arrays, the first array of
      dimensionality N × 2 (where N is the number of edges) holding the node ids for the edges and the second of
      dimensionality N × 1 holding the edge labels, 0 for negative and 1 for positive examples. The graph
      matches the input graph passed to the :class:`.EdgeSplitter` constructor: the returned graph is a
      :class:`.StellarGraph` instance if the input graph was one, and, similarly, a NetworkX graph if the input
      graph was one.
docstr_tok: ["Generates","positive","and","negative","edges","and","a","graph","that","has","the","same","nodes","as","the","original","but","the","positive","edges","removed",".","It","can","be","used","to","generate","data","from","homogeneous","and","heterogeneous","graphs",".","For","heterogeneous","graphs",",","positive","and","negative","examples","can","be","generated","based","on","specified","edge","type","or","edge","type","and","edge","property","given","a","threshold","value","for","the","latter",".","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",")",":","How","negative","edges","are","sampled",".","If","'global","'",",","then","nodes","are","selected","at","random",".","If","'local","'","then","the","first","nodes","is","sampled","from","all","nodes","in","the","graph",",","but","the","second","node","is","chosen","to","be","from","the","former","'s","local","neighbourhood",".","probs","(","list",")",":","list","The","probabilities","for","sampling","a","node","that","is","k-hops","from","the","source","node",",","e.g.",",","[","0.25",",","0.75","]","means","that","there","is","a","0.25","probability","that","the","target","node","will","be","1-hope","away","from","the","source","node","and","0.75","that","it","will","be","2","hops","away","from","the","source","node",".","This","only","affects","sampling","of","negative","edges","if","method","is","set","to","'local","'",".","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_label","(","str",",","optional",")","If","splitting","based","on","edge","type",",","then","this","parameter","specifies","the","key","for","the","type","of","edges","to","split","on",".","edge_attribute_label","(","str",",","optional",")",":","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",".","attribute_is_datetime","(","bool",",","optional",")",":","Specifies","if","edge","attribute","is","datetime","or","not",".","seed","(","int",",","optional",")",":","seed","for","random","number","generator",",","positive","int","or","0","Returns",":","The","reduced","graph","(","positive","edges","removed",")","and","the","edge","data","as","2","numpy","arrays",",","the","first","array","of","dimensionality","N","\u00d7","2","(","where","N","is","the","number","of","edges",")","holding","the","node","ids","for","the","edges","and","the","second","of","dimensionality","N","\u00d7","1","holding","the","edge","labels",",","0","for","negative","and","1","for","positive","examples",".","The","graph","matches","the","input","graph","passed","to","the",":","class",":","`",".EdgeSplitter","`","constructor",":","the","returned","graph","is","a",":","class",":","`",".StellarGraph","`","instance","if","the","input","graph","was","one",",","and",",","similarly",",","a","NetworkX","graph","if","the","input","graph","was","one","."]
code: def train_test_split(
      self,
      p=0.5,
      method="global",
      probs=None,
      keep_connected=False,
      edge_label=None,
      edge_attribute_label=None,
      edge_attribute_threshold=None,
      attribute_is_datetime=None,
      seed=None,
  ):
      """
      Generates positive and negative edges and a graph that has the same nodes as the original but the positive
      edges removed. It can be used to generate data from homogeneous and heterogeneous graphs.
  
      For heterogeneous graphs, positive and negative examples can be generated based on specified edge type or
      edge type and edge property given a threshold value for the latter.
  
      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): How negative edges are sampled. If 'global', then nodes are selected at random.
           If 'local' then the first nodes is sampled from all nodes in the graph, but the second node is
           chosen to be from the former's local neighbourhood.
          probs (list): list The probabilities for sampling a node that is k-hops from the source node,
           e.g., [0.25, 0.75] means that there is a 0.25 probability that the target node will be 1-hope away from the
           source node and 0.75 that it will be 2 hops away from the source node. This only affects sampling of
           negative edges if method is set to 'local'.
          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_label (str, optional) If splitting based on edge type, then this parameter specifies the key for the type
           of edges to split on.
          edge_attribute_label (str, optional): 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.
          attribute_is_datetime (bool, optional): Specifies if edge attribute is datetime or not.
          seed (int, optional): seed for random number generator, positive int or 0
  
      Returns:
          The reduced graph (positive edges removed) and the edge data as 2 numpy arrays, the first array of
          dimensionality N × 2 (where N is the number of edges) holding the node ids for the edges and the second of
          dimensionality N × 1 holding the edge labels, 0 for negative and 1 for positive examples. The graph
          matches the input graph passed to the :class:`.EdgeSplitter` constructor: the returned graph is a
          :class:`.StellarGraph` instance if the input graph was one, and, similarly, a NetworkX graph if the input
          graph was one.
      """
      if p <= 0 or p >= 1:
          raise ValueError(
              "The value of p must be in the interval (0,1)"
          )
  
      if method != "global" and method != "local":
          raise ValueError(
              "Invalid method {}; valid options are 'local' or 'global'".format(
                  method
              )
          )
  
      if not isinstance(keep_connected, (bool,)):
          raise ValueError(
              "({}) The flag keep_connected be boolean type.".format(
                  type(self).__name__
              )
          )
  
      if seed is not None:
          if seed < 0:
              raise ValueError(
                  "({}) The random number generator seed value, seed, should be positive integer or None.".format(
                      type(self).__name__
                  )
              )
          if type(seed) != int:
              raise ValueError(
                  "({}) The random number generator seed value, seed, should be integer type or None.".format(
                      type(self).__name__
                  )
              )
      if self._random is None:  # only do this one
          self._random = np.random.RandomState(seed=seed)
  
      if edge_label is not None:  # working with a heterogeneous graph
          if (
              edge_attribute_label
              and edge_attribute_threshold
              and not attribute_is_datetime
          ):
              raise ValueError(
                  "You can only split by datetime edge attribute"
              )
          else:  # all three are True
              (
                  edge_data_ids,
                  edge_data_labels,
              ) = self._train_test_split_heterogeneous(
                  p=p,
                  method=method,
                  edge_label=edge_label,
                  edge_attribute_label=edge_attribute_label,
                  edge_attribute_threshold=edge_attribute_threshold,
                  keep_connected=keep_connected,
              )
      else:  # working with a homogeneous graph
          (
              edge_data_ids,
              edge_data_labels,
          ) = self._train_test_split_homogeneous(
              p=p,
              method=method,
              probs=probs,
              keep_connected=keep_connected,
          )
  
      if self._input_was_stellargraph:
          # if the graphs came in as a StellarGraph, return one too
          result_graph = StellarGraph.from_networkx(
              self.g_train, node_features=FEATURE_ATTR_NAME
          )
      else:
          result_graph = self.g_train
  
      return result_graph, 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 4 for calling the EdgeSplitter obj's underlying member method code with example usage: obj.train_test_split(p, method, probs, keep_connected, edge_label, edge_attribute_label, edge_attribute_threshold, attribute_is_datetime, seed) and returns: result_graph,  edge_data_ids,  edge_data_labels