class_docstr: Implementation of the GraphSAGE algorithm of Hamilton et al. with Keras layers.
  see: http://snap.stanford.edu/graphsage/
  
  The model minimally requires specification of the layer sizes as a list of int
  corresponding to the feature dimensions for each hidden layer and a generator object.
  
  Different neighbour node aggregators can also be specified with the ``aggregator``
  argument, which should be the aggregator class,
  either :class:`.MeanAggregator`, :class:`.MeanPoolingAggregator`,
  :class:`.MaxPoolingAggregator`, or :class:`.AttentionalAggregator`.
  
  To use this class as a Keras model, the features and graph should be supplied using the
  :class:`.GraphSAGENodeGenerator` class for node inference models or the
  :class:`.GraphSAGELinkGenerator` class for link inference models.  The `.in_out_tensors` method should
  be used to create a Keras model from the `GraphSAGE` object.
  
  Examples:
      Creating a two-level GrapSAGE node classification model with hidden node sizes of 8 and 4
      and 10 neighbours sampled at each layer using an existing :class:`.StellarGraph` object `G`
      containing the graph and node features::
  
          generator = GraphSAGENodeGenerator(G, batch_size=50, num_samples=[10,10])
          gat = GraphSAGE(
                  layer_sizes=[8, 4],
                  activations=["relu","softmax"],
                  generator=generator,
              )
          x_inp, predictions = gat.in_out_tensors()
  
  Note that passing a `NodeSequence` or `LinkSequence` object from the `generator.flow(...)` method
  as the `generator=` argument is now deprecated and the base generator object should be passed instead.
  
  .. seealso::
  
     Examples using GraphSAGE:
  
     - node classification: `natively <https://stellargraph.readthedocs.io/en/stable/demos/node-classification/graphsage-node-classification.html>`__, `via Neo4j <https://stellargraph.readthedocs.io/en/stable/demos/connector/neo4j/undirected-graphsage-on-cora-neo4j-example.html>`__
     - `link prediction <https://stellargraph.readthedocs.io/en/stable/demos/link-prediction/graphsage-link-prediction.html>`__
     - unsupervised representation learning: `via random walks <https://stellargraph.readthedocs.io/en/stable/demos/embeddings/graphsage-unsupervised-sampler-embeddings.html>`__, `via Deep Graph Infomax <https://stellargraph.readthedocs.io/en/stable/demos/embeddings/deep-graph-infomax-embeddings.html>`__
     - calibrating models: `node classification <https://stellargraph.readthedocs.io/en/stable/demos/calibration/calibration-node-classification.html>`__, `link prediction <https://stellargraph.readthedocs.io/en/stable/demos/calibration/calibration-link-prediction.html>`__
     - ensemble models: `node classification <https://stellargraph.readthedocs.io/en/stable/demos/ensembles/ensemble-node-classification-example.html>`__, `link prediction <https://stellargraph.readthedocs.io/en/stable/demos/ensembles/ensemble-link-prediction-example.html>`__
     - `comparison of link prediction algorithms <https://stellargraph.readthedocs.io/en/stable/demos/link-prediction/homogeneous-comparison-link-prediction.html>`__
  
     Appropriate data generators: :class:`.GraphSAGENodeGenerator`, :class:`.Neo4jGraphSAGENodeGenerator`, :class:`.GraphSAGELinkGenerator`.
  
     Related models:
  
     - :class:`.DirectedGraphSAGE` for a generalisation to directed graphs
     - :class:`.HinSAGE` for a generalisation to heterogeneous graphs
     - :class:`.DeepGraphInfomax` for unsupervised training
  
     Aggregators: :class:`.MeanAggregator`, :class:`.MeanPoolingAggregator`, :class:`.MaxPoolingAggregator`, :class:`.AttentionalAggregator`.
  
  Args:
      layer_sizes (list): Hidden feature dimensions for each layer.
      generator (GraphSAGENodeGenerator or GraphSAGELinkGenerator):
          If specified `n_samples` and `input_dim` will be extracted from this object.
      aggregator (class): The GraphSAGE aggregator to use; defaults to the `MeanAggregator`.
      bias (bool): If True (default), a bias vector is learnt for each layer.
      dropout (float): The dropout supplied to each layer; defaults to no dropout.
      normalize (str or None): The normalization used after each layer; defaults to L2 normalization.
      activations (list): Activations applied to each layer's output;
          defaults to ``['relu', ..., 'relu', 'linear']``.
      kernel_initializer (str or func, optional): The initialiser to use for the weights of each layer.
      kernel_regularizer (str or func, optional): The regulariser to use for the weights of each layer.
      kernel_constraint (str or func, optional): The constraint to use for the weights of each layer.
      bias_initializer (str or func, optional): The initialiser to use for the bias of each layer.
      bias_regularizer (str or func, optional): The regulariser to use for the bias of each layer.
      bias_constraint (str or func, optional): The constraint to use for the bias of each layer.
      n_samples (list, optional): The number of samples per layer in the model.
      input_dim (int, optional): The dimensions of the node features used as input to the model.
      multiplicity (int, optional): The number of nodes to process at a time. This is 1 for a node inference
        and 2 for link inference (currently no others are supported).
  
  .. note::
      The values for ``n_samples``, ``input_dim``, and ``multiplicity`` are obtained from the provided
      ``generator`` by default. The additional keyword arguments for these parameters provide an
      alternative way to specify them if a generator cannot be supplied.
