Loading

IIT-M RL-ASSIGNMENT-2-GRIDWORLD

Solution for submission 131987

A detailed solution for submission 131987 submitted for challenge IIT-M RL-ASSIGNMENT-2-GRIDWORLD

g_prashant_bs17b011

What is the notebook about?

Problem - Gridworld Environment Algorithms

This problem deals with a grid world and stochastic actions. The tasks you have to do are:

  • Implement Policy Iteration
  • Implement Value Iteration
  • Implement TD lamdda
  • Visualize the results
  • Explain the results

How to use this notebook? 📝

  • This is a shared template and any edits you make here will not be saved.You should make a copy in your own drive. Click the "File" menu (top-left), then "Save a Copy in Drive". You will be working in your copy however you like.

  • Update the config parameters. You can define the common variables here

Variable Description
AICROWD_DATASET_PATH Path to the file containing test data. This should be an absolute path.
AICROWD_RESULTS_DIR Path to write the output to.
AICROWD_ASSETS_DIR In case your notebook needs additional files (like model weights, etc.,), you can add them to a directory and specify the path to the directory here (please specify relative path). The contents of this directory will be sent to AIcrowd for evaluation.
AICROWD_API_KEY In order to submit your code to AIcrowd, you need to provide your account's API key. This key is available at https://www.aicrowd.com/participants/me

Setup AIcrowd Utilities 🛠

We use this to bundle the files for submission and create a submission on AIcrowd. Do not edit this block.

In [143]:
!pip install aicrowd-cli > /dev/null

AIcrowd Runtime Configuration 🧷

Get login API key from https://www.aicrowd.com/participants/me

In [144]:
import os

AICROWD_DATASET_PATH = os.getenv("DATASET_PATH", os.getcwd()+"/a5562c7d-55f0-4d06-841c-110655bb04ec_a2_gridworld_inputs.zip")
AICROWD_RESULTS_DIR = os.getenv("OUTPUTS_DIR", "results")
In [145]:

API Key valid
Saved API Key successfully!
a5562c7d-55f0-4d06-841c-110655bb04ec_a2_gridworld_inputs.zip: 100% 14.2k/14.2k [00:00<00:00, 572kB/s]
In [146]:
!unzip -q $AICROWD_DATASET_PATH
replace inputs/inputs_base.npy? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
In [147]:
DATASET_DIR = 'inputs/'

GridWorld Environment

Read the code for the environment thoroughly

Do not edit the code for the environment

In [148]:
import numpy as np
from copy import deepcopy
import matplotlib.pyplot as plt
import pandas as pd
class GridEnv_HW2:
    def __init__(self, 
                 goal_location, 
                 action_stochasticity,
                 non_terminal_reward,
                 terminal_reward,
                 grey_in,
                 brown_in,
                 grey_out,
                 brown_out
                ):

        # Do not edit this section 
        self.action_stochasticity = action_stochasticity
        self.non_terminal_reward = non_terminal_reward
        self.terminal_reward = terminal_reward
        self.grid_size = [10, 10]

        # Index of the actions 
        self.actions = {'N': (1, 0), 
                        'E': (0,1),
                        'S': (-1,0), 
                        'W': (0,-1)}
        
        self.perpendicular_order = ['N', 'E', 'S', 'W']
        
        l = ['normal' for _ in range(self.grid_size[0]) ]
        self.grid = np.array([l for _ in range(self.grid_size[1]) ], dtype=object)

        self.grid[goal_location[0], goal_location[1]] = 'goal'
        self.goal_location = goal_location

        for gi in grey_in:
            self.grid[gi[0],gi[1]] = 'grey_in'
        for bi in brown_in:    
            self.grid[bi[0], bi[1]] = 'brown_in'

        for go in grey_out:    
            self.grid[go[0], go[1]] = 'grey_out'
        for bo in brown_out:    
            self.grid[bo[0], bo[1]] = 'brown_out'

        self.grey_outs = grey_out
        self.brown_outs = brown_out

    def _out_of_grid(self, state):
        if state[0] < 0 or state[1] < 0:
            return True
        elif state[0] > self.grid_size[0] - 1:
            return True
        elif state[1] > self.grid_size[1] - 1:
            return True
        else:
            return False

    def _grid_state(self, state):
        return self.grid[state[0], state[1]]        
        
    def get_transition_probabilites_and_reward(self, state, action):
        """ 
        Returns the probabiltity of all possible transitions for the given action in the form:
        A list of tuples of (next_state, probability, reward)
        Note that based on number of state and action there can be many different next states
        Unless the state is All the probabilities of next states should add up to 1
        """

        grid_state = self._grid_state(state)
        
        if grid_state == 'goal':
            return [(self.goal_location, 1.0, 0.0)]
        elif grid_state == 'grey_in':
            npr = []
            for go in self.grey_outs:
                npr.append((go, 1/len(self.grey_outs), 
                            self.non_terminal_reward))
            return npr
        elif grid_state == 'brown_in':
            npr = []
            for bo in self.brown_outs:
                npr.append((bo, 1/len(self.brown_outs), 
                            self.non_terminal_reward))
            return npr
        
        direction = self.actions.get(action, None)
        if direction is None:
            raise ValueError("Invalid action %s , please select among" % action, list(self.actions.keys()))

        dir_index = self.perpendicular_order.index(action)
        wrap_acts = self.perpendicular_order[dir_index:] + self.perpendicular_order[:dir_index]
        next_state_probs = {}
        for prob, a in zip(self.action_stochasticity, wrap_acts):
            d = self.actions[a]
            next_state = (state[0] + d[0]), (state[1] + d[1])
            if self._out_of_grid(next_state):
                next_state = state
            next_state_probs.setdefault(next_state, 0.0)
            next_state_probs[next_state] += prob

        npr = []
        for ns, prob in next_state_probs.items():
            next_grid_state = self._grid_state(ns)
            reward = self.terminal_reward if next_grid_state == 'goal' else self.non_terminal_reward
            npr.append((ns, prob, reward))

        return npr

    def step(self, state, action):
        npr = self.get_transition_probabilites_and_reward(state, action)
        probs = [t[1] for t in npr]
        sampled_idx = np.random.choice(range(len(npr)), p=probs)
        sampled_npr = npr[sampled_idx]
        next_state = sampled_npr[0]
        reward = sampled_npr[2]
        is_terminal = next_state == tuple(self.goal_location)
        return next_state, reward, is_terminal

Example environment

This has the same setup as the pdf, do not edit the settings

In [149]:
def get_base_kwargs():
    goal_location = (9,9)
    action_stochasticity = [0.8, 0.2/3, 0.2/3, 0.2/3]
    grey_out = [(3,2), (4,2), (5,2), (6,2)]
    brown_in = [(9,7)]
    grey_in = [(0,0)]
    brown_out = [(1,7)]
    non_terminal_reward = 0
    terminal_reward = 10

    base_kwargs =  {"goal_location": goal_location, 
            "action_stochasticity": action_stochasticity,
            "brown_in": brown_in, 
            "grey_in": grey_in, 
            "brown_out": brown_out,
            "non_terminal_reward": non_terminal_reward,
            "terminal_reward": terminal_reward,
            "grey_out": grey_out,}
    
    return base_kwargs

base_kwargs = get_base_kwargs()

Task 2.1 - Value Iteration

Run value iteration on the environment and generate the policy and expected reward

