class_docstr: The UnsupervisedSampler is responsible for sampling walks in the given graph
  and returning positive and negative samples w.r.t. those walks, on demand.
  
  The positive samples are all the (target, context) pairs from the walks and the negative
  samples are contexts generated for each target based on a sampling distribution.
  
  By default, a UniformRandomWalk is used, but a custom `walker` can be specified instead. An
  error will be raised if other parameters are specified along with a custom `walker`.
  
  .. seealso::
  
     Examples using this sampler:
  
     - Attri2Vec: `node classification <https://stellargraph.readthedocs.io/en/stable/demos/node-classification/attri2vec-node-classification.html>`__ `link prediction <https://stellargraph.readthedocs.io/en/stable/demos/link-prediction/attri2vec-link-prediction.html>`__, `unsupervised representation learning <https://stellargraph.readthedocs.io/en/stable/demos/embeddings/attri2vec-embeddings.html>`__
     - GraphSAGE: `unsupervised representation learning <https://stellargraph.readthedocs.io/en/stable/demos/embeddings/graphsage-unsupervised-sampler-embeddings.html>`__
     - Node2Vec: `node classification <https://stellargraph.readthedocs.io/en/stable/demos/node-classification/keras-node2vec-node-classification.html>`__, `unsupervised representation learning <https://stellargraph.readthedocs.io/en/stable/demos/embeddings/keras-node2vec-embeddings.html>`__
     - `comparison of link prediction algorithms <https://stellargraph.readthedocs.io/en/stable/demos/link-prediction/homogeneous-comparison-link-prediction.html>`__
  
     Built-in classes for ``walker``: :class:`.UniformRandomWalk`, :class:`.BiasedRandomWalk`, :class:`.UniformRandomMetaPathWalk`.
  
  Args:
      G (StellarGraph): A stellargraph with features.
      nodes (iterable, optional) The root nodes from which individual walks start.
          If not provided, all nodes in the graph are used.
      length (int): Length of the walks for the default UniformRandomWalk walker. Length must
          be at least 2.
      number_of_walks (int): Number of walks from each root node for the default
          UniformRandomWalk walker.
      seed (int, optional): Random seed for the default UniformRandomWalk walker.
      walker (RandomWalk, optional): A RandomWalk object to use instead of the default
          UniformRandomWalk walker.
code: def __init__(
      self,
      G,
      nodes=None,
      length=2,
      number_of_walks=1,
      seed=None,
      walker=None,
  ):
      if not isinstance(G, StellarGraph):
          raise ValueError(
              "({}) Graph must be a StellarGraph or StellarDigraph object.".format(
                  type(self).__name__
              )
          )
      else:
          self.graph = G
  
      # Instantiate the walker class used to generate random walks in the graph
      if walker is not None:
          _warn_if_ignored(length, 2, "length")
          _warn_if_ignored(number_of_walks, 1, "number_of_walks")
          _warn_if_ignored(seed, None, "seed")
          self.walker = walker
      else:
          self.walker = UniformRandomWalk(
              G, n=number_of_walks, length=length, seed=seed
          )
  
      # Define the root nodes for the walks
      # if no root nodes are provided for sampling defaulting to using all nodes as root nodes.
      if nodes is None:
          self.nodes = list(G.nodes())
      elif is_real_iterable(
          nodes
      ):  # check whether the nodes provided are valid.
          self.nodes = list(nodes)
      else:
          raise ValueError(
              "nodes parameter should be an iterable of node IDs."
          )
  
      # Require walks of at lease length two because to create a sample pair we need at least two nodes.
      if length < 2:
          raise ValueError(
              "({}) For generating (target,context) samples, walk length has to be at least 2".format(
                  type(self).__name__
              )
          )
      else:
          self.length = length
  
      if number_of_walks < 1:
          raise ValueError(
              "({}) At least 1 walk from each head node has to be done".format(
                  type(self).__name__
              )
          )
      else:
          self.number_of_walks = number_of_walks
  
      # Setup an interal random state with the given seed
      _, self.np_random = random_state(seed)
  
file_path: stellargraph/stellargraph/data/unsupervised_sampler.py
imports: import numpy
  from stellargraph.core.utils import is_real_iterable
  from stellargraph.core.graph import StellarGraph
  from stellargraph.data.explorer import UniformRandomWalk
  from stellargraph.random import random_state
label_desc: Use image node_id 1 to create a new UnsupervisedSampler object  with example: obj = UnsupervisedSampler(G, nodes, length, number_of_walks, seed, walker)