class_docstr_tok: ["Implementation","of","the","GraphSAGE","algorithm","of","Hamilton","et","al",".","with","Keras","layers",".","see",":","http",":","\/\/snap.stanford.edu\/graphsage\/","The","model","minimally","requires","specification","of","the","layer","sizes","as","a","list","of","int","corresponding","to","the","feature","dimensions","for","each","hidden","layer","and","a","generator","object",".","Different","neighbour","node","aggregators","can","also","be","specified","with","the","``","aggregator","``","argument",",","which","should","be","the","aggregator","class",",","either",":","class",":","`",".MeanAggregator","`",",",":","class",":","`",".MeanPoolingAggregator","`",",",":","class",":","`",".MaxPoolingAggregator","`",",","or",":","class",":","`",".AttentionalAggregator","`",".","To","use","this","class","as","a","Keras","model",",","the","features","and","graph","should","be","supplied","using","the",":","class",":","`",".GraphSAGENodeGenerator","`","class","for","node","inference","models","or","the",":","class",":","`",".GraphSAGELinkGenerator","`","class","for","link","inference","models",".","The","`",".in_out_tensors","`","method","should","be","used","to","create","a","Keras","model","from","the","`","GraphSAGE","`","object",".","Examples",":","Creating","a","two-level","GrapSAGE","node","classification","model","with","hidden","node","sizes","of","8","and","4","and","10","neighbours","sampled","at","each","layer","using","an","existing",":","class",":","`",".StellarGraph","`","object","`","G","`","containing","the","graph","and","node","features",":",":","generator","=","GraphSAGENodeGenerator","(","G",",","batch_size=50",",","num_samples=","[","10,10","]",")","gat","=","GraphSAGE","(","layer_sizes=","[","8",",","4","]",",","activations=","[","``","relu","''",",","''","softmax","''","]",",","generator=generator",",",")","x_inp",",","predictions","=","gat.in_out_tensors","(",")","Note","that","passing","a","`","NodeSequence","`","or","`","LinkSequence","`","object","from","the","`","generator.flow","(","...",")","`","method","as","the","`","generator=","`","argument","is","now","deprecated","and","the","base","generator","object","should","be","passed","instead",".","..","seealso",":",":","Examples","using","GraphSAGE",":","-","node","classification",":","`","natively","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/node-classification\/graphsage-node-classification.html",">","`","__",",","`","via","Neo4j","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/connector\/neo4j\/undirected-graphsage-on-cora-neo4j-example.html",">","`","__","-","`","link","prediction","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/link-prediction\/graphsage-link-prediction.html",">","`","__","-","unsupervised","representation","learning",":","`","via","random","walks","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/embeddings\/graphsage-unsupervised-sampler-embeddings.html",">","`","__",",","`","via","Deep","Graph","Infomax","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/embeddings\/deep-graph-infomax-embeddings.html",">","`","__","-","calibrating","models",":","`","node","classification","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/calibration\/calibration-node-classification.html",">","`","__",",","`","link","prediction","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/calibration\/calibration-link-prediction.html",">","`","__","-","ensemble","models",":","`","node","classification","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/ensembles\/ensemble-node-classification-example.html",">","`","__",",","`","link","prediction","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/ensembles\/ensemble-link-prediction-example.html",">","`","__","-","`","comparison","of","link","prediction","algorithms","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/link-prediction\/homogeneous-comparison-link-prediction.html",">","`","__","Appropriate","data","generators",":",":","class",":","`",".GraphSAGENodeGenerator","`",",",":","class",":","`",".Neo4jGraphSAGENodeGenerator","`",",",":","class",":","`",".GraphSAGELinkGenerator","`",".","Related","models",":","-",":","class",":","`",".DirectedGraphSAGE","`","for","a","generalisation","to","directed","graphs","-",":","class",":","`",".HinSAGE","`","for","a","generalisation","to","heterogeneous","graphs","-",":","class",":","`",".DeepGraphInfomax","`","for","unsupervised","training","Aggregators",":",":","class",":","`",".MeanAggregator","`",",",":","class",":","`",".MeanPoolingAggregator","`",",",":","class",":","`",".MaxPoolingAggregator","`",",",":","class",":","`",".AttentionalAggregator","`",".","Args",":","layer_sizes","(","list",")",":","Hidden","feature","dimensions","for","each","layer",".","generator","(","GraphSAGENodeGenerator","or","GraphSAGELinkGenerator",")",":","If","specified","`","n_samples","`","and","`","input_dim","`","will","be","extracted","from","this","object",".","aggregator","(","class",")",":","The","GraphSAGE","aggregator","to","use",";","defaults","to","the","`","MeanAggregator","`",".","bias","(","bool",")",":","If","True","(","default",")",",","a","bias","vector","is","learnt","for","each","layer",".","dropout","(","float",")",":","The","dropout","supplied","to","each","layer",";","defaults","to","no","dropout",".","normalize","(","str","or","None",")",":","The","normalization","used","after","each","layer",";","defaults","to","L2","normalization",".","activations","(","list",")",":","Activations","applied","to","each","layer","'s","output",";","defaults","to","``","[","'relu","'",",","...",",","'relu","'",",","'linear","'","]","``",".","kernel_initializer","(","str","or","func",",","optional",")",":","The","initialiser","to","use","for","the","weights","of","each","layer",".","kernel_regularizer","(","str","or","func",",","optional",")",":","The","regulariser","to","use","for","the","weights","of","each","layer",".","kernel_constraint","(","str","or","func",",","optional",")",":","The","constraint","to","use","for","the","weights","of","each","layer",".","bias_initializer","(","str","or","func",",","optional",")",":","The","initialiser","to","use","for","the","bias","of","each","layer",".","bias_regularizer","(","str","or","func",",","optional",")",":","The","regulariser","to","use","for","the","bias","of","each","layer",".","bias_constraint","(","str","or","func",",","optional",")",":","The","constraint","to","use","for","the","bias","of","each","layer",".","n_samples","(","list",",","optional",")",":","The","number","of","samples","per","layer","in","the","model",".","input_dim","(","int",",","optional",")",":","The","dimensions","of","the","node","features","used","as","input","to","the","model",".","multiplicity","(","int",",","optional",")",":","The","number","of","nodes","to","process","at","a","time",".","This","is","1","for","a","node","inference","and","2","for","link","inference","(","currently","no","others","are","supported",")",".","..","note",":",":","The","values","for","``","n_samples","``",",","``","input_dim","``",",","and","``","multiplicity","``","are","obtained","from","the","provided","``","generator","``","by","default",".","The","additional","keyword","arguments","for","these","parameters","provide","an","alternative","way","to","specify","them","if","a","generator","can","not","be","supplied","."]
docstr: Computes the total (cumulative product) number of nodes
  sampled at each neighbourhood.
  
  Each hop samples from the neighbours of the previous nodes.
