class_docstr: Implementation of graph structure in pgl.
  
  This is a simple implementation of graph structure in pgl.
  
  Args:
      num_nodes: number of nodes in a graph
      edges: list of (u, v) tuples
      node_feat (optional): a dict of numpy array as node features
      edge_feat (optional): a dict of numpy array as edge features (should
                              have consistent order with edges)
  
  Examples:
  
      .. code-block:: python
  
          import numpy as np
          num_nodes = 5
          edges = [ (0, 1), (1, 2), (3, 4)]
          feature = np.random.randn(5, 100)
          edge_feature = np.random.randn(3, 100)
          graph = Graph(num_nodes=num_nodes,
                      edges=edges,
                      node_feat={
                          "feature": feature
                      },
                      edge_feat={
                          "edge_feature": edge_feature
                      })
class_docstr_tok: ["Implementation","of","graph","structure","in","pgl",".","This","is","a","simple","implementation","of","graph","structure","in","pgl",".","Args",":","num_nodes",":","number","of","nodes","in","a","graph","edges",":","list","of","(","u",",","v",")","tuples","node_feat","(","optional",")",":","a","dict","of","numpy","array","as","node","features","edge_feat","(","optional",")",":","a","dict","of","numpy","array","as","edge","features","(","should","have","consistent","order","with","edges",")","Examples",":","..","code-block",":",":","python","import","numpy","as","np","num_nodes","=","5","edges","=","[","(","0",",","1",")",",","(","1",",","2",")",",","(","3",",","4",")","]","feature","=","np.random.randn","(","5",",","100",")","edge_feature","=","np.random.randn","(","3",",","100",")","graph","=","Graph","(","num_nodes=num_nodes",",","edges=edges",",","node_feat=","{","``","feature","''",":","feature","}",",","edge_feat=","{","``","edge_feature","''",":","edge_feature","}",")"]
docstr: Implement of node2vec stype random walk.
  
  Reference paper: https://cs.stanford.edu/~jure/pubs/node2vec-kdd16.pdf.
  
  Args:
      nodes: Walk starting from nodes
      max_depth: Max walking depth
      p: Return parameter
      q: In-out parameter
  
  Return:
      A list of walks.
code: def node2vec_random_walk(self, nodes, max_depth, p=1.0, q=1.0):
      """Implement of node2vec stype random walk.
  
      Reference paper: https://cs.stanford.edu/~jure/pubs/node2vec-kdd16.pdf.
  
      Args:
          nodes: Walk starting from nodes
          max_depth: Max walking depth
          p: Return parameter
          q: In-out parameter
  
      Return:
          A list of walks.
      """
      if p == 1.0 and q == 1.0:
          return self.random_walk(nodes, max_depth)
  
      walk = []
      # init
      for node in nodes:
          walk.append([node])
  
      cur_walk_ids = np.arange(0, len(nodes))
      cur_nodes = np.array(nodes)
      prev_nodes = np.array([-1] * len(nodes), dtype="int64")
      prev_succs = np.array([[]] * len(nodes), dtype="int64")
      for l in range(max_depth):
          # select the walks not end
          outdegree = self.outdegree(cur_nodes)
          mask = outdegree != 0
          if np.any(mask):
              cur_walk_ids = cur_walk_ids[mask]
              cur_nodes = cur_nodes[mask]
              prev_nodes = prev_nodes[mask]
              prev_succs = prev_succs[mask]
          else:
              # stop when all nodes have no successor
              break
          cur_succs = self.successor(cur_nodes)
          num_nodes = cur_nodes.shape[0]
          nxt_nodes = np.zeros(num_nodes, dtype="int64")
  
          for idx, (succ, prev_succ, walk_id, prev_node) in enumerate(
              zip(cur_succs, prev_succs, cur_walk_ids, prev_nodes)
          ):
              sampled_succ = graph_kernel.node2vec_sample(
                  succ, prev_succ, prev_node, p, q
              )
              walk[walk_id].append(sampled_succ)
              nxt_nodes[idx] = sampled_succ
  
          prev_nodes, prev_succs = cur_nodes, cur_succs
          cur_nodes = nxt_nodes
      return walk
  
imports: import os
  import numpy
  import pickle
  import time
  import pgl.graph_kernel
  from collections import defaultdict
label_desc: Use image node_id 26 for calling the Graph obj's underlying member method code with example usage: obj.node2vec_random_walk(nodes, max_depth, p, q) and returns: walk, self