class_docstr: A data generator for node prediction with Homogeneous GraphSAGE models
  
  At minimum, supply the Neo4jStellarGraph, the batch size, and the number of
  node samples for each layer of the GraphSAGE model.
  
  The supplied graph should be a Neo4jStellarGraph object with node features.
  
  Use the :meth:`flow` method supplying the nodes and (optionally) targets
  to get an object that can be used as a Keras data generator.
  
  Example::
  
      G_generator = GraphSAGENodeGenerator(G, 50, [10,10])
      train_data_gen = G_generator.flow(train_node_ids, train_node_labels)
      test_data_gen = G_generator.flow(test_node_ids)
  
  .. seealso::
  
     Model using this generator: :class:`.GraphSAGE`.
  
     Example using this generator: `node classification <https://stellargraph.readthedocs.io/en/stable/demos/connector/neo4j/undirected-graphsage-on-cora-neo4j-example.html>`__.
  
     Related functionality: :class:`.GraphSAGENodeGenerator` for using :class:`.GraphSAGE` without Neo4j.
  
  Args:
      graph (Neo4jStellarGraph): Neo4jStellarGraph object
      batch_size (int): Size of batch to return.
      num_samples (list): The number of samples per layer (hop) to take.
      name (int, optional): Optional name for the generator.
class_docstr_tok: ["A","data","generator","for","node","prediction","with","Homogeneous","GraphSAGE","models","At","minimum",",","supply","the","Neo4jStellarGraph",",","the","batch","size",",","and","the","number","of","node","samples","for","each","layer","of","the","GraphSAGE","model",".","The","supplied","graph","should","be","a","Neo4jStellarGraph","object","with","node","features",".","Use","the",":","meth",":","`","flow","`","method","supplying","the","nodes","and","(","optionally",")","targets","to","get","an","object","that","can","be","used","as","a","Keras","data","generator",".","Example",":",":","G_generator","=","GraphSAGENodeGenerator","(","G",",","50",",","[","10,10","]",")","train_data_gen","=","G_generator.flow","(","train_node_ids",",","train_node_labels",")","test_data_gen","=","G_generator.flow","(","test_node_ids",")","..","seealso",":",":","Model","using","this","generator",":",":","class",":","`",".GraphSAGE","`",".","Example","using","this","generator",":","`","node","classification","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/connector\/neo4j\/undirected-graphsage-on-cora-neo4j-example.html",">","`","__",".","Related","functionality",":",":","class",":","`",".GraphSAGENodeGenerator","`","for","using",":","class",":","`",".GraphSAGE","`","without","Neo4j",".","Args",":","graph","(","Neo4jStellarGraph",")",":","Neo4jStellarGraph","object","batch_size","(","int",")",":","Size","of","batch","to","return",".","num_samples","(","list",")",":","The","number","of","samples","per","layer","(","hop",")","to","take",".","name","(","int",",","optional",")",":","Optional","name","for","the","generator","."]
docstr: Collect the features of the nodes sampled from Neo4j,
  and return these as a list of feature arrays for the GraphSAGE
  algorithm.
  
  Args:
      head_nodes: An iterable of head nodes to perform sampling on.
      batch_num: Ignored, because this is not reproducible.
  
  Returns:
      A list of the same length as ``num_samples`` of collected features from
      the sampled nodes of shape:
      ``(len(head_nodes), num_sampled_at_layer, feature_size)``
      where ``num_sampled_at_layer`` is the cumulative product of ``num_samples``
      for that layer.
docstr_tok: ["Collect","the","features","of","the","nodes","sampled","from","Neo4j",",","and","return","these","as","a","list","of","feature","arrays","for","the","GraphSAGE","algorithm",".","Args",":","head_nodes",":","An","iterable","of","head","nodes","to","perform","sampling","on",".","batch_num",":","Ignored",",","because","this","is","not","reproducible",".","Returns",":","A","list","of","the","same","length","as","``","num_samples","``","of","collected","features","from","the","sampled","nodes","of","shape",":","``","(","len","(","head_nodes",")",",","num_sampled_at_layer",",","feature_size",")","``","where","``","num_sampled_at_layer","``","is","the","cumulative","product","of","``","num_samples","``","for","that","layer","."]
code: def sample_features(self, head_nodes, batch_num):
      """
      Collect the features of the nodes sampled from Neo4j,
      and return these as a list of feature arrays for the GraphSAGE
      algorithm.
  
      Args:
          head_nodes: An iterable of head nodes to perform sampling on.
          batch_num: Ignored, because this is not reproducible.
  
      Returns:
          A list of the same length as ``num_samples`` of collected features from
          the sampled nodes of shape:
          ``(len(head_nodes), num_sampled_at_layer, feature_size)``
          where ``num_sampled_at_layer`` is the cumulative product of ``num_samples``
          for that layer.
      """
      nodes_per_hop = self.sampler.run(
          nodes=head_nodes, n=1, n_size=self.num_samples
      )
  
      batch_nodes = np.concatenate(nodes_per_hop)
      batch_features = self.graph.node_features(batch_nodes)
  
      features = []
      idx = 0
      for nodes in nodes_per_hop:
          features_for_slot = batch_features[idx : idx + len(nodes)]
          resize = -1 if np.size(features_for_slot) > 0 else 0
          features.append(
              np.reshape(
                  features_for_slot,
                  (len(head_nodes), resize, features_for_slot.shape[1]),
              )
          )
          idx += len(nodes)
  
      return features
  
file_path: stellargraph/stellargraph/connector/neo4j/mapper.py
imports: import numpy
  import random
  from .sampler import Neo4jDirectedBreadthFirstNeighbors, Neo4jSampledBreadthFirstWalk
  from ...core.graph import GraphSchema
  from ...mapper import NodeSequence
  from ...mapper.sampled_node_generators import BatchedNodeGenerator
  from ...core.experimental import experimental
  from .graph import Neo4jStellarGraph
label_desc: Use image node_id 2 for calling the Neo4jGraphSAGENodeGenerator obj's underlying member method code with example usage: obj.sample_features(head_nodes, batch_num) and returns: features