|
17 | 17 | WARNING: Do NOT modify or regenerate the transition tables (.npy files). |
18 | 18 | The grading server uses the same tables - changing them will cause your submission to fail. |
19 | 19 |
|
| 20 | +TRANSITION TABLES: |
| 21 | +================= |
| 22 | +
|
| 23 | +The state space is discretized into a 200x200 grid: |
| 24 | + - s0 (first index): Position index, ranging from 0 to 199 |
| 25 | + - Index 0 corresponds to position -1.2 (leftmost) |
| 26 | + - Index 199 corresponds to position 0.6 (rightmost) |
| 27 | + - The goal region (position >= 0.5) is roughly indices 189-199 |
| 28 | + - s1 (second index): Velocity index, ranging from 0 to 199 |
| 29 | + - Index 0 corresponds to velocity -0.07 (moving left fastest) |
| 30 | + - Index 199 corresponds to velocity 0.07 (moving right fastest) |
| 31 | + - Index ~100 corresponds to velocity ~0 (stationary) |
| 32 | +
|
| 33 | +The transition tables are numpy arrays: |
| 34 | +
|
20 | 35 | P (transition_next_states.npy): shape (200, 200, 3, 2) |
21 | | - P[s0, s1, a] = [s0', s1'] |
22 | | - The next state indices when taking action a from state (s0, s1) |
| 36 | + P[s0, s1, a] = [s0', s1'] (a numpy array of 2 integers) |
| 37 | +
|
| 38 | + Given current state indices (s0, s1) and action a, returns the |
| 39 | + next state indices [s0', s1']. |
| 40 | +
|
| 41 | + Example: |
| 42 | + next_state = P[100, 100, 2] # State (100,100), action 2 (push right) |
| 43 | + s0_next, s1_next = next_state[0], next_state[1] |
| 44 | + # Now you can look up Q[s0_next, s1_next, :] to get Q-values at next state |
23 | 45 |
|
24 | 46 | R (transition_rewards.npy): shape (200, 200, 3) |
25 | | - R[s0, s1, a] = reward |
26 | | - The reward is -1 for each step until the goal is reached. |
| 47 | + R[s0, s1, a] = reward (a single float) |
| 48 | +
|
| 49 | + The immediate reward for taking action a in state (s0, s1). |
| 50 | + In MountainCar, this is always -1 for every step (encourages reaching |
| 51 | + the goal quickly). |
| 52 | +
|
| 53 | + Example: |
| 54 | + reward = R[100, 100, 2] # Always -1.0 |
27 | 55 |
|
28 | 56 | D (transition_dones.npy): shape (200, 200, 3) |
29 | | - D[s0, s1, a] = done (True/False) |
30 | | - True when the car reaches the goal (position >= 0.5) |
| 57 | + D[s0, s1, a] = done (a boolean: True or False) |
| 58 | +
|
| 59 | + Whether the episode terminates after taking action a in state (s0, s1). |
| 60 | + True only when the car reaches the goal (position >= 0.5). |
| 61 | +
|
| 62 | + Example: |
| 63 | + done = D[195, 150, 2] # True if this transition reaches the goal |
| 64 | + # If done is True, there is no future reward (episode ends) |
| 65 | +
|
| 66 | +USING THE TABLES IN Q-ITERATION: |
| 67 | +=============================== |
| 68 | +
|
| 69 | +For each state-action pair (s0, s1, a): |
| 70 | + 1. Look up the next state: s0', s1' = P[s0, s1, a] |
| 71 | + 2. Look up the reward: r = R[s0, s1, a] |
| 72 | + 3. Look up if terminal: d = D[s0, s1, a] |
| 73 | + 4. Apply Bellman update: |
| 74 | + Q_new[s0, s1, a] = r + gamma * (1 - d) * max_a' Q[s0', s1', a'] |
| 75 | +
|
| 76 | + Note: (1 - d) ensures we don't add future value for terminal states |
31 | 77 |
|
32 | 78 | Your task: |
33 | 79 | Implement Q-iteration using the Bellman optimality equation: |
|
38 | 84 |
|
39 | 85 | Submission: |
40 | 86 | - checkpoint.pt: Your Q-table saved with torch.save (shape: 200x200x3) |
41 | | - - policy.py is provided - do not modify it |
| 87 | + - policy.py: Implement the forward() method to select actions using your Q-table |
42 | 88 |
|
43 | 89 | Expected performance: |
44 | 90 | A well-implemented solution should consistently reach the goal. |
|
0 commit comments