code: def detect_trajectory(
      f_next_step,
      grid,
      coords,
      max_iter=30,
      return_none_if_failed=False,
  ):
      target_coords = get_target_coords(grid)
      input_grid = asfloat(np.expand_dims(grid, axis=0))
      grid = grid[:, :, 0]
  
      trajectory = [coords]
      coord_x, coord_y = coords
  
      for i in range(max_iter):
          current_position = (coord_x, coord_y)
  
          if target_coords == current_position:
              # Network successfully reached desired destination.
              break
  
          if grid[current_position] == 1:
              # Interrupt trajectory detection procedure, because
              # current position is located on the obstacle.
              break
  
          step = f_next_step(
              [
                  input_grid,
                  int_as_2d_array(coord_x),
                  int_as_2d_array(coord_y),
              ]
          )
          step = np.argmax(step, axis=1)
          action = actions[step[0]]
  
          coord_x, coord_y = action(coord_x, coord_y)
          trajectory.append((coord_x, coord_y))
  
      if return_none_if_failed and trajectory[-1] != target_coords:
          return None
  
      return np.array(trajectory)
  
file_path: neupy/examples/reinforcement_learning/vin/evaluation.py
imports: from __future__ import division
  import numpy
  from tqdm import tqdm
  from neupy.utils import asfloat
label_desc: Use image node_id 3 for calling a global function with example usage: detect_trajectory(f_next_step, grid, coords, max_iter, return_none_if_failed) and returns: np, None