def filter_batch(batch, percentile):
    rewards = list(map((lambda s: s.reward), batch))
    reward_bound = np.percentile(rewards, percentile)
    reward_mean = float(np.mean(rewards))
    train_obs = []
    train_act = []
    for example in batch:
        if (example.reward < reward_bound):
            continue
        train_obs.extend(map((lambda step: step.observation), example.steps))
        train_act.extend(map((lambda step: step.action), example.steps))
    train_obs_v = torch.FloatTensor(train_obs)
    train_act_v = torch.LongTensor(train_act)
    return (train_obs_v, train_act_v, reward_bound, reward_mean)
def filter_batch(batch, percentile):
    rewards = list(map((lambda s: s.reward), batch))
    reward_bound = np.percentile(rewards, percentile)
    reward_mean = float(np.mean(rewards))
    train_obs = []
    train_act = []
    for example in batch:
        if (example.reward < reward_bound):
            continue
        train_obs.extend(map((lambda step: step.observation), example.steps))
        train_act.extend(map((lambda step: step.action), example.steps))
    train_obs_v = torch.FloatTensor(train_obs)
    train_act_v = torch.LongTensor(train_act)
    return (train_obs_v, train_act_v, reward_bound, reward_mean)