class_docstr: Performs biased second order random walks (like those used in Node2Vec algorithm
  https://snap.stanford.edu/node2vec/) controlled by the values of two parameters p and q.
  
  .. seealso::
  
     Examples using this random walk:
  
     - unsupervised representation learning: `Node2Vec using Gensim Word2Vec <https://stellargraph.readthedocs.io/en/stable/demos/embeddings/node2vec-embeddings.html>`__, `Node2Vec using StellarGraph <https://stellargraph.readthedocs.io/en/stable/demos/embeddings/keras-node2vec-embeddings.html>`__
     - node classification: `Node2Vec using Gensim Word2Vec <https://stellargraph.readthedocs.io/en/stable/demos/node-classification/node2vec-node-classification.html>`__, `Node2Vec using StellarGraph <https://stellargraph.readthedocs.io/en/stable/demos/node-classification/keras-node2vec-node-classification.html>`__, `Node2Vec with edge weights <https://stellargraph.readthedocs.io/en/stable/demos/node-classification/node2vec-weighted-node-classification.html>`__
     - link prediction: `Node2Vec <https://stellargraph.readthedocs.io/en/stable/demos/link-prediction/node2vec-link-prediction.html>`__, `comparison to CTDNE (TemporalRandomWalk) <https://stellargraph.readthedocs.io/en/stable/demos/link-prediction/ctdne-link-prediction.html>`__, `comparison of algorithms <https://stellargraph.readthedocs.io/en/stable/demos/link-prediction/homogeneous-comparison-link-prediction.html>`__
  
     Related functionality:
  
     - :class:`.UnsupervisedSampler` for transforming random walks into links for unsupervised training of link prediction models
     - :class:`.Node2Vec`, :class:`.Node2VecNodeGenerator` and :class:`.Node2VecLinkGenerator` for training a Node2Vec using only StellarGraph
     - Other random walks: :class:`.UniformRandomWalk`, :class:`.UniformRandomMetaPathWalk`, :class:`.TemporalRandomWalk`.
  
  Args:
      graph (StellarGraph): Graph to traverse
      n (int, optional): Total number of random walks per root node
      length (int, optional): Maximum length of each random walk
      p (float, optional): Defines probability, 1/p, of returning to source node
      q (float, optional): Defines probability, 1/q, for moving to a node away from the source node
      weighted (bool, optional): Indicates whether the walk is unweighted or weighted
      seed (int, optional): Random number generator seed
class_docstr_tok: ["Performs","biased","second","order","random","walks","(","like","those","used","in","Node2Vec","algorithm","https",":","\/\/snap.stanford.edu\/node2vec\/",")","controlled","by","the","values","of","two","parameters","p","and","q",".","..","seealso",":",":","Examples","using","this","random","walk",":","-","unsupervised","representation","learning",":","`","Node2Vec","using","Gensim","Word2Vec","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/embeddings\/node2vec-embeddings.html",">","`","__",",","`","Node2Vec","using","StellarGraph","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/embeddings\/keras-node2vec-embeddings.html",">","`","__","-","node","classification",":","`","Node2Vec","using","Gensim","Word2Vec","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/node-classification\/node2vec-node-classification.html",">","`","__",",","`","Node2Vec","using","StellarGraph","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/node-classification\/keras-node2vec-node-classification.html",">","`","__",",","`","Node2Vec","with","edge","weights","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/node-classification\/node2vec-weighted-node-classification.html",">","`","__","-","link","prediction",":","`","Node2Vec","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/link-prediction\/node2vec-link-prediction.html",">","`","__",",","`","comparison","to","CTDNE","(","TemporalRandomWalk",")","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/link-prediction\/ctdne-link-prediction.html",">","`","__",",","`","comparison","of","algorithms","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/link-prediction\/homogeneous-comparison-link-prediction.html",">","`","__","Related","functionality",":","-",":","class",":","`",".UnsupervisedSampler","`","for","transforming","random","walks","into","links","for","unsupervised","training","of","link","prediction","models","-",":","class",":","`",".Node2Vec","`",",",":","class",":","`",".Node2VecNodeGenerator","`","and",":","class",":","`",".Node2VecLinkGenerator","`","for","training","a","Node2Vec","using","only","StellarGraph","-","Other","random","walks",":",":","class",":","`",".UniformRandomWalk","`",",",":","class",":","`",".UniformRandomMetaPathWalk","`",",",":","class",":","`",".TemporalRandomWalk","`",".","Args",":","graph","(","StellarGraph",")",":","Graph","to","traverse","n","(","int",",","optional",")",":","Total","number","of","random","walks","per","root","node","length","(","int",",","optional",")",":","Maximum","length","of","each","random","walk","p","(","float",",","optional",")",":","Defines","probability",",","1\/p",",","of","returning","to","source","node","q","(","float",",","optional",")",":","Defines","probability",",","1\/q",",","for","moving","to","a","node","away","from","the","source","node","weighted","(","bool",",","optional",")",":","Indicates","whether","the","walk","is","unweighted","or","weighted","seed","(","int",",","optional",")",":","Random","number","generator","seed"]
docstr: Perform a random walk starting from the root nodes. Optional parameters default to using the
  values passed in during construction.
  
  Args:
      nodes (list): The root nodes as a list of node IDs
      n (int, optional): Total number of random walks per root node
      length (int, optional): Maximum length of each random walk
      p (float, optional): Defines probability, 1/p, of returning to source node
      q (float, optional): Defines probability, 1/q, for moving to a node away from the source node
      seed (int, optional): Random number generator seed; default is None
      weighted (bool, optional): Indicates whether the walk is unweighted or weighted
  
  Returns:
      List of lists of nodes ids for each of the random walks
docstr_tok: ["Perform","a","random","walk","starting","from","the","root","nodes",".","Optional","parameters","default","to","using","the","values","passed","in","during","construction",".","Args",":","nodes","(","list",")",":","The","root","nodes","as","a","list","of","node","IDs","n","(","int",",","optional",")",":","Total","number","of","random","walks","per","root","node","length","(","int",",","optional",")",":","Maximum","length","of","each","random","walk","p","(","float",",","optional",")",":","Defines","probability",",","1\/p",",","of","returning","to","source","node","q","(","float",",","optional",")",":","Defines","probability",",","1\/q",",","for","moving","to","a","node","away","from","the","source","node","seed","(","int",",","optional",")",":","Random","number","generator","seed",";","default","is","None","weighted","(","bool",",","optional",")",":","Indicates","whether","the","walk","is","unweighted","or","weighted","Returns",":","List","of","lists","of","nodes","ids","for","each","of","the","random","walks"]
code: def run(
      self,
      nodes,
      *,
      n=None,
      length=None,
      p=None,
      q=None,
      seed=None,
      weighted=None,
  ):
      """
      Perform a random walk starting from the root nodes. Optional parameters default to using the
      values passed in during construction.
  
      Args:
          nodes (list): The root nodes as a list of node IDs
          n (int, optional): Total number of random walks per root node
          length (int, optional): Maximum length of each random walk
          p (float, optional): Defines probability, 1/p, of returning to source node
          q (float, optional): Defines probability, 1/q, for moving to a node away from the source node
          seed (int, optional): Random number generator seed; default is None
          weighted (bool, optional): Indicates whether the walk is unweighted or weighted
  
      Returns:
          List of lists of nodes ids for each of the random walks
  
      """
      n = _default_if_none(n, self.n, "n")
      length = _default_if_none(length, self.length, "length")
      p = _default_if_none(p, self.p, "p")
      q = _default_if_none(q, self.q, "q")
      weighted = _default_if_none(weighted, self.weighted, "weighted")
      self._validate_walk_params(nodes, n, length)
      self._check_weights(p, q, weighted)
      rs, _ = self._get_random_state(seed)
  
      nodes = self.graph.node_ids_to_ilocs(nodes)
  
      if weighted:
          self._check_weights_valid()
  
      weight_dtype = self.graph._edges.weights.dtype
      cast_func = np.cast[weight_dtype]
      ip = cast_func(1.0 / p)
      iq = cast_func(1.0 / q)
  
      if np.isinf(ip):
          raise ValueError(
              f"p: value ({p}) is too small. It must be possible to represent 1/p in {weight_dtype}, but this value overflows to infinity."
          )
      if np.isinf(iq):
          raise ValueError(
              f"q: value ({q}) is too small. It must be possible to represent 1/q in {weight_dtype}, but this value overflows to infinity."
          )
  
      walks = []
      for node in nodes:  # iterate over root nodes
          for walk_number in range(n):  # generate n walks per root node
              # the walk starts at the root
              walk = [node]
  
              previous_node = None
              previous_node_neighbours = []
  
              current_node = node
  
              for _ in range(length - 1):
                  # select one of the neighbours using the
                  # appropriate transition probabilities
                  if weighted:
                      neighbours, weights = self.graph.neighbor_arrays(
                          current_node,
                          include_edge_weight=True,
                          use_ilocs=True,
                      )
                  else:
                      neighbours = self.graph.neighbor_arrays(
                          current_node, use_ilocs=True
                      )
                      weights = np.ones(
                          neighbours.shape, dtype=weight_dtype
                      )
                  if len(neighbours) == 0:
                      break
  
                  mask = neighbours == previous_node
                  weights[mask] *= ip
                  mask |= np.isin(neighbours, previous_node_neighbours)
                  weights[~mask] *= iq
  
                  choice = naive_weighted_choices(rs, weights)
                  if choice is None:
                      break
  
                  previous_node = current_node
                  previous_node_neighbours = neighbours
                  current_node = neighbours[choice]
  
                  walk.append(current_node)
  
              walks.append(list(self.graph.node_ilocs_to_ids(walk)))
  
      return walks
  
imports: import numpy
  import warnings
  from collections import defaultdict, deque
  from scipy import stats
  from scipy.special import softmax
  from ..core.schema import GraphSchema
  from ..core.graph import StellarGraph
  from ..core.utils import is_real_iterable
  from ..core.validation import require_integer_in_range, comma_sep
  from ..random import random_state
  from abc import ABC, abstractmethod
label_desc: Use image node_id 3 for calling the BiasedRandomWalk obj's underlying member method code with example usage: obj.run(nodes) and returns: walks