docstr_tok: ["Computes","the","total","(","cumulative","product",")","number","of","nodes","sampled","at","each","neighbourhood",".","Each","hop","samples","from","the","neighbours","of","the","previous","nodes","."]
code: def _compute_neighbourhood_sizes(self):
      """
      Computes the total (cumulative product) number of nodes
      sampled at each neighbourhood.
  
      Each hop samples from the neighbours of the previous nodes.
      """
  
      def size_at(i):
          return np.product(self.n_samples[:i], dtype=int)
  
      self.neighbourhood_sizes = [
          size_at(i) for i in range(self.max_hops + 1)
      ]
  
imports: import warnings
  import numpy
  from tensorflow.keras.layers import Layer
  from tensorflow.keras import Input
  from tensorflow.keras import backend
  from tensorflow.keras.layers import Lambda, Dropout, Reshape, LeakyReLU
  from tensorflow.keras.utils import Sequence
  from tensorflow.keras import activations, initializers, constraints, regularizers
  from typing import List, Tuple, Callable, AnyStr, Union
  from ..mapper import GraphSAGENodeGenerator, GraphSAGELinkGenerator, DirectedGraphSAGENodeGenerator, DirectedGraphSAGELinkGenerator, NodeSequence, LinkSequence
  from .misc import deprecated_model_function
  from ..connector.neo4j.mapper import Neo4jGraphSAGENodeGenerator, Neo4jDirectedGraphSAGENodeGenerator
label_desc: Use image node_id 3 for calling the GraphSAGE obj's underlying member method code with example usage: obj._compute_neighbourhood_sizes() and returns: np