Esempio n. 1
0
def _compute_hardness():
    # Load the stanford data to compute the hardness.
    if FLAGS.type == '':
        args = sna.get_args_for_config(FLAGS.config_name + '+bench_' +
                                       FLAGS.imset)
    else:
        args = sna.get_args_for_config(FLAGS.type + '.' + FLAGS.config_name +
                                       '+bench_' + FLAGS.imset)

    args.navtask.logdir = None
    R = lambda: nav_env.get_multiplexer_class(args.navtask, 0)
    R = R()

    rng_data = [np.random.RandomState(0), np.random.RandomState(0)]

    # Sample a room.
    h_dists = []
    gt_dists = []
    for i in range(250):
        e = R.sample_env(rng_data)
        nodes = e.task.nodes

        # Initialize the agent.
        init_env_state = e.reset(rng_data)

        gt_dist_to_goal = [
            e.episode.dist_to_goal[0][j][s]
            for j, s in enumerate(e.episode.start_node_ids)
        ]

        for j in range(args.navtask.task_params.batch_size):
            start_node_id = e.episode.start_node_ids[j]
            end_node_id = e.episode.goal_node_ids[0][j]
            h_dist = graph_utils.heuristic_fn_vec(
                nodes[[start_node_id], :],
                nodes[[end_node_id], :],
                n_ori=args.navtask.task_params.n_ori,
                step_size=args.navtask.task_params.step_size)[0][0]
            gt_dist = e.episode.dist_to_goal[0][j][start_node_id]
            h_dists.append(h_dist)
            gt_dists.append(gt_dist)

    h_dists = np.array(h_dists)
    gt_dists = np.array(gt_dists)
    e = R.sample_env([np.random.RandomState(0), np.random.RandomState(0)])
    input = e.get_common_data()
    orig_maps = input['orig_maps'][0, 0, :, :, 0]
    return h_dists, gt_dists, orig_maps
Esempio n. 2
0
def _compute_hardness():
  # Load the stanford data to compute the hardness.
  if FLAGS.type == '':
    args = sna.get_args_for_config(FLAGS.config_name+'+bench_'+FLAGS.imset)
  else:
    args = sna.get_args_for_config(FLAGS.type+'.'+FLAGS.config_name+'+bench_'+FLAGS.imset)

  args.navtask.logdir = None
  R = lambda: nav_env.get_multiplexer_class(args.navtask, 0)
  R = R()

  rng_data = [np.random.RandomState(0), np.random.RandomState(0)]

  # Sample a room.
  h_dists = []
  gt_dists = []
  for i in range(250):
    e = R.sample_env(rng_data)
    nodes = e.task.nodes

    # Initialize the agent.
    init_env_state = e.reset(rng_data)

    gt_dist_to_goal = [e.episode.dist_to_goal[0][j][s]
                       for j, s in enumerate(e.episode.start_node_ids)]

    for j in range(args.navtask.task_params.batch_size):
      start_node_id = e.episode.start_node_ids[j]
      end_node_id =e.episode.goal_node_ids[0][j]
      h_dist = graph_utils.heuristic_fn_vec(
          nodes[[start_node_id],:], nodes[[end_node_id], :],
          n_ori=args.navtask.task_params.n_ori,
          step_size=args.navtask.task_params.step_size)[0][0]
      gt_dist = e.episode.dist_to_goal[0][j][start_node_id]
      h_dists.append(h_dist)
      gt_dists.append(gt_dist)

  h_dists = np.array(h_dists)
  gt_dists = np.array(gt_dists)
  e = R.sample_env([np.random.RandomState(0), np.random.RandomState(0)])
  input = e.get_common_data()
  orig_maps = input['orig_maps'][0,0,:,:,0]
  return h_dists, gt_dists, orig_maps