In [150]:
def value_iteration(env, gamma):
    # Initial Values
    values = np.zeros((10, 10))

    # Initial policy
    policy = np.empty((10, 10), object)
    policy[:] = 'N' # Make all the policy values as 'N'

    # Begin code here
    
    # Put your extra information needed for plots etc in this dictionary
    extra_info = {}
    n = values.shape[0]
    
    #initializing cost vector
    J = np.zeros((n*n,1))
    #Policy Vector
    pi_s = np.zeros((n*n,1))
    #Invoking all possible actions
    action_space = env.actions
    #Transtition Probability Matrix for each action
    transition_probs = {act:np.zeros((n*n,n*n)) for act in action_space.keys()}
    #Reward Matrix for each action
    transition_rewards = {act:np.zeros((n*n,n*n)) for act in action_space.keys()}
    #Assigning probabilities and rewards
    for action in action_space:
      for i in range(values.shape[0]):
        for j in range(values.shape[1]):
          state = (i,j)
          pseudo_state = i*values.shape[0]+j
          next = env.get_transition_probabilites_and_reward(state,action)
          for ele in next:
            next_state = ele[0]
            pseudo_next = next_state[0]*values.shape[0]+next_state[1]
            transition_probs[action][pseudo_state,pseudo_next] = ele[1]
            transition_rewards[action][pseudo_state,pseudo_next] = ele[2]
    #Setting Tolerance Level
    tol = 1e-8
    ite = 0
    delta = 0
    extra_info["Expected Rewards"] = [deepcopy(values)]
    extra_info["Policies"] = [deepcopy(policy)]

    #Convergence Criteria
    while delta>tol or ite == 0:
      ite += 1
      delta = 0
      J_new = np.zeros((n*n,1))
      policy_new = np.empty((n*n, 1), object)
      for i in range(len(J)):
        state = (i//n,i%n)
        j = J[i]
        MAX = -np.inf
        for action in action_space:
          r_a = transition_rewards[action][i,:].T
          P_a = transition_probs[action][i,:].T
          #Value Iteration
          tmp = np.dot(P_a,r_a+gamma*J.ravel())
          # Maximum J(s) across all actions
          if tmp > MAX:
            MAX = tmp
            J_new[i] = tmp
            best_action = action
        policy_new[i] = best_action
        delta = max(delta,abs(j-MAX))
      #Updating J
      J = deepcopy(J_new)
      policy = policy_new.reshape((n,n))
      values = J.reshape((n,n))
      extra_info["Expected Rewards"].append(deepcopy(values))
      extra_info["Policies"].append(deepcopy(policy))
    # End code

    # Do not change the number of output values
    return {"Values": values, "Policy": policy}, extra_info
In [151]:
env = GridEnv_HW2(**base_kwargs)
res, extra_info = value_iteration(env, 0.7)

 # The rounding off is just for making print statement cleaner
print(np.flipud(np.round(res['Values'], decimals=2)))
print(np.flipud(res['Policy']))
[[0.1  0.15 0.24 0.37 0.56 0.86 1.29 0.12 8.68 0.  ]
 [0.13 0.2  0.31 0.5  0.81 1.31 2.12 3.43 5.75 8.95]
 [0.1  0.16 0.25 0.39 0.62 0.97 1.52 2.38 3.7  5.61]
 [0.07 0.11 0.17 0.26 0.41 0.64 0.99 1.54 2.38 3.52]
 [0.05 0.07 0.11 0.17 0.27 0.41 0.64 0.99 1.53 2.21]
 [0.03 0.05 0.07 0.11 0.17 0.27 0.41 0.64 0.98 1.39]
 [0.02 0.03 0.05 0.07 0.11 0.17 0.27 0.41 0.63 0.87]
 [0.03 0.02 0.03 0.05 0.07 0.11 0.17 0.27 0.4  0.55]
 [0.04 0.03 0.02 0.03 0.05 0.07 0.11 0.17 0.26 0.35]
 [0.07 0.04 0.03 0.02 0.03 0.05 0.07 0.11 0.17 0.22]]
[['E' 'E' 'E' 'E' 'E' 'S' 'S' 'N' 'E' 'N']
 ['E' 'E' 'E' 'E' 'E' 'E' 'E' 'E' 'E' 'N']
 ['E' 'E' 'E' 'E' 'E' 'E' 'E' 'E' 'N' 'N']
 ['E' 'E' 'E' 'E' 'E' 'E' 'E' 'E' 'N' 'N']
 ['N' 'E' 'E' 'E' 'E' 'E' 'E' 'N' 'N' 'N']
 ['N' 'E' 'E' 'E' 'E' 'E' 'N' 'N' 'N' 'N']
 ['N' 'N' 'E' 'E' 'E' 'N' 'N' 'N' 'N' 'N']
 ['S' 'N' 'E' 'E' 'E' 'N' 'N' 'N' 'N' 'N']
 ['S' 'S' 'E' 'E' 'E' 'E' 'N' 'N' 'N' 'N']
 ['N' 'W' 'W' 'E' 'E' 'E' 'E' 'N' 'N' 'N']]

Task 2.2 - Policy Iteration

Run policy iteration on the environment and generate the policy and expected reward

In [152]:
def policy_iteration(env, gamma):
    # Initial Values
    values = np.zeros((10, 10))

    # Initial policy
    policy = np.empty((10, 10), object)
    policy[:] = 'N' # Make all the policy values as 'N'

    # Begin code here   
    
    # Put your extra information needed for plots etc in this dictionary
    extra_info = {}
    n = values.shape[0]

    #initializing cost vector
    J = np.zeros((n*n,1))
    #Policy Vector
    pi_s = np.zeros((n*n,1))
    #Invoking all possible actions
    action_space = env.actions
    #Transtition Probability Matrix for each action
    transition_probs = {act:np.zeros((n*n,n*n)) for act in action_space.keys()}
    #Reward Matrix for each action
    transition_rewards = {act:np.zeros((n*n,n*n)) for act in action_space.keys()}
    #Assigning probabilities and rewards
    for action in action_space:
      for i in range(values.shape[0]):
        for j in range(values.shape[1]):
          state = (i,j)
          pseudo_state = i*values.shape[0]+j
          next = env.get_transition_probabilites_and_reward(state,action)
          for ele in next:
            next_state = ele[0]
            pseudo_next = next_state[0]*values.shape[0]+next_state[1]
            transition_probs[action][pseudo_state,pseudo_next] = ele[1]
            transition_rewards[action][pseudo_state,pseudo_next] = ele[2]
    
    done = 0
    tol = 1e-8
    ite1 = 0
    extra_info["Expected Rewards"] = [deepcopy(values)]
    extra_info["Policies"] = [deepcopy(policy)]
    while done == 0:
      ite1 += 1
      ite2 = 0
      delta = 0
      while delta > tol or ite2 == 0:
        ite2 += 1
        delta = 0
        tmp = np.zeros((n*n,1))
        for i in range(len(J)):
          state = (i//n,i%n)
          j = J[i]
          act = policy[state[0],state[1]]
          r_a = transition_rewards[act][i,:].T
          P_a = transition_probs[act][i,:].T
          tmp[i] = np.dot(P_a,r_a+gamma*J.ravel())
          delta = max(delta,abs(j-tmp[i]))
        J = deepcopy(tmp)
        values = J.reshape((n,n))

      done = 1

      policy_old = deepcopy(policy)
      for i in range(len(J)):
          state = (i//n,i%n)
          MAX = -np.inf
          for act in action_space:
            r_a = transition_rewards[act][i,:].T
            P_a = transition_probs[act][i,:].T
            J_new = np.dot(P_a,r_a+gamma*J.ravel())
            if J_new > MAX:
              MAX = J_new
              best_act = act
            # J_vals.append(J_new)
          policy[state[0],state[1]] = best_act
          if best_act!= policy_old[state[0],state[1]]:
            done = 0
      extra_info["Expected Rewards"].append(deepcopy(values))
      extra_info["Policies"].append(deepcopy(policy))

    # End code

    # Do not change the number of output values
    return {"Values": values, "Policy": policy}, extra_info
In [153]:
env = GridEnv_HW2(**base_kwargs)
res, extra_info = policy_iteration(env, 0.7)

 # The rounding off is just for making print statement cleaner
print(np.flipud(np.round(res['Values'], decimals=2)))
print(np.flipud(res['Policy']))
[[0.1  0.15 0.24 0.37 0.56 0.86 1.29 0.12 8.68 0.  ]
 [0.13 0.2  0.31 0.5  0.81 1.31 2.12 3.43 5.75 8.95]
 [0.1  0.16 0.25 0.39 0.62 0.97 1.52 2.38 3.7  5.61]
 [0.07 0.11 0.17 0.26 0.41 0.64 0.99 1.54 2.38 3.52]
 [0.05 0.07 0.11 0.17 0.27 0.41 0.64 0.99 1.53 2.21]
 [0.03 0.05 0.07 0.11 0.17 0.27 0.41 0.64 0.98 1.39]
 [0.02 0.03 0.05 0.07 0.11 0.17 0.27 0.41 0.63 0.87]
 [0.03 0.02 0.03 0.05 0.07 0.11 0.17 0.27 0.4  0.55]
 [0.04 0.03 0.02 0.03 0.05 0.07 0.11 0.17 0.26 0.35]
 [0.07 0.04 0.03 0.02 0.03 0.05 0.07 0.11 0.17 0.22]]
[['E' 'E' 'E' 'E' 'E' 'S' 'S' 'N' 'E' 'N']
 ['E' 'E' 'E' 'E' 'E' 'E' 'E' 'E' 'E' 'N']
 ['E' 'E' 'E' 'E' 'E' 'E' 'E' 'E' 'N' 'N']
 ['E' 'E' 'E' 'E' 'E' 'E' 'E' 'E' 'N' 'N']
 ['N' 'E' 'E' 'E' 'E' 'E' 'E' 'N' 'N' 'N']
 ['N' 'E' 'E' 'E' 'E' 'E' 'N' 'N' 'N' 'N']
 ['N' 'N' 'E' 'E' 'E' 'N' 'N' 'N' 'N' 'N']
 ['S' 'N' 'E' 'E' 'E' 'N' 'N' 'N' 'N' 'N']
 ['S' 'S' 'E' 'E' 'E' 'E' 'N' 'N' 'N' 'N']
 ['N' 'W' 'W' 'E' 'E' 'E' 'E' 'N' 'N' 'N']]

Task 2.3 - TD Lambda

Use the heuristic policy and implement TD lambda to find values on the gridworld

In [154]:
# The policy mentioned in the pdf to be used for TD lambda, do not modify this
def heuristic_policy(env, state):
    goal = env.goal_location
    dx = goal[0] - state[0]
    dy = goal[1] - state[1]
    if abs(dx) >= abs(dy):
        direction = (np.sign(dx), 0)
    else:
        direction = (0, np.sign(dy))
    for action, dir_val in env.actions.items():
        if dir_val == direction:
            target_action = action
            break
    return target_action
In [155]:
def td_lambda(env, lamda, seeds):
    alpha = 0.5
    gamma = 0.7
    N = len(seeds)
    # Usage of input_policy
    # heuristic_policy(env, state) -> action
    example_action = heuristic_policy(env, (1,2)) # Returns 'N' if goal is (9,9)

    # Example of env.step
    # env.step(state, action) -> Returns next_state, reward, is_terminal

    # Initial values
    values = np.zeros((10, 10))
    es = np.zeros((10,10))
    n = values.shape[0]
    extra_info = {}
    extra_info['Reward'] = [deepcopy(values)]
    for episode_idx in range(N):
         # Do not change this else the results will not match due to environment stochas
        np.random.seed(seeds[episode_idx])
        grey_in_loc = np.where(env.grid == 'grey_in')
        state = grey_in_loc[0][0], grey_in_loc[1][0]
        done = False
        while not done:
            action = heuristic_policy(env, state)
            ns, rew, is_terminal = env.step(state, action) 
            # env.step is already taken inside the loop for you, 
            # Don't use env.step anywhere else in your code

            # Begin code here
            delta = rew + gamma*values[ns[0],ns[1]] - values[state[0],state[1]]
            es[state[0],state[1]] += 1 
            values = values + alpha*delta*es
            es = gamma*lamda*es
            state = deepcopy(ns)
            if is_terminal:
              done = True
            extra_info['Reward'].append(deepcopy(values))

    # End code

    # Do not change the number of output values
    return {"Values": values}, extra_info
In [156]:
env = GridEnv_HW2(**base_kwargs)
res, extra_info = td_lambda(env, lamda=0.5, seeds=np.arange(1000))

 # The rounding off is just for making print statement cleaner
print(np.flipud(np.round(res['Values'], decimals=2)))
[[ 0.    0.    0.01  0.02  0.03  0.06  0.08  0.11 10.    0.  ]
 [ 0.    0.    0.04  0.18  0.91  1.4   1.28  4.85  6.98  9.92]
 [ 0.    0.05  0.24  0.42  0.63  0.71  2.08  3.28  3.8   5.89]
 [ 0.02  0.08  0.21  0.31  0.48  0.82  1.29  1.66  2.2   3.39]
 [ 0.02  0.07  0.08  0.11  0.25  0.4   0.52  0.96  1.62  1.44]
 [ 0.02  0.04  0.05  0.1   0.16  0.23  0.38  0.57  1.08  0.97]
 [ 0.01  0.03  0.03  0.05  0.08  0.17  0.2   0.35  0.58  0.26]
 [ 0.    0.01  0.03  0.03  0.07  0.1   0.15  0.23  0.18  0.18]
 [ 0.    0.    0.01  0.01  0.03  0.03  0.1   0.15  0.16  0.  ]
 [ 0.12  0.    0.    0.    0.    0.01  0.01  0.11  0.13  0.  ]]

Task 2.4 - TD Lamdba for multiple values of $\lambda$

Ideally this code should run as is

In [157]:
# This cell is only for your subjective evaluation results, display the results as asked in the pdf
# You can change it as you require, this code should run TD lamdba by default for different values of lambda

lamda_values = np.arange(0, 100+5, 5)/100
td_lamda_results = {}
extra_info_TD = {}
for lamda in lamda_values:
    env = GridEnv_HW2(**base_kwargs)
    td_lamda_results[lamda], extra_info_TD[lamda] = td_lambda(env, lamda,
                                                           seeds=np.arange(1000))

Generate Results ✅

In [158]:
def get_results(kwargs):

    gridenv = GridEnv_HW2(**kwargs)

    policy_iteration_results = policy_iteration(gridenv, 0.7)[0]
    value_iteration_results = value_iteration(gridenv, 0.7)[0]
    td_lambda_results = td_lambda(env, 0.5, np.arange(1000))[0]

    final_results = {}
    final_results["policy_iteration"] = policy_iteration_results
    final_results["value_iteration"] = value_iteration_results
    final_results["td_lambda"] = td_lambda_results

    return final_results
In [159]:
# Do not edit this cell, generate results with it as is
if not os.path.exists(AICROWD_RESULTS_DIR):
    os.mkdir(AICROWD_RESULTS_DIR)

for params_file in os.listdir(DATASET_DIR):
  kwargs = np.load(os.path.join(DATASET_DIR, params_file), allow_pickle=True).item()
  results = get_results(kwargs)
  idx = params_file.split('_')[-1][:-4]
  np.save(os.path.join(AICROWD_RESULTS_DIR, 'results_' + idx), results)

Check your score on the public data

This scores is not your final score, and it doesn't use the marks weightages. This is only for your reference of how arrays are matched and with what tolerance.

In [160]:
# Check your score on the given test cases (There are more private test cases not provided)
target_folder = 'targets'
result_folder = AICROWD_RESULTS_DIR

def check_algo_match(results, targets):
    if 'Policy' in results:
        policy_match = results['Policy'] == targets['Policy']
    else:
        policy_match = True
    # Reference https://numpy.org/doc/stable/reference/generated/numpy.allclose.html
    rewards_match = np.allclose(results['Values'], targets['Values'], rtol=3)
    equal = rewards_match and policy_match
    return equal

def check_score(target_folder, result_folder):
    match = []
    for out_file in os.listdir(result_folder):
        res_file = os.path.join(result_folder, out_file)
        results = np.load(res_file, allow_pickle=True).item()
        idx = out_file.split('_')[-1][:-4]  # Extract the file number
        target_file = os.path.join(target_folder, f"targets_{idx}.npy")
        targets = np.load(target_file, allow_pickle=True).item()
        algo_match = []
        for k in targets:
            algo_results = results[k]
            algo_targets = targets[k]
            algo_match.append(check_algo_match(algo_results, algo_targets))
        match.append(np.mean(algo_match))
    return np.mean(match)

if os.path.exists(target_folder):
    print("Shared data Score (normalized to 1):", check_score(target_folder, result_folder))
Shared data Score (normalized to 1): 1.0
/usr/local/lib/python3.7/dist-packages/numpy/core/_asarray.py:136: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
  return array(a, dtype, copy=False, order=order, subok=True)

Display Results of TD lambda

Display Results of TD lambda with lambda values from 0 to 1 with steps of 0.05

Add code/text as required

In [161]:
pd.set_option('display.max_colwidth', None)
pd.DataFrame(td_lamda_results).T
Out[161]:
Values
0.00 [[0.11220578033298932, 0.0, 0.0, 0.0, 0.0, 0.0017376043481768396, 0.0, 0.0657787744254232, 0.068346887525491, 0.0], [0.0, 0.0, 0.005549753089635211, 0.0, 0.012765453849698603, 0.0013765939633981327, 0.08287019180003113, 0.1539147009060231, 0.1422619862085013, 0.0], [0.0, 0.00900393220957427, 0.024201727180540308, 0.019012625609299182, 0.035787937660907196, 0.06931208125976017, 0.1298884733188246, 0.21919787349186348, 0.1860417791125543, 0.0714497181346363], [0.0018648689256255677, 0.017168632063948024, 0.03700971052684397, 0.04480334474466087, 0.07436434889294458, 0.12437363345149632, 0.14389549092306037, 0.3296170869933363, 0.5542874669559789, 0.0], [0.00554681074452701, 0.029973738454166062, 0.05345476847936038, 0.09214623132072705, 0.13775673985014736, 0.22177583709410031, 0.3045685380008174, 0.5667823751469356, 0.9878986397350086, 0.3470949019207416], [0.013081158259113268, 0.05079099283978464, 0.09911409545039324, 0.10738784554648437, 0.1866688532821313, 0.25730926895980333, 0.48389268502367977, 0.9624284014335724, 1.54914648401587, 1.0844543607734807], [0.004858092720263892, 0.04744470881925872, 0.17689951003253648, 0.198858461941318, 0.27365612056873334, 0.4713287313160936, 0.8194546381670034, 1.501906207481873, 2.2867072542163305, 3.5180855239536104], [0.0, 0.046375649353475934, 0.1940741872432657, 0.3791503193935741, 0.5500705670192967, 0.6065251091923831, 1.67621868270033, 3.1340838101719446, 3.4181449363867173, 5.585501248118595], [0.0, 0.0, 0.034498708307998734, 0.09334584185459087, 0.6891674494154003, 1.0916565926457908, 1.5617096096727543, 4.7875575059729805, 6.9451941895791025, 9.910449540355957], [0.0, 0.0, 0.001787328185793577, 0.009485356749709555, 0.02652853951580707, 0.051789395165186394, 0.0784088200540762, 0.10259003791568201, 9.992897358796423, 0.0]]
0.05 [[0.11116585741978822, 0.0, 0.0, 0.0, 0.0, 0.0020913615446541784, 4.0103451843892734e-06, 0.07019348862114945, 0.07570286205444535, 0.0], [0.0, 0.0, 0.00626275807056679, 0.00037473883154454416, 0.014075098960670426, 0.0034847545366317326, 0.08584225207827956, 0.1555081048128394, 0.1469239563915365, 0.0], [1.2092766560240386e-05, 0.009753710932402805, 0.024875077372897868, 0.0201219999253409, 0.03853849847004033, 0.07171573002478195, 0.1314105914081273, 0.22310574319348972, 0.18885348280312902, 0.07380137312380439], [0.0022140616164831157, 0.018242814898964604, 0.036623311604958804, 0.04572669287543596, 0.07566830159041851, 0.12970804204019404, 0.1483879195761756, 0.33836466343680566, 0.5625414343838236, 0.004144486718509644], [0.006483412338017875, 0.03122566435164441, 0.05385415648079271, 0.09193833412042023, 0.13539750903104567, 0.22361079571087794, 0.3139531709708629, 0.5790317711319817, 1.003926515721929, 0.4016822362253182], [0.0140600585303431, 0.05345783746244638, 0.09682480892920613, 0.10682759273119681, 0.18713760477293329, 0.2668661491879632, 0.4890229155477112, 0.9687329798774531, 1.5661750265562453, 1.1309634591824171], [0.0058105256642697976, 0.05031568513391601, 0.17581819894488576, 0.20399417193478186, 0.2908377161454874, 0.5006033671290598, 0.8674943968099567, 1.5119753216975804, 2.279494969177087, 3.5494008628495957], [0.0, 0.04753450126271868, 0.200913593094404, 0.3807941937003757, 0.54844058468032, 0.6170629310164731, 1.7191778886305191, 3.148726513191828, 3.452753913546083, 5.61313209836202], [0.0, 0.0, 0.03584532494246472, 0.09976753142553656, 0.7064259558275533, 1.1420114708587195, 1.5321043655830655, 4.793818615310529, 6.948415172587709, 9.910118863299886], [0.0, 0.0, 0.002226316788551416, 0.01042272390106702, 0.02744919615463124, 0.05262053081283404, 0.07794763968177697, 0.10489647122073856, 9.993986378473853, 0.0]]
0.10 [[0.11005529157238976, 0.0, 0.0, 0.0, 0.0, 0.002525511421035799, 3.411905213747047e-05, 0.0747447224489885, 0.08307027328495, 0.0], [0.0, 0.0, 0.006906355423966387, 0.0008483041822422602, 0.01544950732907031, 0.005720023284246105, 0.08862701187230758, 0.15707947476752954, 0.15093113082320542, 0.0], [4.913219418138527e-05, 0.010467773687057496, 0.025441346781589515, 0.021226341367099583, 0.041451829738989164, 0.07429838415661351, 0.13331497478025037, 0.2270030313208769, 0.19112853764256188, 0.07690104220136312], [0.002578192700133821, 0.01933218305300419, 0.03622874235288177, 0.04659954804862095, 0.07678045034625053, 0.13508484254792105, 0.15304293511888178, 0.3456529818198252, 0.5699325685842851, 0.013340883247724157], [0.007501253484848573, 0.03253129630573937, 0.0539984974234128, 0.09178369814134213, 0.13398254714766672, 0.22510750877903152, 0.32297463186443437, 0.5879850680084241, 1.0168747907026725, 0.45798139214785083], [0.015084710073251462, 0.055837592861041195, 0.09443999768017325, 0.10602053742298856, 0.18881742928143183, 0.27772904997225867, 0.4935502752493209, 0.9739478219439133, 1.5819477156596482, 1.1741270038432992], [0.006939824645991454, 0.053262905000460194, 0.17541825812241357, 0.21043725110568703, 0.3081180770559104, 0.531250536250411, 0.9157827010773573, 1.5232172546729648, 2.2718862576098675, 3.572815928171708], [0.0, 0.04837692719337516, 0.2068701293233496, 0.3827128633772472, 0.5497744128068727, 0.6284863626220106, 1.7620302287727196, 3.163626176182989, 3.488412957483003, 5.642252061463233], [0.0, 0.0, 0.03701309389124363, 0.1063414551036697, 0.726502929203207, 1.1891521546036188, 1.503454977689651, 4.80013583657319, 6.951727073855611, 9.910005039177571], [0.0, 0.0, 0.0026802697402993642, 0.011362108843107272, 0.028296978176086923, 0.05346835208932013, 0.07778499274065089, 0.10683227637853034, 9.995084908527739, 0.0]]
0.15 [[0.10907956102742684, 0.0, 0.0, 0.0, 0.0, 0.003063215437209772, 0.00012267978123118716, 0.07936139106264789, 0.09032683890981495, 0.0], [0.0, 0.0, 0.007470112415127074, 0.0014109962977308709, 0.01689182244767955, 0.008097358753930563, 0.09123979781246053, 0.15848838703713397, 0.15433942953833746, 0.0], [0.00011336848440716423, 0.011139205708929671, 0.02591265701086402, 0.022328203376507965, 0.04452094507579573, 0.07710003070967116, 0.13557379470990796, 0.23049706213671062, 0.1927689775574574, 0.08110718406446407], [0.002958319270787573, 0.02044775496985264, 0.03581952967600427, 0.04741090179770834, 0.07770683666605226, 0.14047252254998913, 0.15795389440998897, 0.35134177643709985, 0.5761155983181899, 0.027466625545814388], [0.008631271251341974, 0.03386993266669896, 0.053960806346211455, 0.09175683851944591, 0.1335493683152407, 0.22625715010944686, 0.33170092992961947, 0.5936161097008655, 1.0272434234380152, 0.5161837966198549], [0.016149058875684213, 0.05792567132331816, 0.09210855980557078, 0.10514634012838367, 0.19176770625148673, 0.28978413669471237, 0.4976620673597378, 0.9777978755776083, 1.5957635676054476, 1.2145913249529299], [0.00823415270891932, 0.05629472934896299, 0.17587132508813685, 0.21820533842106632, 0.32592592763687916, 0.5633097326011355, 0.9642137955677553, 1.5355342859243732, 2.2639213823152606, 3.587941799104837], [0.0, 0.04894312401944115, 0.21205047846521663, 0.38509757683523493, 0.5538209135650553, 0.6402547943286657, 1.8046323994631768, 3.178721681657407, 3.524968278290721, 5.67255602454955], [0.0, 0.0, 0.03802248647717503, 0.11318566717169776, 0.7488498469898297, 1.232744998879102, 1.4754821250339962, 4.80647758075283, 6.955107194782438, 9.910136415369495], [0.0, 0.0, 0.0031445129640421997, 0.012295836024601242, 0.029095792496848485, 0.054332474357659456, 0.07790923700648594, 0.10841050998522969, 9.996188513336147, 0.0]]
0.20 [[0.10840080331692681, 0.0, 0.0, 0.0, 0.0, 0.0037292161853445063, 0.00030964392317115987, 0.0839779214824184, 0.09734358729910744, 0.0], [0.0, 0.0, 0.007950094341547892, 0.002051160018417017, 0.01840061075073304, 0.010638195508808134, 0.09368221894966312, 0.1595679837695473, 0.15714969642790216, 0.0], [0.00020869602333080115, 0.011763161144715093, 0.026304574613839844, 0.023429645109540653, 0.047754586567750265, 0.08013463621945428, 0.13814046604539473, 0.2332883385820086, 0.19365596017204997, 0.08678098854633459], [0.0033564467452742823, 0.021591670570665623, 0.03538556602428221, 0.0481542230633851, 0.0784593652238378, 0.14583875033109786, 0.16319204695764128, 0.3553218529649807, 0.5808380742023124, 0.04639386438891413], [0.009903117514673872, 0.035220194661787066, 0.05379779823119768, 0.09194350945227306, 0.13412157738999905, 0.2270814218606596, 0.34017536031521306, 0.5960139139251893, 1.0355615136863752, 0.5764015102524509], [0.01724904215453881, 0.059757003080721204, 0.08994723242411107, 0.10437843942544989, 0.19600668988517894, 0.30293943406574186, 0.5015403421644207, 0.9800838021546739, 1.6071166661780243, 1.2528246618804477], [0.009681297661748432, 0.05942288225005617, 0.17730433216516472, 0.22733920296805382, 0.34460182264945866, 0.5967361239014826, 1.0126505564898163, 1.5488962359834497, 2.2556245796325802, 3.594214210018315], [0.0, 0.049295175718668344, 0.21659563365882167, 0.3881198936504954, 0.5602725062829337, 0.6519703528866883, 1.8468390228585845, 3.1939495495237673, 3.5622812926583705, 5.70374516266359], [0.0, 0.0, 0.038890611522964615, 0.12042010117637054, 0.7728645500937488, 1.272393078225511, 1.4479454891256864, 4.812815198305132, 6.958540448464237, 9.910555315008674], [0.0, 0.0, 0.003617028367617629, 0.013226174980408038, 0.02987284272953768, 0.055204651993844875, 0.07829112063679927, 0.10959940314755731, 9.997298151321768, 0.0]]
0.25 [[0.1081501504931559, 0.0, 0.0, 0.0, 0.0, 0.004549709630868319, 0.0006425656869119296, 0.0885303106897093, 0.10398201064903607, 0.0], [0.0, 0.0, 0.008347864046540886, 0.002755692740146299, 0.019973302503105795, 0.013369765390038686, 0.09594087262685652, 0.16015343699468423, 0.15932678602176353, 0.0], [0.0003404986657732139, 0.012338389423965028, 0.026632160193285227, 0.024533705312891146, 0.05117193718496641, 0.08339128352649357, 0.1409411132414285, 0.23516788951662806, 0.1936741828958967, 0.09429425925463346], [0.0037752551829077123, 0.02275731596212246, 0.03491681612748655, 0.048834817738491035, 0.07904316915580128, 0.15113719418361024, 0.16879154666021948, 0.35753907187210116, 0.5839483350100075, 0.07000921500168442], [0.01133880128830434, 0.03655757005316018, 0.05355349792629402, 0.09243376419487004, 0.13570878332167083, 0.22761798012754836, 0.34841097953558464, 0.5953929870545784, 1.0423872567300747, 0.6386581568007793], [0.01837876281149512, 0.06139364413032187, 0.08804607110894973, 0.10388060511284485, 0.2015269701048633, 0.3171182731760762, 0.5053360594428061, 0.9806956847383296, 1.615681733229257, 1.2891181987618694], [0.011270390259347953, 0.06266962617738688, 0.17981422599423735, 0.23788878506511152, 0.36440619820555215, 0.6314143801497213, 1.060928471168467, 1.5633414020298964, 2.2470179857801527, 3.5908892691769645], [0.0, 0.049513424957118454, 0.2206821514937066, 0.3919139837465754, 0.5687698105252423, 0.6633606291322545, 1.8885020875404293, 3.209245541751096, 3.600232307177639, 5.735527209587625], [0.0, 0.0, 0.03962982384374701, 0.12816359360598553, 0.7978946337719458, 1.3076558348746827, 1.4206271768805818, 4.81912445408377, 6.962018770202906, 9.911315699391155], [0.0, 0.0, 0.004098763798471678, 0.014162185579036101, 0.030653488814697673, 0.056071651753169395, 0.07888530235106883, 0.11033557197288563, 9.998418834477224, 0.0]]
0.30 [[0.10843920499053794, 0.0, 0.0, 0.0, 0.0, 0.005552729828960568, 0.0011757519051716135, 0.09295649389767924, 0.11009248911878315, 0.0], [0.0, 0.0, 0.008668891802057335, 0.003510701995802719, 0.02160819348567971, 0.016324347447750222, 0.09798732492798258, 0.16010610637630224, 0.16081297521473786, 0.0], [0.0005151457766565078, 0.012868263829376489, 0.026906275756257567, 0.025646200225815863, 0.05479585904020838, 0.0868383187827869, 0.1438686960863344, 0.23601803435613913, 0.19273065756522745, 0.10404389928622061], [0.004218470808300566, 0.023929971501257256, 0.03440571117129735, 0.049473877560479, 0.07944840568691446, 0.15629704466162783, 0.1747391035964683, 0.358021445990459, 0.5854105762453442, 0.09822882468133953], [0.012946316164749653, 0.03785356120316088, 0.05326312202929816, 0.09331700179685708, 0.13830849020835856, 0.22791213622255221, 0.3563874796947831, 0.5921093986755099, 1.0483070940836665, 0.7028800143888266], [0.019527637553096926, 0.06291484728105197, 0.08647391883463224, 0.10380267119020052, 0.20830685046391934, 0.3322537423769606, 0.5091486014480368, 0.9796267258404471, 1.6213013357448167, 1.323586593822726], [0.012991570362350198, 0.06607116738639587, 0.1834778442386376, 0.24989979404012336, 0.38552697596358637, 0.6671709888689384, 1.1088592059522207, 1.5789765986471231, 2.238137570206853, 3.5770387085128803], [0.0, 0.0496925282979574, 0.2245162519671613, 0.39656002854277217, 0.5789032111376494, 0.6742611704899776, 1.9294717418120297, 3.2245462980717123, 3.638725920467358, 5.767617374315356], [0.0, 0.0, 0.040247280799061314, 0.13653322427256348, 0.8232438240290741, 1.3380657546719468, 1.3933174754539839, 4.825386159744139, 6.96554057146125, 9.912480148604903], [0.0, 0.0, 0.004592872405150497, 0.015116064182970243, 0.03145729977292465, 0.056916813023154794, 0.07963307308819596, 0.11054141447048473, 9.999559097721269, 0.0]]
0.35 [[0.10937029776682163, 0.0, 0.0, 0.0, 0.0, 0.006769041443224288, 0.0019685444444710485, 0.09719975665988088, 0.11551446644382408, 0.0], [0.0, 0.0, 0.008920378577924696, 0.004301995016253411, 0.023305238965405147, 0.01953927514745209, 0.09977935686871658, 0.15933380884480347, 0.1615368155403108, 0.0], [0.0007393419074277953, 0.013361317030560536, 0.02713139922282082, 0.026777316436321412, 0.05864466853465846, 0.09042983254683945, 0.14678054733629237, 0.23581901227272548, 0.19076775049768804, 0.11647160837944331], [0.004691796039091806, 0.025088127007934807, 0.033848988238842595, 0.05010984861060955, 0.07964610073027209, 0.16121489184791, 0.18096793247608628, 0.3569109762094637, 0.5853276311867628, 0.13100900287600092], [0.014713567562706628, 0.03907588806156518, 0.052956985928138994, 0.09467906378530438, 0.14190925390466438, 0.22801220497721073, 0.364050361708299, 0.5866811930958349, 1.0539352755319353, 0.7688880281212109], [0.02067904820417277, 0.06441091916415637, 0.08528385834600595, 0.10427647382463065, 0.21631858538060222, 0.3482838222702332, 0.5130101027959563, 0.9769865161652073, 1.6239746720007338, 1.3561689746016565], [0.014834984121756347, 0.06967631708494154, 0.188357571714802, 0.26340049436260604, 0.40808699582729296, 0.7037855700712743, 1.156233966806386, 1.5959766599506442, 2.2290507743972308, 3.5515447908962705], [0.0, 0.04993778819699293, 0.2283211957876625, 0.4020679158266476, 0.5902117908258775, 0.6845976477021088, 1.9695980083001932, 3.239790890966278, 3.6776977950090073, 5.799739882218728], [0.0, 0.0, 0.04074462028067638, 0.14564470999291676, 0.8481812573285745, 1.363142049892742, 1.3658045497793077, 4.831586447177146, 6.969110446076148, 9.914116774637328], [0.0, 0.0, 0.0051032235883759335, 0.01609941081389634, 0.03229528678986738, 0.057720688621569566, 0.08046726652479001, 0.11014420696023214, 10.000731223006442, 0.0]]
0.40 [[0.11104510935078375, 0.0, 0.0, 0.0, 0.0, 0.00823371053567127, 0.003082632898633468, 0.10121397911590864, 0.12007860332243805, 0.0], [0.0, 0.0, 0.009108797703740757, 0.005115119807973275, 0.02506582128249193, 0.023058529295219926, 0.10126341852569268, 0.1578077466726533, 0.16141974684087376, 0.0], [0.0010196187176788017, 0.013831285105091382, 0.02730582561728478, 0.02794243452365794, 0.06272242630779386, 0.09411360818417375, 0.1494998409246955, 0.23466382856999457, 0.18777133082828948, 0.13208731284500969], [0.005204185560767414, 0.02620539199930857, 0.03324929212365525, 0.05079739930516473, 0.07958719433753002, 0.16574876221258558, 0.1873557405523899, 0.35450146714687497, 0.5839728372613064, 0.1683528985458408], [0.016603152853205218, 0.04018942342857173, 0.05266428655906515, 0.09660124633052897, 0.1464946061900008, 0.22796645139142555, 0.37131241987949465, 0.57981153603625, 1.0599147475431592, 0.8363918577032379], [0.021811077198107827, 0.06598151465058708, 0.0845189734626644, 0.10541268090258761, 0.22553410975188157, 0.3651470964917794, 0.5168744696632205, 0.9730135496333387, 1.6238477820677262, 1.3866312807161048], [0.016790247303029672, 0.07353974317350662, 0.19450336018250458, 0.2783887361357875, 0.432151502399928, 0.7410014799048679, 1.202826738302459, 1.6145838000449033, 2.219875424220546, 3.5130950108275], [0.0, 0.05036223670166467, 0.23231794987825613, 0.4083609522922788, 0.6021802501726057, 0.6943674722499741, 2.00873304226488, 3.2549223297574303, 3.7171222494276153, 5.831629742162852], [0.0, 0.0, 0.041117199539285505, 0.15561297802067167, 0.8719535381541477, 1.3824012903440188, 1.3378694691469966, 4.837717015350711, 6.9727392525124126, 9.916296325888391], [0.0, 0.0, 0.005632572219527616, 0.017119841182054053, 0.03316851836643227, 0.05846196994049957, 0.08132048539846784, 0.1090948198070361, 10.001952249572204, 0.0]]
0.45 [[0.11357111524019228, 0.0, 0.0, 0.0, 0.0, 0.009988685191030794, 0.004578150725613089, 0.10496920618726943, 0.1236110193820983, 0.0], [0.0, 0.0, 0.009237757096686623, 0.005934854868576364, 0.026891526134519728, 0.02693677401506768, 0.10237824107717938, 0.15557699148895093, 0.16038395115454682, 0.0], [0.0013622623788716061, 0.014296697635749955, 0.027424580652413117, 0.0291616311325217, 0.06700762501001588, 0.09783905802954845, 0.1518215805004357, 0.23278320966119384, 0.18377602775065716, 0.15149447129566582], [0.005769110972563032, 0.027252825244488486, 0.03261650128013046, 0.05160398214529798, 0.07920361156366948, 0.16971436644800694, 0.1937266693655329, 0.3512828060458065, 0.5818329510154131, 0.21031388558915828], [0.01854876039557905, 0.041157785571703256, 0.052416726372528914, 0.09916098977825895, 0.15204736427867566, 0.2278202298244818, 0.3780577549726526, 0.5724128140691664, 1.0669198620548717, 0.9049873994699719], [0.022900021187888055, 0.06773826448825879, 0.08421883040954657, 0.10729892170421801, 0.23592865902420257, 0.38277905261447004, 0.5206112985490194, 0.9680867672460565, 1.6212048230083442, 1.4145709176892771], [0.018847314613961934, 0.07770958760808348, 0.20195164857787315, 0.29481960666144347, 0.4577358163791651, 0.7785358058393893, 1.2483974166898157, 1.6351072781248999, 2.2107992632507028, 3.460176681430535], [0.0, 0.051084967339247764, 0.2366990341867753, 0.41525983062419236, 0.6142344477486719, 0.703620607561637, 2.0467336317310774, 3.269889060971468, 3.757019947887796, 5.863033903458847], [0.0, 0.0, 0.04135264911624052, 0.16655243937675404, 0.8937993907847629, 1.3953649450938603, 1.3092876131306252, 4.843775488437334, 6.976444505132107, 9.919089400316633], [0.0, 0.0, 0.006180906878549905, 0.018178638425579437, 0.03406884620732424, 0.05912054416223428, 0.08213757365924612, 0.10738462234425562, 10.003245805634606, 0.0]]
0.50 [[0.11706517510959256, 0.0, 0.0, 0.0, 0.0, 0.012086914567465372, 0.006508010630451101, 0.10845510019862986, 0.12593983963446667, 0.0], [0.0, 0.0, 0.00930697487015399, 0.006744334616762899, 0.028781647709490318, 0.0312467593789008, 0.10305957208758716, 0.15278188064703221, 0.15836609139779415, 0.0], [0.0017738426268281318, 0.014780088393066226, 0.027484693055423875, 0.030457384462948253, 0.0714399809601793, 0.10156273834129184, 0.1535240122064242, 0.23058162695960704, 0.1788709463030196, 0.1754147479554172], [0.006405344872074113, 0.028201667903266125, 0.031968490071867584, 0.05260380427316655, 0.07841002409434743, 0.17288403467472857, 0.19985746626061954, 0.34799096845418237, 0.5796643757866089, 0.2569964661299842], [0.020454106217286005, 0.04194571380816295, 0.05225205062451491, 0.1024339554590389, 0.1585539915612337, 0.22761259480884483, 0.3841488065413352, 0.5656297308713235, 1.0756608460366013, 0.9741595028666722], [0.023927552635612425, 0.06981079442902667, 0.08442696378395458, 0.10999935297613433, 0.24748248888309457, 0.40110904171774614, 0.524005131847338, 0.9627359958822804, 1.6164597360822972, 1.4394249144523494], [0.02099960445915631, 0.08220974985708862, 0.21072166192268832, 0.31259428900686975, 0.4848131940810621, 0.8160887002768277, 1.292694789391902, 1.6579238234161326, 2.2020991536815866, 3.3910714028260722], [0.0, 0.052231416529454316, 0.2415956507285422, 0.42246751609889727, 0.625736022238341, 0.712439438271528, 2.0834636987872446, 3.284646397748621, 3.797464863124936, 5.893710464323326], [0.0, 0.0, 0.04142890024433359, 0.17857692797617503, 0.9129666328749303, 1.4015638665387862, 1.2798371769527126, 4.849765774240384, 6.980250747907889, 9.922563384950777], [0.0, 0.0, 0.006744717442732771, 0.01927062127961491, 0.034983066310338665, 0.05968485105489956, 0.08289282649215476, 0.10506002405707, 10.00464471698896, 0.0]]
0.55 [[0.12165344360857724, 0.0, 0.0, 0.0, 0.0, 0.014598830922983686, 0.008909354444431044, 0.11167809385682557, 0.12690480692333725, 0.0], [0.0, 0.0, 0.00931312759931916, 0.007524327850448438, 0.030728539921640204, 0.03609114614626062, 0.10324591684748344, 0.14966807969864276, 0.1553427538609672, 0.0], [0.0022622217291668146, 0.015306897142647925, 0.02749171690845559, 0.03185015573976026, 0.0759047725873991, 0.10524786327434318, 0.15438678104029294, 0.22868381745132874, 0.17321059890214285, 0.20470860804257685], [0.007136800933302272, 0.029026943927350016, 0.031330920370261896, 0.05386893415137795, 0.07710506903817735, 0.1749895631825174, 0.2054887927452062, 0.34566124987943403, 0.5785648477548682, 0.3085556560839908], [0.022195443046943215, 0.042522462485269044, 0.05221768229601437, 0.10649716833761141, 0.16600868246153294, 0.22737234968367762, 0.38943721668983433, 0.5608592698864305, 1.0868892970603194, 1.0432918121844648], [0.024892617923549333, 0.07235428364904321, 0.08519933625631279, 0.11355549617701262, 0.2601807627900338, 0.42005798880735623, 0.5267605648716001, 0.9576511800878172, 1.6101472556607646, 1.4604830865095377], [0.023250274878273254, 0.08701769808294615, 0.22080948148927065, 0.3315507964463024, 0.513322693916328, 0.8533518314824103, 1.3354591884087648, 1.683479169257316, 2.194158664909779, 3.303849289727975], [0.0, 0.05393674853020325, 0.24703873245983363, 0.4295559865094715, 0.6359761692947543, 0.7209178751900953, 2.1187965860375617, 3.2991575749362476, 3.8385897055407776, 5.923424080213802], [0.0, 0.0, 0.04131235137053107, 0.19179978046424398, 0.9287310680642266, 1.4005398722027327, 1.2493152937094134, 4.855698018817488, 6.984189298536877, 9.926778518700033], [0.0, 0.0, 0.007318143416429577, 0.020387885173297864, 0.035902155983187994, 0.06016541501401439, 0.08361176718545407, 0.10223515429886325, 10.006194185581117, 0.0]]
0.60 [[0.1274666528756714, 0.0, 0.0, 0.0, 0.0, 0.01762248333835452, 0.011789973762047216, 0.11464556347334615, 0.1263720634890377, 0.0], [0.0, 0.0, 0.00925294553022896, 0.008253433553466721, 0.032708886725362665, 0.041620026019990077, 0.10288482722924344, 0.14660317107870077, 0.1513744914385782, 0.0], [0.0028374990592001407, 0.015904060574827912, 0.02746556283000234, 0.03335170465991191, 0.08021381146228121, 0.10885285389428988, 0.15421741674600117, 0.22798894669104658, 0.16703693766116134, 0.2403871325092077], [0.007991237437517559, 0.029713134680231464, 0.030735660357491815, 0.05545719620062743, 0.07517133789816492, 0.17573151427129421, 0.21034349968209515, 0.34567984304910837, 0.5800620661101306, 0.3651959879759768], [0.023628779022646772, 0.04286648161113712, 0.05237482842761101, 0.11143287576418606, 0.17441684345403818, 0.22711413180132484, 0.39377970588502403, 0.5597651892709384, 1.101403215072262, 1.1116857688064927], [0.025829393571253408, 0.07555574117604616, 0.08661327262014845, 0.11798785287646006, 0.2740116118355528, 0.43953698348778064, 0.5285136154192738, 0.9536902580785884, 1.6029118570101015, 1.4769079680635977], [0.025622711266111157, 0.09203919675348653, 0.2321801346803553, 0.35145718046555535, 0.5431765660995519, 0.8900154809885882, 1.3764243917289687, 1.7122907497296218, 2.1874825207216197, 3.196362809124657], [0.0, 0.05635429076532816, 0.2529153826385707, 0.4359557976744063, 0.6441679970485016, 0.7291403859132638, 2.1526169008706537, 3.3133938073864946, 3.8805891416923934, 5.951935348391441], [0.0, 0.0, 0.04095736768320908, 0.2063350524829813, 0.9404167120015604, 1.3918447773223097, 1.217562299349323, 4.861587454761251, 6.9882964940677725, 9.931782385957545], [0.0, 0.0, 0.007896964650113308, 0.021529154892721492, 0.03683682916302306, 0.06061515345718353, 0.08439635221080058, 0.09910430403924378, 10.007955092095017, 0.0]]
0.65 [[0.1346297185386525, 0.0, 0.0, 0.0, 0.0, 0.021299281902100887, 0.015105932976952745, 0.11732735547091522, 0.12425878076773986, 0.0], [0.0, 0.0, 0.009128060875902034, 0.008909943089467137, 0.03466730340988146, 0.04805566766942298, 0.10193846514239166, 0.1440971596091915, 0.14667606361807684, 0.0], [0.00351191611772849, 0.016598183344128582, 0.0274426334643687, 0.034956146114485116, 0.08408165373518352, 0.11230232986906656, 0.15288746562692204, 0.2297263855450595, 0.16071856413288138, 0.2836087281190934], [0.008998433861875639, 0.03026395280381845, 0.030217479809014316, 0.057396308983738584, 0.07247477682118439, 0.17479979585567054, 0.21415485737161963, 0.34982585335937816, 0.5862194718164043, 0.4271714304702603], [0.024602951731627007, 0.04297174105031984, 0.05280385173663729, 0.11733274415748363, 0.1837976702300482, 0.22683564397371717, 0.3970606052905823, 0.5642844448390077, 1.1200493267716793, 1.1785907659069839], [0.026832846439569454, 0.07963516633929085, 0.08877582064222375, 0.12329752126942124, 0.28896242226907665, 0.45944695758721904, 0.5288494671537649, 0.9518853831747336, 1.5954930321408123, 1.4877632928898958], [0.028176450413388354, 0.09708174256061665, 0.24475770855636012, 0.3720075475685365, 0.5742661773689791, 0.9257734170777889, 1.415317941942204, 1.744951106665433, 2.1827063275441683, 3.066240399849382], [0.0, 0.05967221503668134, 0.2589232291843358, 0.44094919939732413, 0.6494359341414859, 0.7371623529620186, 2.184821675300178, 3.327332403365362, 3.923720270690957, 5.9789820268466], [0.0, 0.0, 0.0403085904847892, 0.22230123264976157, 0.9474165021875675, 1.3750375103263925, 1.1844948460748828, 4.8674512085558215, 6.992609409522764, 9.937602274245211], [0.0, 0.0, 0.008485784894572145, 0.022715602049453207, 0.03783907320489006, 0.061154400155207386, 0.08545101186443772, 0.09595672490476025, 10.010006675161073, 0.0]]
0.70 [[0.14324459975601536, 0.0, 0.0, 0.0, 0.0, 0.025838103267616316, 0.018724241141602243, 0.11958197679956757, 0.12057650929017867, 0.0], [0.0, 0.0, 0.00894960256327042, 0.009475589706734984, 0.03648623472797421, 0.055726088376738675, 0.10038562908638754, 0.14282692023635007, 0.1417202281815048, 0.0], [0.004297595645808322, 0.017413248078862065, 0.027469478197246974, 0.03662877482798838, 0.08709501526867507, 0.11543201468805339, 0.15037823446742968, 0.2355029269924786, 0.15481138387317356, 0.33565238818368764], [0.010190229936881127, 0.03071880184523466, 0.029808585390067543, 0.05966326378613006, 0.06886684203639276, 0.17191419578031747, 0.21670898865905522, 0.36029225497184797, 0.5997574999352414, 0.4947876522538905], [0.02497928116594337, 0.042856555344935175, 0.05361261598138078, 0.12430198642036795, 0.19418559762327497, 0.226517456515392, 0.39922338664554646, 0.5766226117989546, 1.1437198486061988, 1.2432472522771336], [0.02809365927775637, 0.08483671373342463, 0.09182999273706535, 0.12946696803749141, 0.3050145874109064, 0.4796797563141587, 0.5273261998133784, 0.9534469443202671, 1.5887053417984738, 1.4920523429813382], [0.031029637831192055, 0.10182869638825097, 0.2584131175159465, 0.39282074629263, 0.6064647195678288, 0.9603241132944706, 1.4518585680697114, 1.7821309836756294, 2.1806002292754756, 2.910881259368098], [0.0, 0.06414348392060806, 0.26452637584621147, 0.4436669599799012, 0.6507993608926229, 0.744994148224721, 2.215320652778293, 3.3409517681098944, 3.968299724071938, 6.00425105777724], [0.0, 0.0, 0.03930705089332814, 0.23982865785589438, 0.9492122098662342, 1.349680229059506, 1.1501486016219327, 4.8733020659526245, 6.997158036758073, 9.944235306538825], [0.0, 0.0, 0.00910702049320916, 0.024011451257017764, 0.039026168168523924, 0.061994152540830315, 0.08710471457229199, 0.09319683347229327, 10.01244750412355, 0.0]]
0.75 [[0.15336555111720382, 0.0, 0.0, 0.0, 0.0, 0.03155106064230759, 0.022361171358899125, 0.1210321465524998, 0.1155079781179149, 0.0], [0.0, 0.0, 0.008738068219938742, 0.009939973019264785, 0.037932812596392, 0.06510835920259943, 0.09821493428008082, 0.1436620607297887, 0.1373802391462223, 0.0], [0.005201660216361378, 0.018368674111163368, 0.02757959391868911, 0.03829250275549398, 0.08867251119440149, 0.11789680904901127, 0.14683298392475333, 0.24732631175381348, 0.15013966847539156, 0.3978567449477336], [0.011608229220466788, 0.031178374709606348, 0.029530024604840364, 0.06215716751044612, 0.0641978750025174, 0.16689979079485667, 0.21790695719286576, 0.37967055485000684, 0.6241864003374441, 0.5684082141961353], [0.024656901437288006, 0.042577401162837994, 0.05495133053035108, 0.13246295482338893, 0.20563050012634734, 0.22612681959618472, 0.4003147278934225, 0.5992352109663311, 1.173340641364212, 1.3049443933991764], [0.029944542327216956, 0.09140390177143938, 0.09595707692432442, 0.13645956125967887, 0.3221372435048445, 0.5001209576403183, 0.5235033904804106, 0.9597646085445783, 1.5834121337326725, 1.4887664046979188], [0.03438816161824868, 0.10581606337464337, 0.2729486985658444, 0.4134409573423839, 0.6396239705260879, 0.9933662762675276, 1.4857490490772332, 1.8245809493405336, 2.1820655552730184, 2.7274558712903936], [0.0, 0.07013655962807405, 0.2689177328371988, 0.4430881450378764, 0.6471458578289834, 0.7525928083495047, 2.2440357513810376, 3.3542221692776564, 4.014695950171662, 6.0273435482289806], [0.0, 0.0, 0.03789908085235983, 0.25907047014106094, 0.9453914552761926, 1.3153343589408255, 1.114730318540835, 4.87913839981565, 7.00195317650047, 9.951637291812252], [0.0, 0.0, 0.00980698276941682, 0.0255429035709448, 0.04059874448237465, 0.06344458106983264, 0.08982091929946578, 0.09137223962388655, 10.01539334794496, 0.0]]
0.80 [[0.16496672453627922, 0.0, 0.0, 0.0, 0.0, 0.03890370573132427, 0.025482716568847895, 0.12087223888741783, 0.10953882340037491, 0.0], [0.0, 0.0, 0.008509850258576448, 0.010301364822550547, 0.03856944174056192, 0.07687998955102984, 0.0954002892935672, 0.14768585461659758, 0.13511019548524947, 0.0], [0.006220729680732361, 0.019481533229820474, 0.027737587157207772, 0.03981135294629595, 0.08801087406763099, 0.11902927161690129, 0.14260671435746586, 0.2675849916548255, 0.14788584600659777, 0.47151141487389525], [0.013330777254707129, 0.031840600576808945, 0.02937757185103653, 0.06466291517474047, 0.05835954236926952, 0.1598219472796455, 0.21785308884174157, 0.4108813022287583, 0.6639449266310515, 0.6484668648628295], [0.023598668307242554, 0.042254231500255715, 0.057040740757860815, 0.14195754621429385, 0.21819656578334162, 0.22562642263731736, 0.4005467717966462, 0.6347925806244405, 1.20984853226556, 1.3630943269345819], [0.03292039954816322, 0.09953173672312011, 0.1013733639751175, 0.14421890811768914, 0.34028082823394007, 0.5206546677835434, 0.5169733217256555, 0.972404799729795, 1.5804928265526594, 1.4769421329096704], [0.03857903128013175, 0.10841367328149813, 0.28807849343947656, 0.43333886749181383, 0.6735613607703197, 1.024586299746444, 1.5166630013356994, 1.873131904045949, 2.1881239203820804, 2.512924077112816], [0.0, 0.07821744304880487, 0.27099330693520185, 0.4380407514692067, 0.6371868655864956, 0.7598674195214694, 2.2709003318800223, 3.367091583864879, 4.063313181668992, 6.0477420270349], [0.0, 0.0, 0.03604273896918361, 0.2802132758454387, 0.9356580770206567, 1.2715565096611696, 1.0786755063494018, 4.884930015724761, 7.006969860261064, 9.959713058045736], [0.0, 0.0, 0.010649431330467585, 0.02750157201152549, 0.04283788669201118, 0.06588726113123299, 0.09418257377374352, 0.09120959707325917, 10.018970363333914, 0.0]]
0.85 [[0.17790431771782392, 0.0, 0.0, 0.0, 0.0, 0.048579316355150524, 0.027148806799780757, 0.11758756602565215, 0.1036710136574569, 0.0], [0.0, 0.0, 0.00823421984883733, 0.010553321868803724, 0.03761159276552245, 0.09197062656569299, 0.09184554367444693, 0.15620044862276575, 0.13714909935980135, 0.0], [0.007342700430172378, 0.02078442493047754, 0.027720541162943726, 0.0409698406409541, 0.08401310233628201, 0.11763571258467397, 0.13829579246016088, 0.2989615911930485, 0.14965937022329015, 0.5576841014692332], [0.01553947294925109, 0.03304570043033251, 0.02929694844987578, 0.06680302328114372, 0.05139113754282425, 0.1512208073496751, 0.21697769354742674, 0.45703412545591837, 0.724540067537415, 0.7354903675714917], [0.02184364533232326, 0.04212200357121753, 0.06022626593820498, 0.15294721629519095, 0.23195961239049945, 0.22498742528642687, 0.4003868191270904, 0.6861294418560748, 1.254158768271944, 1.417327735513822], [0.03783567214918153, 0.10928719753798362, 0.10832032731774871, 0.15267213512354905, 0.35937159170834887, 0.541170030572203, 0.5073903345760321, 0.9931057239592944, 1.5808057432042018, 1.4557260733915798], [0.04408053304710449, 0.10881212511043278, 0.30340345376943423, 0.4519121596572195, 0.7080328067367687, 1.05363562523076, 1.5442250964589894, 1.9287005427142048, 2.1998985435219707, 2.264097666137938], [0.0, 0.08927681952711307, 0.26934400567603356, 0.42719898541570467, 0.6193841852807569, 0.7667062840318756, 2.2958600014759103, 3.379466952729091, 4.1145599739648295, 6.064804068079432], [0.0, 0.0, 0.033699797861964184, 0.30347609120660884, 0.9198288090008224, 1.2178910756790995, 1.0426994016874553, 4.890600535653317, 7.012126962886073, 9.968313695888469], [0.0, 0.0, 0.011681635845145498, 0.030109307714195264, 0.04605889719008367, 0.06967918930727479, 0.100833308129906, 0.09365351067991134, 10.023302212177576, 0.0]]
0.90 [[0.19188056435679776, 0.0, 0.0, 0.0, 0.0, 0.06154925739514705, 0.02577734234352943, 0.10856090268102696, 0.09974356306843904, 0.0], [0.0, 0.0, 0.0077301819839937355, 0.01063398725729666, 0.03371710433519103, 0.11159495166903406, 0.08728149296642497, 0.17070291412478872, 0.14670740119265774, 0.0], [0.008576006961616964, 0.0223868443767333, 0.026881249917550795, 0.04144627180369518, 0.07519471143293505, 0.111724013864791, 0.13471782824351902, 0.34426344477641824, 0.15748798782662488, 0.656962964675678], [0.018655977254024743, 0.035326221108321905, 0.02913892821548865, 0.06797834159282273, 0.04371521818318973, 0.14250952855224516, 0.21620655980125533, 0.5212133725163955, 0.8126928065607736, 0.8301430323146156], [0.019475616653821966, 0.04263769617233326, 0.06508048169648208, 0.1656079169977588, 0.24700185670898267, 0.22420170036978987, 0.40068931341266234, 0.7561906726125623, 1.307131966796002, 1.4676241065082467], [0.04588339989106973, 0.12048747900869773, 0.11704844326114812, 0.16174695123329116, 0.37930830855854997, 0.5615678142200484, 0.49448898076891246, 1.0237767940175353, 1.5851530251846428, 1.4244480546437546], [0.05153423353431598, 0.10601519593562068, 0.31838284345936096, 0.4684856154780425, 0.7426862771432993, 1.0800974090011868, 1.567986190725434, 1.9923208926357436, 2.2185890566968074, 1.9778051217939507], [0.0, 0.10471797604004943, 0.26226835023077955, 0.4090690782380661, 0.5918273739950459, 0.7730294460823617, 2.3188784426636877, 3.3911928080730376, 4.168790990931754, 6.077835671399403], [0.0, 0.0, 0.03079409588617537, 0.32907279363518255, 0.8978028691295141, 1.1538493296720047, 1.007813266085753, 4.896007841841423, 7.0172646114150865, 9.977248968102177], [0.0, 0.0, 0.01285564375144369, 0.03351210438892528, 0.050492572307595164, 0.07494526343399777, 0.11034961206274665, 0.09989711616530524, 10.028490690868102, 0.0]]
0.95 [[0.2064271720681793, 0.0, 0.0, 0.0, 0.0, 0.07912773246978794, 0.01879725175929211, 0.08953619834463751, 0.1008696272498147, 0.0], [0.0, 0.0, 0.006446364074267579, 0.010291233216212075, 0.02470524740372384, 0.13723142468205893, 0.08109880498313628, 0.19282420910796755, 0.16804238784935477, 0.0], [0.010050758947224047, 0.024637424627921876, 0.02369950795084535, 0.040777712650791664, 0.05956926937661816, 0.09818342325241204, 0.13280059802601174, 0.40618068506419536, 0.17363873254681528, 0.7690852979163022], [0.023587342786222716, 0.039457155602999706, 0.028580138168175645, 0.06731215601839018, 0.0366242757576946, 0.1366441004617963, 0.21720252159613687, 0.6062223793686706, 0.936530675277975, 0.9333208099178494], [0.016488827249559346, 0.04469408083392467, 0.07259280526838037, 0.18011289174722023, 0.26339980206497926, 0.22327644721329798, 0.4028932632899593, 0.8480104244056692, 1.3695687875824485, 1.514512173222223], [0.05876052976337379, 0.1325224152576172, 0.12779608351340616, 0.17142187787189614, 0.3999613210946048, 0.5817610229136313, 0.4780704094315433, 1.0665247712867927, 1.5942643962096832, 1.382718408936648], [0.061717931807571305, 0.09882919852409322, 0.3323080717191363, 0.4823152847080965, 0.7769905845255902, 1.1034438822185695, 1.5873966748910984, 2.0652576512101826, 2.245449486705257, 1.651278132811424], [0.0, 0.12671797414050315, 0.24780176574862817, 0.38194719954721135, 0.5520246990726426, 0.7788370079630947, 2.339953885672838, 3.402031231196444, 4.2262105292669885, 6.0863547127202], [0.0, 0.0, 0.027115431497412544, 0.35709244528913714, 0.8694788360288648, 1.0788521030930254, 0.9752571606414665, 4.9009241975971864, 7.022121438085993, 9.98632370728791], [0.0, 0.0, 0.01389558676734178, 0.03756649398430354, 0.056060820337121495, 0.08120529898642019, 0.1230139484322529, 0.11138795128460345, 10.034591732822099, 0.0]]
1.00 [[0.2209454022730491, 0.0, 0.0, 0.0, 0.0, 0.10297125153911645, 0.002149301059709195, 0.05391783490148128, 0.11195411656997162, 0.0], [0.0, 0.0, 0.0030257124842693337, 0.008777522443636346, 0.007253264516288271, 0.17049790557130295, 0.07211379731258978, 0.22424984382887975, 0.20623350436428212, 0.0], [0.012283696473644362, 0.02848905950340872, 0.014980430928816287, 0.03831963946946219, 0.03452979824132384, 0.07251122774466784, 0.1333387634459363, 0.4870577549355676, 0.20014030396202445, 0.8923963696416298], [0.03210819374479202, 0.04650922368073688, 0.026995688241033225, 0.06365464510692476, 0.03324414576726042, 0.13926296945645855, 0.2227409053307213, 0.7144101225433922, 1.105972961632879, 1.0463580463591935], [0.012447375330629012, 0.050014918680164826, 0.08450961521184587, 0.19658123378474704, 0.281186038586858, 0.22216263535083572, 0.40932175959309147, 0.9648199819891651, 1.4422971657537553, 1.5594258462637174], [0.07881612881815332, 0.1441042926572531, 0.14076443378785178, 0.18184290321234117, 0.4211658996503925, 0.6016474365121321, 0.4579119942337586, 1.1237672913624244, 1.6088393575698756, 1.3305944910585599], [0.07547120033220939, 0.0858085800296562, 0.34429392776414103, 0.4926079564890793, 0.8101345733444306, 1.1229856917826637, 1.601779144034771, 2.149333073272291, 2.2818124008234117, 1.2830097312357336], [0.0, 0.1585581721216047, 0.22373580331327722, 0.34381367807229746, 0.4965326775713116, 0.7840975442944937, 2.3591519450424063, 3.411647792729942, 4.286745320727526, 6.0907633774342305], [0.0, 0.0, 0.02216732629064543, 0.38722274911092086, 0.8345670598480799, 0.9920905838414954, 0.9462906938611229, 4.90501487241693, 7.02631206110123, 9.995400712857583], [0.0, 0.0, 0.014135750771402661, 0.04149220556338484, 0.06201414714043829, 0.08677546555491786, 0.13845428248785618, 0.12979993251235647, 10.041592046309297, 0.0]]

Subjective questions

2.a Value Iteration vs Policy Iteration

  1. Compare value iteration and policy iteration for states Brown in, Brown Out, Grey out and Grey In
  2. Which one converges faster and why
In [162]:
env = GridEnv_HW2(**base_kwargs)
val_res, extra_info_val = value_iteration(env, 0.7)
pol_res, extra_info_pol = policy_iteration(env, 0.7)

Brown In State

In [163]:
brown_in_loc = np.where(env.grid == 'brown_in')
state = brown_in_loc[0][0], brown_in_loc[1][0]
value_iter_vals = [extra_info_val['Expected Rewards'][i][state[0],state[1]] for i in range(len(extra_info_val['Expected Rewards']))]
x_val = range(len(extra_info_val['Expected Rewards']))
pol_iter_vals = [extra_info_pol['Expected Rewards'][i][state[0],state[1]] for i in range(len(extra_info_pol['Expected Rewards']))]
x_pol = range(len(extra_info_pol['Expected Rewards']))
plt.figure(figsize = (8,6))
plt.plot(x_val,value_iter_vals,label = "Value Iteration")
plt.plot(x_pol,pol_iter_vals,label = "Policy Iteration")
plt.legend(loc = "best")
plt.xlabel("iteration")
plt.ylabel("Value")
plt.title("Value Convergence of Value and Policy Iteration for state Brown In")
Out[163]:
Text(0.5, 1.0, 'Value Convergence of Value and Policy Iteration for state Brown In')

Brown Out State

In [164]:
brown_out_loc = np.where(env.grid == 'brown_out')
state = brown_out_loc[0][0], brown_out_loc[1][0]
value_iter_vals = [extra_info_val['Expected Rewards'][i][state[0],state[1]] for i in range(len(extra_info_val['Expected Rewards']))]
x_val = range(len(extra_info_val['Expected Rewards']))
pol_iter_vals = [extra_info_pol['Expected Rewards'][i][state[0],state[1]] for i in range(len(extra_info_pol['Expected Rewards']))]
x_pol = range(len(extra_info_pol['Expected Rewards']))
plt.figure(figsize = (8,6))
plt.plot(x_val,value_iter_vals,label = "Value Iteration")
plt.plot(x_pol,pol_iter_vals,label = "Policy Iteration")
plt.legend(loc = "best")
plt.xlabel("iteration")
plt.ylabel("Value")
plt.title("Value Convergence of Value and Policy Iteration for state Brown Out")
Out[164]:
Text(0.5, 1.0, 'Value Convergence of Value and Policy Iteration for state Brown Out')

Grey Out State

In [165]:
grey_out_loc = np.where(env.grid == 'grey_out')
state = grey_out_loc[0][0], grey_out_loc[1][0]
value_iter_vals = [extra_info_val['Expected Rewards'][i][state[0],state[1]] for i in range(len(extra_info_val['Expected Rewards']))]
x_val = range(len(extra_info_val['Expected Rewards']))
pol_iter_vals = [extra_info_pol['Expected Rewards'][i][state[0],state[1]] for i in range(len(extra_info_pol['Expected Rewards']))]
x_pol = range(len(extra_info_pol['Expected Rewards']))
plt.figure(figsize = (8,6))
plt.plot(x_val,value_iter_vals,label = "Value Iteration")
plt.plot(x_pol,pol_iter_vals,label = "Policy Iteration")
plt.legend(loc = "best")
plt.xlabel("iteration")
plt.ylabel("Value")
plt.title("Value Convergence of Value and Policy Iteration for state Grey Out")
Out[165]:
Text(0.5, 1.0, 'Value Convergence of Value and Policy Iteration for state Grey Out')

Grey In State

In [166]:
grey_in_loc = np.where(env.grid == 'grey_in')
state = grey_in_loc[0][0], grey_in_loc[1][0]
value_iter_vals = [extra_info_val['Expected Rewards'][i][state[0],state[1]] for i in range(len(extra_info_val['Expected Rewards']))]
x_val = range(len(extra_info_val['Expected Rewards']))
pol_iter_vals = [extra_info_pol['Expected Rewards'][i][state[0],state[1]] for i in range(len(extra_info_pol['Expected Rewards']))]
x_pol = range(len(extra_info_pol['Expected Rewards']))
plt.figure(figsize = (8,6))
plt.plot(x_val,value_iter_vals,label = "Value Iteration")
plt.plot(x_pol,pol_iter_vals,label = "Policy Iteration")
plt.legend(loc = "best")
plt.xlabel("iteration")
plt.ylabel("Value")
plt.title("Value Convergence of Value and Policy Iteration for state Grey In")
Out[166]:
Text(0.5, 1.0, 'Value Convergence of Value and Policy Iteration for state Grey In')

From the above plots, in all cases it can be noticed that Policy Iteration converges much faster than Value Iteration. Policy Iteration converges sooner because of the fact that the action is space is finite and the policy function reaches an optimum sooner than the value function

2.b How changing $\lambda$ affecting TD Lambda

In [167]:
errors = []
for lamda in td_lamda_results:
  errors.append(np.sqrt(np.sum((td_lamda_results[lamda]['Values'] - val_res['Values'])**2)/100))
lamda_vals = np.sort(list(td_lamda_results.keys()))
plt.figure(figsize = (8,6))
plt.plot(lamda_vals,errors)
plt.xlabel("lambda")
plt.ylabel("Error Standard Deviation")
plt.title("Error vs Lambda of TD(lambda)")
Out[167]:
Text(0.5, 1.0, 'Error vs Lambda of TD(lambda)')

From the above plot, it can be seen that the error standard deviation (variance) decreases until a point and then further increases. The best value of $\lambda$ that gives minimum variance hence lies between 0.4 to 0.6. Tuning for $\lambda$ therefore presents a bias-variance trade-off.

2.c Policy iteration error curve

Plot error curve of $J_i$ vs iteration $i$ for policy iteration

In [168]:
errors = []
extra_info_pol['Expected Rewards']
for i in range(len(extra_info_pol['Expected Rewards'])):
  errors.append(np.sqrt(np.sum((extra_info_pol['Expected Rewards'][i] - val_res['Values'])**2)/100))
x_pol = range(len(extra_info_pol['Expected Rewards']))
plt.figure(figsize = (8,6))
plt.plot(x_pol,errors)
plt.xlabel("iteration")
plt.ylabel("Error Standard Deviation")
plt.title("Error vs Iteration of Policy Iteration")
Out[168]:
Text(0.5, 1.0, 'Error vs Iteration of Policy Iteration')

Therefore, the error variance (standard deviation) decreases after every iteration to converge to 0.

2.d TD Lamdba error curve

Plot error curve of $J_i$ vs iteration $i$ for TD Lambda for $\lambda = [0, 0.25, 0.5, 0.75, 1]$

In [169]:
for lamda in [0, 0.25, 0.5, 0.75, 1]:
  errors = []
  for i in range(len(extra_info_TD[lamda]["Reward"])):
    errors.append(np.sqrt(np.sum((extra_info_TD[lamda]["Reward"][i] - val_res['Values'])**2)/100))
  plt.figure(figsize = (8,6))
  plt.plot(range(len(extra_info_TD[lamda]["Reward"])),errors,label = "lambda = "+str(lamda))
  plt.xlabel("iteration")
  plt.ylabel("Error Standard Deviation")
  plt.legend(loc = "best")
  plt.title("Error vs Iteration of TD("+str(lamda)+") Iteration")

Hence, the increase in variance (standard deviation) with increase in lambda can be observed from the above plots

Submit to AIcrowd 🚀

In [ ]:
!DATASET_PATH=$AICROWD_DATASET_PATH aicrowd notebook submit --no-verify -c iit-m-rl-assignment-2-gridworld -a assets
WARNING: No assets directory at assets... Creating one...
No jupyter lab module found. Using jupyter notebook.
Using notebook: /content/Copy%20of%20IITM_Assignment_2_Gridworld_Release.ipynb for submission...
Mounting Google Drive 💾
Your Google Drive will be mounted to access the colab notebook
Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob&scope=email%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdocs.test%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive.photos.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fpeopleapi.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive.activity.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fexperimentsandconfigs%20https%3a%2f%2fwww.googleapis.com%2fauth%2fphotos.native&response_type=code

Enter your authorization code:
In [ ]:

1278

Comments

You must login before you can post a comment.

Execute